RFR: 8288204: GVN Crash: assert() failed: correct memory chain [v4]
Tobias Hartmann
thartmann at openjdk.org
Fri Dec 23 07:29:48 UTC 2022
On Fri, 23 Dec 2022 06:32:35 GMT, Yi Yang <yyang at openjdk.org> wrote:
>> Hi can I have a review for this fix? LoadBNode::Ideal crashes after performing GVN right after EA. The bad IR is as follows:
>>
>> 
>>
>> The memory input of Load#971 is Phi#1109 and the address input of Load#971 is AddP whose object base is CheckCastPP#335:
>>
>> The type of Phi#1109 is `byte[int:>=0]:exact+any *` while `byte[int:8]:NotNull:exact+any *,iid=177` is the type of CheckCastPP#335 due to EA, they have different alias index, that's why we hit the assertion at L226:
>>
>> https://github.com/openjdk/jdk/blob/b17a745d7f55941f02b0bdde83866aa5d32cce07/src/hotspot/share/opto/memnode.cpp#L207-L226
>> (t is `byte[int:>=0]:exact+any *`, t_adr is `byte[int:8]:NotNull:exact+any *,iid=177`).
>>
>> There is a long story. In the beginning, LoadB#971 is generated at array_copy_forward, and GVN transformed it iteratively:
>>
>> 971 LoadB === 1115 1046 969 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 1109 969 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 1109 969 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 1109 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> ...
>>
>> In this case, we get alias index 5 from address input AddP#969, and step it through MergeMem#1046, we found Phi#1109 then, that's why LoadB->in(Mem) is changed from MergeMem#1046 to Phi#1109 (Which finally leads to crash).
>>
>> 1046 MergeMem === _ 1 160 389 389 1109 1 1 389 1 1 1 1 1 1 1 1 1 1 1 1 1 709 709 709 709 882 888 894 190 190 912 191 [[ 1025 1021 1017 1013 1009 1005 1002 1001 998 996 991 986 981 976 971 966 962 961 960 121 122 123 124 1027 ]]
>>
>>
>> After applying this patch, some related nodes are pushed into the GVN worklist, before stepping through MergeMem#1046, the address input is already changed to AddP#473. i.e., we get alias index 32 from address input AddP#473, and step it through MergeMem#1046, we found StoreB#191 then,LoadB->in(Mem) is changed from MergeMem#1046 to StoreB#191.
>>
>> 971 LoadB === 1115 1046 969 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 1046 969 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 1046 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 1115 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 468 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 468 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> 971 LoadB === 390 191 473 [[ 972 ]] @byte[int:8]:NotNull:exact+any *,iid=177, idx=32; #byte !jvms: String::coder @ bci:0 (line 4540) String::getBytes @ bci:1 (line 4453) StringConcatHelper::prepend @ bci:21 (line 354) StringConcatHelper::simpleConcat @ bci:81 (line 425) DirectMethodHandle$Holder::invokeStatic @ bci:11 DelegatingMethodHandle$Holder::reinvoke_L @ bci:14 Invokers$Holder::linkToTargetMethod @ bci:6 Test::test @ bci:121 (line 22)
>> ...
>>
>> The well-formed IR looks like this:
>> 
>>
>> Thanks for your patience.
>
> Yi Yang has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains four commits:
>
> - review from tobias
> - Merge branch 'master' into gvn_crash
> - fix
> - 8288204 GVN Crash: assert() failed: correct memory chain
Thanks for making these changes.
Several tests (for example, compiler/arraycopy/TestArrayCopyAsLoadsStores.java) are now failing with:
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (workspace/open/src/hotspot/share/opto/phaseX.cpp:843), pid=3983761, tid=3983777
# assert(i->_idx >= k->_idx) failed: Idealize should return new nodes, use Identity to return old nodes
#
# JRE version: Java(TM) SE Runtime Environment (21.0) (fastdebug build 21-internal-LTS-2022-12-23-0641545.tobias.hartmann.jdk2)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 21-internal-LTS-2022-12-23-0641545.tobias.hartmann.jdk2, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V [libjvm.so+0x179ad0c] PhaseGVN::transform_no_reclaim(Node*)+0xec
Current CompileTask:
C2: 2222 478 b 4 compiler.arraycopy.TestArrayCopyAsLoadsStores::m14 (9 bytes)
Stack: [0x00007f86dc7f5000,0x00007f86dc8f6000], sp=0x00007f86dc8f20e0, free space=1012k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x179ad0c] PhaseGVN::transform_no_reclaim(Node*)+0xec (phaseX.cpp:843)
V [libjvm.so+0x141be0f] LibraryCallKit::inline_arraycopy()+0x71f (library_call.cpp:5289)
V [libjvm.so+0x1438712] LibraryIntrinsic::generate(JVMState*)+0x302 (library_call.cpp:115)
V [libjvm.so+0xcbfbe9] Parse::do_call()+0x389 (doCall.cpp:662)
V [libjvm.so+0x176c5f8] Parse::do_one_bytecode()+0x638 (parse2.cpp:2704)
V [libjvm.so+0x175a734] Parse::do_one_block()+0x844 (parse1.cpp:1555)
V [libjvm.so+0x175b697] Parse::do_all_blocks()+0x137 (parse1.cpp:707)
V [libjvm.so+0x176021d] Parse::Parse(JVMState*, ciMethod*, float)+0xb3d (parse1.cpp:614)
V [libjvm.so+0x918c40] ParseGenerator::generate(JVMState*)+0x110 (callGenerator.cpp:99)
V [libjvm.so+0xb0275d] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x168d (compile.cpp:760)
V [libjvm.so+0x916857] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x4e7 (c2compiler.cpp:113)
V [libjvm.so+0xb0fa2c] CompileBroker::invoke_compiler_on_method(CompileTask*)+0xa7c (compileBroker.cpp:2237)
V [libjvm.so+0xb107e8] CompileBroker::compiler_thread_loop()+0x5d8 (compileBroker.cpp:1916)
V [libjvm.so+0x107d066] JavaThread::thread_main_inner()+0x206 (javaThread.cpp:709)
V [libjvm.so+0x1a723c0] Thread::call_run()+0x100 (thread.cpp:224)
V [libjvm.so+0x1712553] thread_native_entry(Thread*)+0x103 (os_linux.cpp:739)
-------------
Changes requested by thartmann (Reviewer).
PR: https://git.openjdk.org/jdk/pull/9777
More information about the hotspot-compiler-dev
mailing list