JDK-8319793 : C2 compilation fails with "Bad graph detected in build_loop_late" after JDK-8279888
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 19,21,22,23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-11-09
  • Updated: 2024-07-01
  • Resolved: 2024-01-11
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 JDK 23
21.0.5-oracleFixed 22Resolved 23 b06Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Attached Test.java fails after JDK-8279888.

java -Xbatch -XX:-TieredCompilation Test.java

Bad graph detected in build_loop_late
n:   790  AddP  === _ 73 791 32  [[ 789 ]]  !orig=589 !jvms: Test::test @ bci:76 (line 18)
early(n):   907  Region  === 907 906 1020  [[ 907 292 289 921 924 925 926 930 932 939 948 ]]  !orig=[281] !jvms: Test::test @ bci:35 (line 12)
n->in(1):    73  CheckCastPP  === 70 68  [[ 842 105 365 413 152 163 174 589 590 590 781 790 791 791 864 865 865 977 978 978 1251 1252 1252 ]]  #float[int:0..max-2] (java/lang/Cloneable,java/io/Serializable):NotNull:exact * !orig=[384] !jvms: Test::test @ bci:3 (line 6)
early(n->in(1)):    70  Proj  === 69  [[ 625 73 626 105 ]] #0 !jvms: Test::test @ bci:3 (line 6)
n->in(1)->in(1):    68  Proj  === 56  [[ 69 73 ]] #5 !jvms: Test::test @ bci:3 (line 6)
early(n->in(1)->in(1)):    56  AllocateArray  === 5 6 7 8 1 (47 25 52 24 55 1 1 1 1 1 1 ) [[ 57 58 59 66 67 68 ]]  rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, int, bool ) Test::test @ bci:3 (line 6) !jvms: Test::test @ bci:3 (line 6)
n->in(2):   791  AddP  === _ 73 73 792  [[ 790 ]]  !orig=590 !jvms: Test::test @ bci:76 (line 18)
early(n->in(2)):   907  Region  === 907 906 1020  [[ 907 292 289 921 924 925 926 930 932 939 948 ]]  !orig=[281] !jvms: Test::test @ bci:35 (line 12)
n->in(2)->in(1):    73  CheckCastPP  === 70 68  [[ 842 105 365 413 152 163 174 589 590 590 781 790 791 791 864 865 865 977 978 978 1251 1252 1252 ]]  #float[int:0..max-2] (java/lang/Cloneable,java/io/Serializable):NotNull:exact * !orig=[384] !jvms: Test::test @ bci:3 (line 6)
early(n->in(2)->in(1)):    70  Proj  === 69  [[ 625 73 626 105 ]] #0 !jvms: Test::test @ bci:3 (line 6)
n->in(2)->in(2):    73  CheckCastPP  === 70 68  [[ 842 105 365 413 152 163 174 589 590 590 781 790 791 791 864 865 865 977 978 978 1251 1252 1252 ]]  #float[int:0..max-2] (java/lang/Cloneable,java/io/Serializable):NotNull:exact * !orig=[384] !jvms: Test::test @ bci:3 (line 6)
early(n->in(2)->in(2)):    70  Proj  === 69  [[ 625 73 626 105 ]] #0 !jvms: Test::test @ bci:3 (line 6)
n->in(2)->in(3):   792  LShiftL  === _ 802 30  [[ 791 ]]  !orig=588 !jvms: Test::test @ bci:76 (line 18)
early(n->in(2)->in(3)):   907  Region  === 907 906 1020  [[ 907 292 289 921 924 925 926 930 932 939 948 ]]  !orig=[281] !jvms: Test::test @ bci:35 (line 12)
n->in(3):    32  ConL  === 0  [[ 589 98 646 374 790 794 856 864 868 969 977 981 1243 1251 1255 ]]  #long:16
early(n->in(3)):     0  Root  === 0 156 167 178 615 369 417 616 1232 1113 1129 1222 1168 1184 1199 1209  [[ 0 1 3 20 21 22 25 26 557 30 32 520 45 46 49 53 504 83 84 87 465 137 138 140 151 162 173 207 208 210 212 213 214 216 218 266 270 364 354 757 1069 1070 1078 1085 1332 1333 1346 ]] 

LCA(n):   782  IfTrue  === 783  [[ 781 788 789 793 797 801 ]] #1 !orig=[700],[418] !jvms: Test::test @ bci:47 (line 15)
n->out(0):   789  StoreF  === 782 947 790 557  [[ 787 811 824 ]]  @float[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=7;  Memory: @float[int:0..max-2] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=7; !orig=591,1305 !jvms: Test::test @ bci:76 (line 18)
later(n->out(0)):   782  IfTrue  === 783  [[ 781 788 789 793 797 801 ]] #1 !orig=[700],[418] !jvms: Test::test @ bci:47 (line 15)
n->out(0)->out(0):   787  MergeMem  === _ 1 7 337 1 120 120 789 793 338 1 1 788  [[ 781 ]]  { N337:rawptr:BotPTR - N120:java/lang/Object * N120:java/lang/Object+8 * [narrowklass] N789:float[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any * N793:long[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any * N338:java/lang/Throwable (java/io/Serializable)+20 * [narrow] - - N788:int[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any * }  Memory: @BotPTR *+bot, idx=Bot; !orig=594 !jvms: Test::test @ bci:80 (line 9)
later(n->out(0)->out(0)):   782  IfTrue  === 783  [[ 781 788 789 793 797 801 ]] #1 !orig=[700],[418] !jvms: Test::test @ bci:47 (line 15)
n->out(0)->out(1):   811  Phi  === 810 71 789  [[ 1001 ]]  #memory  Memory: @float[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=7; !orig=[195],[382] !jvms: Test::test @ bci:22 (line 11)
later(n->out(0)->out(1)):   810  Loop  === 810 179 779  [[ 810 1002 811 812 813 814 815 816 ]] 
n->out(0)->out(2):   824  Phi  === 818 789 919  [[ 15 ]]  #memory  Memory: @float[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=7;
later(n->out(0)->out(2)):   818  Region  === 818 817 915  [[ 818 615 823 824 825 827 830 ]]  !orig=[602] !jvms: Test::test @ bci:19 (line 9)

idoms of early "907 Region":
idom[2]:   1003  If
idom[1]:   1004  IfTrue
idom[0]:   1005  If
n:          907  Region

idoms of (wrong) LCA "782 IfTrue":
idom[2]:   1003  If
idom[1]:    269  Region
idom[0]:    783  RangeCheck
n:          782  IfTrue

Real LCA of early "907 Region" (idom[2]) and wrong LCA "782 IfTrue" (idom[2]):
 1003  If  === 1002 973  [[ 1004 1016 ]] P=0,999000, C=-1,000000 !orig=204 !jvms: Test::test @ bci:25 (line 11)


# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/workspace/open/src/hotspot/share/opto/loopnode.cpp:6146), pid=3992598, tid=3992612
#  assert(false) failed: Bad graph detected in build_loop_late
#
# JRE version: Java(TM) SE Runtime Environment (22.0+23) (fastdebug build 22-ea+23-1832)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-ea+23-1832, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x12afcf3]  PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0x8a3

Current CompileTask:
C2:2516  412   !b        Test::test (84 bytes)

Stack: [0x00007f41efeff000,0x00007f41f0000000],  sp=0x00007f41efffad00,  free space=1007k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x12afcf3]  PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0x8a3  (loopnode.cpp:6146)
V  [libjvm.so+0x12afdef]  PhaseIdealLoop::build_loop_late(VectorSet&, Node_List&, Node_Stack&)+0xaf
V  [libjvm.so+0x12b06fb]  PhaseIdealLoop::build_and_optimize()+0x62b
V  [libjvm.so+0x9feabb]  PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x3ab
V  [libjvm.so+0x9f96c6]  Compile::Optimize()+0xf36
V  [libjvm.so+0x9fd101]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b41
V  [libjvm.so+0x849717]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x207
V  [libjvm.so+0xa09270]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x980
V  [libjvm.so+0xa0a008]  CompileBroker::compiler_thread_loop()+0x508
V  [libjvm.so+0xec463c]  JavaThread::thread_main_inner()+0xcc
V  [libjvm.so+0x17a510a]  Thread::call_run()+0xba
V  [libjvm.so+0x14acc4a]  thread_native_entry(Thread*)+0x12a
Comments
[jdk21u-fix-request] Approval Request from Martin Should get backported for parity with 21.0.5-oracle. The backport has been reviewed and tier 1-4 have passed.
14-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/715 Date: 2024-06-13 14:32:55 +0000
13-06-2024

I think this is less important once JDK-8318889 is in, which gets the clean bailout.
06-02-2024

Deferral Request: Complex and incomplete fix (see follow-up fix JDK-8323274) that needs some time to stabilize. Not a regression in JDK 22.
12-01-2024

Changeset: b922f8d4 Author: Roland Westrelin <roland@openjdk.org> Date: 2024-01-11 09:00:44 +0000 URL: https://git.openjdk.org/jdk/commit/b922f8d45951250b7c39cb179b9bc1a8a6256a9e
11-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16886 Date: 2023-11-29 15:52:59 +0000
29-11-2023

Paging [~roland], [~chagedorn].
09-11-2023

A less reduced version of the same JavaFuzzer Test (Test2.java) triggers a different assert: # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/open/src/hotspot/share/opto/chaitin.cpp:284), pid=4083260, tid=4083287 # Error: assert(src) failed # # JRE version: Java(TM) SE Runtime Environment (22.0+23) (fastdebug build 22-ea+23-1845) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-ea+23-1845, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x8b7145] PhaseChaitin::Union(Node const*, Node const*)+0x2d5 Current CompileTask: C2:5962 413 !b Test2::test (108 bytes) Stack: [0x00007fefc0cee000,0x00007fefc0def000], sp=0x00007fefc0deabd0, free space=1010k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x8b7145] PhaseChaitin::Union(Node const*, Node const*)+0x2d5 (chaitin.cpp:284) V [libjvm.so+0x99c252] PhaseCoalesce::combine_these_two(Node*, Node*)+0x402 V [libjvm.so+0x99cb38] PhaseAggressiveCoalesce::coalesce(Block*)+0x128 V [libjvm.so+0x99ce82] PhaseCoalesce::coalesce_driver()+0x42 V [libjvm.so+0x8c3dad] PhaseChaitin::Register_Allocate()+0x29d V [libjvm.so+0x9fa37d] Compile::Code_Gen()+0x32d V [libjvm.so+0x9fd1af] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1c2f V [libjvm.so+0x8496d7] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x207 V [libjvm.so+0xa09230] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x980 V [libjvm.so+0xa09fc8] CompileBroker::compiler_thread_loop()+0x508 V [libjvm.so+0xec45ec] JavaThread::thread_main_inner()+0xcc V [libjvm.so+0x17a518a] Thread::call_run()+0xba V [libjvm.so+0x14ace9a] thread_native_entry(Thread*)+0x12a This might well be a different issue though but I'll keep both issue in one bug for now. This one only reproduces since JDK-8305637.
09-11-2023

ILW = Crash due to bad graph, single Java Fuzzer fail, disable compilation of affected method = HLM = P3
09-11-2023

Similar to JDK-8314111, this might be another duplicate of JDK-8275202. Or it's related to JDK-8318826.
09-11-2023