RFR: 8360389: Support printing from C2 compiled code [v8]

Benoît Maillard bmaillard at openjdk.org
Mon Sep 1 14:43:45 UTC 2025


On Mon, 1 Sep 2025 13:15:08 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Benoît Maillard has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fix mismatch with #ifdef COMPILER2 between .hpp and .cpp
>
> I have not read the PR in any detail. Just tried to use it in a bug I'm trying to fix. [JDK-8366490](https://bugs.openjdk.org/browse/JDK-8366490)
> 
> So I did this:
> 
> 
> diff --git a/src/hotspot/share/opto/vectorization.cpp b/src/hotspot/share/opto/vectorization.cpp
> index cd5aba6c31d..1b1f7c2f6f2 100644
> --- a/src/hotspot/share/opto/vectorization.cpp
> +++ b/src/hotspot/share/opto/vectorization.cpp
> @@ -1046,6 +1046,8 @@ BoolNode* VPointer::make_speculative_aliasing_check_with(const VPointer& other)
>        tty->print("size2: "); size2->dump();
>        tty->print_cr("span1: "); span1->dump_bfs(5, nullptr, "");
>        tty->print_cr("span2: "); span2->dump_bfs(5, nullptr, "");
> +
> +      phase->C->make_debug_print<jlong>("span ", &igvn, span1);
>      }
>  #endif
> 
> 
> And ran my test:
> `./java -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,Reduced1::test -XX:CompileCommand=printcompilation,Reduced1::* -XX:CompileCommand=dontinline,Reduced1::allocateArrays -XX:-TieredCompilation -Xbatch -XX:+StressGCM -XX:+TraceLoopOpts -XX:CompileCommand=TraceAutoVectorization,Reduced1::test,SW_INFO,SPECULATIVE_ALIASING_ANALYSIS -XX:+TraceNewVectors -XX:-LoopMultiversioning -XX:SuperWordAutomaticAlignment=0 -XX:+TraceDeoptimization Reduced1.java`
> 
> 
> class Reduced1 {
>     static final int N = 400;
> 
>     static void allocateArrays() {
>         for (int i = 0; 200_000 > i; ++i) {
>             int[] a = new int[N];
>         }
>     }
> 
>     static int[] test() {
>         int a[] = new int[N];
>         allocateArrays();
>         for (int k = 0; k < 500; k++) {
>             for (int i = 1; i < 69; i++) {
>                 a[i] =  14;
>                 a[4] -= 14;
>             }
>         }
>         return a;
>     }
> 
>     public static void main(String[] args) {
>         int[] gold = test();
>         for (int r = 0; r < 10; r++) {
>             int[] a = test();
>             System.out.println("a[4]: " + a[4]);
>             if (a[4] != gold[4]) {
>                 throw new RuntimeException("wrong value " + gold[4] + " " + a[4]);
>             }
>         }
>     }
> }
> 
> 
> But that got me some assert:
> 
> #  Internal Error (/home/empeter/Documents/oracle/jdk-fork2/open/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp:1126), pid=2630187, tid=2630207
> #  assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID) failed: expecting half
> 
>     33 Stack: [0x00007fe32ed13000,0x00007fe32ee13000],  sp=0x00007fe32ee0e8d0,  free space=1006k
>     34 Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
>     35 V  [libjvm.so+0x19...

When using `jlong` or `jdouble` you need to pass an additional placeholder half node @eme64. Here you can just do this:
```c++
phase->C->make_debug_print<jlong>("span ", &igvn, span1, phase->C->top());

The first of the additional examples (identity optimizations) hints at this but I should have probably made it more explicit in the description.

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

PR Comment: https://git.openjdk.org/jdk/pull/26475#issuecomment-3242604663


More information about the hotspot-dev mailing list