JDK-8282218 : C1: Missing side effects of dynamic class loading during constant linkage
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-02-21
  • Updated: 2022-05-06
  • Resolved: 2022-05-06
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.
JDK 19
19 masterFixed
Related Reports
Relates :  
Description
(JDK-8282194 covers the special case of dynamic constants.)

C1 handles unresolved constants by performing constant resolution at runtime and then putting the constant value into the generated code by patching it. But it treats the not-yet-resolved value as a pure constant without any side effects. 

It's not the case for constants which trigger class loading using custom class loaders. (All non-String constants do that.)

There are no guarantees that there are no side effects during class loading, so C1 has to be conservative.
Comments
Changeset: 5212535a Author: Vladimir Ivanov <vlivanov@openjdk.org> Date: 2022-05-06 23:09:23 +0000 URL: https://git.openjdk.java.net/jdk/commit/5212535a276a92d96ca20bdcfccfbce956febdb1
06-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7612 Date: 2022-02-24 13:51:18 +0000
24-02-2022

ILW = Possible side effects of unresolved constants resulting in undefined behavior, low?, disable C1 compilation of affected method = HLM = P3
22-02-2022

public static Object[] run(boolean b) { int t1 = COUNTER; Class<?> c = null; if (b) { c = T.class; } int t2 = COUNTER; return new Object[] { c, t2 - t1}; } B0 (SV) [0, 7] -> B5 B1 dom B4 pred: B4 empty stack inlining depth 0 __bci__use__tid____instr____________________________________ 0 1 a4 <instance 0x000000014781c918 klass=java/lang/Class> . 0 8 i5 a4._112 (I) COUNTER 4 3 a6 null 7 2 i7 0 . 7 0 8 if i3 == i7 then B5 else B1 B5 [13, 13] -> B2 dom B0 pred: B0 empty stack inlining depth 0 __bci__use__tid____instr____________________________________ . 13 0 32 goto B2 B1 (V) [10, 13] -> B2 dom B0 pred: B0 empty stack inlining depth 0 __bci__use__tid____instr____________________________________ . 10 1 a9 <unloaded object 0x000000013000add0> . 13 0 10 goto B2 B2 (V) [13, 34] dom B0 pred: B5 B1 Locals: 1 i5 2 a11 [ a6 a9] empty stack inlining depth 0 __bci__use__tid____instr____________________________________ 17 1 i14 2 . 18 3 a15 new object array [i14] java/lang/Object . 24 0 a19 a15[i7] := a11 (L) 26 1 i20 1 29 1 i21 i5 - i5 // t2 - t1 . 30 1 a22 invokestatic(i21) java/lang/Integer.valueOf(I)Ljava/lang/Integer; stack [0:a15, 1:a15, 2:i20] . 33 0 a25 a15[i20] := a22 (L) . 34 0 a26 areturn a15
21-02-2022

$ java -Xcomp -XX:TieredStopAtLevel=1 -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,*Test::run -XX:+PrintCompilation -XX:-PrintIR CustomCLTest TRACE: CustomCLTest$Test 0 499 14 b 1 CustomCLTest$Test::run (35 bytes) [null, 0] TRACE: CustomCLTest$Test$T [class CustomCLTest$Test$T, 0] 1
21-02-2022