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

Christian Hagedorn chagedorn at openjdk.org
Wed May 14 14:17:59 UTC 2025


On Tue, 13 May 2025 09:11:08 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:
> 
>   Move functions into !PRODUCT

Looks good to me otherwise!

src/hotspot/share/opto/c2_globals.hpp line 395:

> 393:           "6=all details printed. "                                         \
> 394:           "Level of detail of printouts can be set on a per-method level "  \
> 395:           "as well by using CompileCommand=option.")                        \

Suggestion:

          "as well by using CompileCommand=PrintPhaseLevel.")                        \

src/hotspot/share/opto/compile.cpp line 5180:

> 5178: bool Compile::should_print_phase(const int level) const {
> 5179:   return PrintPhaseLevel > 0 && directive()->PhasePrintLevelOption >= level &&
> 5180:     _method != nullptr; // Do not print phases for stubs.

Maybe align:
Suggestion:

  return PrintPhaseLevel > 0 && directive()->PhasePrintLevelOption >= level &&
         _method != nullptr; // Do not print phases for stubs.

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

Marked as reviewed by chagedorn (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/25183#pullrequestreview-2833207034
PR Review Comment: https://git.openjdk.org/jdk/pull/25183#discussion_r2084665235
PR Review Comment: https://git.openjdk.org/jdk/pull/25183#discussion_r2089049805


More information about the hotspot-compiler-dev mailing list