JDK-8314191 : C2 compilation fails with "bad AD file"
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18,19,20,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-08-14
  • Updated: 2024-01-30
  • Resolved: 2023-09-05
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 21 JDK 22
21.0.2Fixed 22 b14Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
java -Xcomp -XX:CompileCommand=compileonly,Test4::test*  -XX:-TieredCompilation Test4.java
CompileCommand: compileonly Test4.test* bool compileonly = true

o137  CountedLoopEnd  === o144 o155 o154  [[ o138 o140 7 ]] [gt] P=0,900000, C=-1,000000

--N: o137  CountedLoopEnd  === o144 o155 o154  [[ o138 o140 7 ]] [gt] P=0,900000, C=-1,000000

   --N: o155  Bool  === _ o154  [[ o137 ]] [gt]
   CMPOP  0  CMPOP
   CMPOPU  0  CMPOPU
   CMPOPUCF  0  CMPOPUCF
   CMPOP_VCMPPD  0  CMPOP_VCMPPD

   --N: o154  CmpU  === _ o85 o24  [[ o155 o137 ]] 
   RFLAGSREGU  100  compU_rReg

      --N: o85  Phi  === o144 o20 o97  [[ o97 o154 ]]  #int:min+1..0
      RREGI  0  RREGI
      RAX_REGI  0  RAX_REGI
      RBX_REGI  0  RBX_REGI
      RCX_REGI  0  RCX_REGI
      RDX_REGI  0  RDX_REGI
      RDI_REGI  0  RDI_REGI
      NO_RAX_RDX_REGI  0  NO_RAX_RDX_REGI
      NO_RBP_R13_REGI  0  NO_RBP_R13_REGI
      STACKSLOTI  100  storeSSI

      --N: o24  LoadI  === _ o7 o23  [[ o26 o154 ]]  @java/lang/Class (java/io/Serializable,java/lang/constant/Constable,java/lang/reflect/AnnotatedElement,java/lang/invoke/TypeDescriptor,java/lang/reflect/GenericDeclaration,java/lang/reflect/Type,java/lang/invoke/TypeDescriptor$OfField):exact+112 *, name=limit, idx=4; #int
      RREGI  0  RREGI
      RAX_REGI  0  RAX_REGI
      RBX_REGI  0  RBX_REGI
      RCX_REGI  0  RCX_REGI
      RDX_REGI  0  RDX_REGI
      RDI_REGI  0  RDI_REGI
      NO_RAX_RDX_REGI  0  NO_RAX_RDX_REGI
      NO_RBP_R13_REGI  0  NO_RBP_R13_REGI
      STACKSLOTI  100  storeSSI

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/opt/mach5/mesos/work_dir/slaves/741e9afd-8c02-45c3-b2e2-9db1450d0832-S24783/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d520ea84-8540-4e3f-bebb-7467656d99a8/runs/a75cd7f7-52f4-4fb9-b459-e34df625d6c3/workspace/open/src/hotspot/share/opto/matcher.cpp:1723), pid=476875, tid=476888
#  assert(false) failed: bad AD file
#
# JRE version: Java(TM) SE Runtime Environment (21.0+22) (fastdebug build 21-ea+22-LTS-1875)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 21-ea+22-LTS-1875, compiled mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x12ede38]  Matcher::Label_Root(Node const*, State*, Node*, Node*&)+0x508

Current CompileTask:
C2:   1865   82    b        Test4::test (30 bytes)

Stack: [0x00007fd3b5218000,0x00007fd3b5319000],  sp=0x00007fd3b5313bc0,  free space=1006k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x12ede38]  Matcher::Label_Root(Node const*, State*, Node*, Node*&)+0x508  (matcher.cpp:1723)
V  [libjvm.so+0x12ee447]  Matcher::match_tree(Node const*)+0x187
V  [libjvm.so+0x12f5a4d]  Matcher::xform(Node*, int)+0xc7d
V  [libjvm.so+0x12fb039]  Matcher::match()+0x1649
V  [libjvm.so+0x9b79ca]  Compile::Code_Gen()+0x9a
V  [libjvm.so+0x9bd7e9]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b89
V  [libjvm.so+0x814aa4]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x3c4
V  [libjvm.so+0x9c94f0]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x9e0
V  [libjvm.so+0x9ca398]  CompileBroker::compiler_thread_loop()+0x628
V  [libjvm.so+0xe6594e]  JavaThread::thread_main_inner()+0xee
V  [libjvm.so+0x17361e8]  Thread::call_run()+0xb8
V  [libjvm.so+0x14371da]  thread_native_entry(Thread*)+0x11a

Running with -XX:+TraceLoopOpts also triggers this:

Counted          Loop: N144/N138  counted [0,int),-2147483648 (-1 iters) 
Loop: N0/N0  has_sfpt
  Loop: N143/N142  limit_check profile_predicated predicated
    Loop: N144/N138  limit_check profile_predicated predicated counted [0,int),-2147483648 (-1 iters)  has_sfpt strip_mined
Loop: N0/N0  has_sfpt
  Loop: N143/N142  limit_check profile_predicated predicated sfpts={ 145 }
    Loop: N144/N138  limit_check profile_predicated predicated counted [int,int),#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/opt/mach5/mesos/work_dir/slaves/741e9afd-8c02-45c3-b2e2-9db1450d0832-S24783/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d520ea84-8540-4e3f-bebb-7467656d99a8/runs/a75cd7f7-52f4-4fb9-b459-e34df625d6c3/workspace/open/src/hotspot/share/opto/type.hpp:596), pid=479842, tid=479855
#  Error: assert(is_con()) failed
#
# JRE version: Java(TM) SE Runtime Environment (21.0+22) (fastdebug build 21-ea+22-LTS-1875)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 21-ea+22-LTS-1875, compiled mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x17585f3]  TypeInteger::get_con_as_long(BasicType) const+0xb3

Current CompileTask:
C2:   1725   82    b        Test4::test (30 bytes)

Stack: [0x00007f76b7638000,0x00007f76b7739000],  sp=0x00007f76b7732fb0,  free space=1003k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x17585f3]  TypeInteger::get_con_as_long(BasicType) const+0xb3  (type.hpp:596)
V  [libjvm.so+0x12236cc]  IdealLoopTree::dump_head()+0x51c
V  [libjvm.so+0x122396b]  IdealLoopTree::dump()+0x5b
V  [libjvm.so+0x123c8cd]  PhaseIdealLoop::build_and_optimize()+0xfdd
V  [libjvm.so+0x9be9d0]  PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x250
V  [libjvm.so+0x9bb02e]  Compile::Optimize()+0x10fe
V  [libjvm.so+0x9bd705]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1aa5
V  [libjvm.so+0x814aa4]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x3c4
V  [libjvm.so+0x9c94f0]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x9e0
V  [libjvm.so+0x9ca398]  CompileBroker::compiler_thread_loop()+0x628
V  [libjvm.so+0xe6594e]  JavaThread::thread_main_inner()+0xee
V  [libjvm.so+0x17361e8]  Thread::call_run()+0xb8
V  [libjvm.so+0x14371da]  thread_native_entry(Thread*)+0x11a
Comments
Waiting for JDK-8316719 to be resolved before continuing with backports.
22-09-2023

[jdk21u-fix-request] Approval Request from Aleksey Shipilëv Fixes a recent C2 regression.
21-09-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/190 Date: 2023-09-21 15:20:32 +0000
21-09-2023

Changeset: 969fcdb0 Author: Quan Anh Mai <qamai@openjdk.org> Date: 2023-09-05 16:15:54 +0000 URL: https://git.openjdk.org/jdk/commit/969fcdb0de962b6eda7b362af010cb138e45afcf
05-09-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15551 Date: 2023-09-02 11:34:17 +0000
02-09-2023

[~qamai] What JDK version and platform are you using? I just checked and I can reproduce it with latest JDK 22 (fastdebug build 22-ea+14-975) on Linux x64: java -Xcomp -XX:CompileCommand=compileonly,Test4::test* -XX:-TieredCompilation Test4.java
01-09-2023

[~thartmann] I cannot reproduce this issue with and without `-XX:+TraceLoopOpts`, but my educated guess is that the loop exit test `x + MIN_INT >= limit + (MIN_INT + 1)` is transformed into `x u> limit`, which violates the assumption regarding counted loop shape. As a result, my proposed fix is to not do the transformation if either side is a loop increment variable. Can you verify if the issue is still present and if this patch can fix it? Thanks a lot. diff --git a/src/hotspot/share/opto/subnode.cpp b/src/hotspot/share/opto/subnode.cpp index 1dcc8b045c2..c317759585a 100644 --- a/src/hotspot/share/opto/subnode.cpp +++ b/src/hotspot/share/opto/subnode.cpp @@ -1556,12 +1556,14 @@ Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { // and "cmp (add X min_jint) c" into "cmpu X (c + min_jint)" if (cop == Op_CmpI && cmp1_op == Op_AddI && + !is_cloop_increment(cmp1) && phase->type(cmp1->in(2)) == TypeInt::MIN) { if (cmp2_op == Op_ConI) { Node* ncmp2 = phase->intcon(java_add(cmp2->get_int(), min_jint)); Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), ncmp2)); return new BoolNode(ncmp, _test._test); } else if (cmp2_op == Op_AddI && + !is_cloop_increment(cmp2) && phase->type(cmp2->in(2)) == TypeInt::MIN) { Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), cmp2->in(1))); return new BoolNode(ncmp, _test._test); @@ -1572,12 +1574,14 @@ Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) { // and "cmp (add X min_jlong) c" into "cmpu X (c + min_jlong)" if (cop == Op_CmpL && cmp1_op == Op_AddL && + !is_cloop_increment(cmp1) && phase->type(cmp1->in(2)) == TypeLong::MIN) { if (cmp2_op == Op_ConL) { Node* ncmp2 = phase->longcon(java_add(cmp2->get_long(), min_jlong)); Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), ncmp2)); return new BoolNode(ncmp, _test._test); } else if (cmp2_op == Op_AddL && + !is_cloop_increment(cmp2) && phase->type(cmp2->in(2)) == TypeLong::MIN) { Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), cmp2->in(1))); return new BoolNode(ncmp, _test._test);
30-08-2023

Thanks to [~chagedorn] for helping with analyzing this failure!
14-08-2023

[~qamai], could you please have a look?
14-08-2023

This is a regression from JDK-8276162 in JDK 18 b24. The new cmp optimization introduces an unexpected pattern, triggering an assert in IdealLoopTree::dump_head with -XX:+TraceLoopOpts. The corresponding ad file rules were later removed by JDK-8302814 in JDK 21 b16, now leading to a failure during matching. ILW = Crash during C2 compilation, reproducible with single test, no workaround but disable compilation of affected method = HLM = P3
14-08-2023