JDK-8371457 : [lworld] C2: Incorrect type is used for array creation
  • Type: Sub-task
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: repo-valhalla
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2025-11-07
  • Updated: 2025-11-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
repo-valhallaUnresolved
Related Reports
Relates :  
Description
For this method:

static Integer test(Integer[] a) {
    return a[0];
}

when being called from:

static void run() {
    test(new Integer[1]);
}

Then the class check of a would fail and the method gets recompiled. If I change the method to:

static Integer test(Integer[] a) {
    field = new Integer[1];
    return a[0];
}

Then it is clear what is the issue, the class that is put in the new array is:

narrowklass: precise [precise java/lang/Integer: 0x0000759cf0007ff0 (java/io/Serializable,java/lang/Comparable,java/lang/constant/Constable,java/lang/constant/ConstantDesc):Constant:exact * (java/lang/Cloneable,java/io/Serializable): :Constant:exact:flat:refined_type *

While the one that is used in the speculative type check is:

narrowklass: precise [precise java/lang/Integer: 0x0000759cf0007ff0 (java/io/Serializable,java/lang/Comparable,java/lang/constant/Constable,java/lang/constant/ConstantDesc):Constant:exact * (java/lang/Cloneable,java/io/Serializable): :Constant:exact:flat:atomic:refined_type * 

(Notice the last part, one is flat:atomic, another is only flat)

Furthermore, if I don't compile run, then there is no decompilation happening. It seems the compiler use a different klass pointer from the one used by the interpreter.


Comments
I think this is a bug tail from the array metadata re-work. See JDK-8366705 (and JDK-8366668 / JDK-8370341).
10-11-2025