RFR: 8355970: C2: Add command line option to print the compile phases [v4]

Vladimir Kozlov kvn at openjdk.org
Mon May 12 16:30:55 UTC 2025


On Mon, 12 May 2025 14:59:29 GMT, Manuel Hässig <mhaessig at openjdk.org> wrote:

>> This PR introduces the flag `-XX:PrintPhaseLevel` that works like the flag `-XX:PrintIdealGraphLevel` and prints the name phases of a C2 compilation (essentially what we have in the left side bar in IGV) to the terminal. This allows redirecting the output to a file and comparing phase decisions between two compilations. Further, it is useful in conjunction with loop opts tracing to immediately see in which phase a certain optimization happened.
>> 
>> <details>
>> <summary>Output with `-XX:PrintPhaseLevel=2`</summary>
>> 
>> 
>>> java-fastdebug -Xbatch -XX:CompileCommand=compileonly,TestLoop.test10 -XX:CompileCommand=printcompilation,TestLoop.test* -XX:PrintPhaseLevel=2 TestLoop.java
>> CompileCommand: compileonly TestLoop.test10 bool compileonly = true
>> CompileCommand: PrintCompilation TestLoop.test* bool PrintCompilation = true
>> 3577   98 %  b  3       TestLoop::test10 @ 2 (64 bytes)
>> 3584   99    b  3       TestLoop::test10 (64 bytes)
>> 3648  100 %  b  4       TestLoop::test10 @ 2 (64 bytes)
>> 1.      After Parsing
>> 2.      Iter GVN 1
>> 3.      Incremental Inline
>> 4.      Incremental Boxing Inline
>> 5.      Before Loop Optimizations
>> 6.      PhaseIdealLoop 1
>> 7.      PhaseIdealLoop 2
>> 8.      PhaseIdealLoop 3
>> 9.      Before PhaseCCP 1
>> 10.     PhaseCCP 1
>> 11.     Iter GVN 2
>> 12.     PhaseIdealLoop iterations
>> 13.     After Loop Optimizations
>> 14.     After Macro Expansion
>> 15.     Barrier expand
>> 16.     Optimize finished
>> 17.     Before matching
>> 18.     After matching
>> 19.     Global code motion
>> 20.     Register Allocation
>> 21.     Final Code
>> 3668  103    b  4       TestLoop::test10 (64 bytes)
>> 1.      After Parsing
>> 2.      Iter GVN 1
>> 3.      Incremental Inline
>> 4.      Incremental Boxing Inline
>> 5.      Before Loop Optimizations
>> 6.      PhaseIdealLoop 1
>> 7.      PhaseIdealLoop 2
>> 8.      PhaseIdealLoop 3
>> 9.      Before PhaseCCP 1
>> 10.     PhaseCCP 1
>> 11.     Iter GVN 2
>> 12.     PhaseIdealLoop iterations
>> 13.     PhaseIdealLoop iterations 2
>> 14.     PhaseIdealLoop iterations 3
>> 15.     PhaseIdealLoop iterations 4
>> 16.     PhaseIdealLoop iterations 5
>> 17.     PhaseIdealLoop iterations 6
>> 18.     PhaseIdealLoop iterations 7
>> 19.     PhaseIdealLoop iterations 8
>> 20.     PhaseIdealLoop iterations 9
>> 21.     After Loop Optimizations
>> 22.     After Macro Expansion
>> 23.     Barrier expand
>> 24.     Optimize finished
>> 25.     Before matching
>> 26.     After matching
>> 27.     Global code motion
>> 28.     Registe...
>
> Manuel Hässig has updated the pull request incrementally with one additional commit since the last revision:
> 
>   No tty lock needed for one print

src/hotspot/share/opto/compile.hpp line 671:

> 669:   bool should_print_igv(int level);
> 670:   bool should_print_phase(int level) const;
> 671:   bool should_print_ideal_phase(CompilerPhaseType cpt) const;

You can use macro `PRODUCT_RETURN_(return false;);` and put both methods under `#ifndef PRODUCT` in .cpp file.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25183#discussion_r2085046167


More information about the hotspot-compiler-dev mailing list