JDK-8329777 : Make C2 more robust in the face of hash collisions during GVN
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,21,23
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-04-05
  • Updated: 2024-04-08
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
tbdUnresolved
Related Reports
Relates :  
Description
Working on JDK-8321204, I noticed that there are issues in C2 when Node::hash returns 0 == Node::NO_HASH, which can happen in extremely rare cases but should be harmless:
https://github.com/openjdk/jdk/blob/f26e4308992d989d71e7fbfaa3feb95f0ea17c06/src/hotspot/share/opto/node.hpp#L1114-L1118

[~dlong] suggested to adjust the hash method to never return 0: https://github.com/openjdk/jdk/pull/18647#issuecomment-2040642019

We should investigate that.

Running some testing with attached patch that always returns 0 triggers massive failures. Although some of them are surely false positives since the patch basically disables GVN, we should investigate if there are real issues. Failures include but are not limited to:

#  Internal Error (/workspace/open/src/hotspot/share/opto/escape.cpp:2113), pid=34319, tid=34737
#  assert(base == null_obj) failed: only null ptr base expected here

Stack: [0x00007f8a051f2000,0x00007f8a052f2000],  sp=0x00007f8a052ecb50,  free space=1002k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0xbb4df4]  ConnectionGraph::find_field_value(FieldNode*)+0x114  (escape.cpp:2113)
V  [libjvm.so+0xbc477d]  ConnectionGraph::complete_connection_graph(GrowableArray<PointsToNode*>&, GrowableArray<JavaObjectNode*>&, GrowableArray<JavaObjectNode*>&, GrowableArray<FieldNode*>&)+0x19d  (escape.cpp:1812)
V  [libjvm.so+0xbc7255]  ConnectionGraph::compute_escape()+0x1e85  (escape.cpp:283)
V  [libjvm.so+0xbc7f91]  ConnectionGraph::do_analysis(Compile*, PhaseIterGVN*)+0xf1  (escape.cpp:117)
V  [libjvm.so+0x9e9c7a]  Compile::Optimize()+0x63a  (compile.cpp:2342)
V  [libjvm.so+0x9edad0]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b50  (compile.cpp:861)
V  [libjvm.so+0x841a45]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5  (c2compiler.cpp:142)
V  [libjvm.so+0x9f98d8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928  (compileBroker.cpp:2310)
V  [libjvm.so+0x9fa568]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1969)
V  [libjvm.so+0xeab86c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17ab836]  Thread::call_run()+0xb6  (thread.cpp:221)
V  [libjvm.so+0x14b0867]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:853)

#  Internal Error (/workspace/open/src/hotspot/share/opto/node.hpp:412), pid=2893220, tid=2893234
#  assert(_outcnt==1) failed: not unique

Stack: [0x00007f4a23cfe000,0x00007f4a23dfe000],  sp=0x00007f4a23df9230,  free space=1004k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x12d67aa]  PhaseMacroExpand::expand_subtypecheck_node(SubTypeCheckNode*)+0xa9a  (node.hpp:412)
V  [libjvm.so+0x12dca83]  PhaseMacroExpand::expand_macro_nodes()+0xa83  (macro.cpp:2588)
V  [libjvm.so+0x9ea548]  Compile::Optimize()+0xf08  (compile.cpp:2456)
V  [libjvm.so+0x9edad0]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b50  (compile.cpp:861)
V  [libjvm.so+0x841a45]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5  (c2compiler.cpp:142)
V  [libjvm.so+0x9f98d8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928  (compileBroker.cpp:2310)
V  [libjvm.so+0x9fa568]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1969)
V  [libjvm.so+0xeab86c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17ab836]  Thread::call_run()+0xb6  (thread.cpp:221)
V  [libjvm.so+0x14b0867]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:853)

#  Internal Error (/workspace/open/src/hotspot/share/opto/compile.cpp:3326), pid=3376095, tid=3376135
#  assert(!addp->is_AddP() || addp->in(AddPNode::Base)->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode::Base)) failed: Base pointers must match (addp 932)

Stack: [0x00007f501d010000,0x00007f501d110000],  sp=0x00007f501d10ade0,  free space=1003k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x9db841]  Compile::final_graph_reshaping_main_switch(Node*, Final_Reshape_Counts&, unsigned int, Unique_Node_List&)+0x1531  (compile.cpp:3326)
V  [libjvm.so+0x9dc6ef]  Compile::final_graph_reshaping_impl(Node*, Final_Reshape_Counts&, Unique_Node_List&) [clone .part.0]+0x15f  (compile.cpp:3172)
V  [libjvm.so+0x9dd004]  Compile::final_graph_reshaping_walk(Node_Stack&, Node*, Final_Reshape_Counts&, Unique_Node_List&)+0x174  (compile.cpp:3121)
V  [libjvm.so+0x9e888d]  Compile::final_graph_reshaping()+0x54d  (compile.cpp:4030)
V  [libjvm.so+0x9ea6fd]  Compile::Optimize()+0x10bd  (compile.cpp:2503)
V  [libjvm.so+0x9edad0]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b50  (compile.cpp:861)
V  [libjvm.so+0x841a45]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5  (c2compiler.cpp:142)
V  [libjvm.so+0x9f98d8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928  (compileBroker.cpp:2310)
V  [libjvm.so+0x9fa568]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1969)
V  [libjvm.so+0xeab86c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17ab836]  Thread::call_run()+0xb6  (thread.cpp:221)
V  [libjvm.so+0x14b0867]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:853)

#  Internal Error (/workspace/open/src/hotspot/share/compiler/compileBroker.cpp:2118), pid=524626, tid=524650
#  fatal error: Not compilable at tier 4: failed spill-split-recycle sanity check

Stack: [0x00007fb2b37f9000,0x00007fb2b38f9000],  sp=0x00007fb2b38f7470,  free space=1017k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x9f4aab]  CompileBroker::handle_compile_error(CompilerThread*, CompileTask*, ciEnv*, int, char const*)+0x6b  (compileBroker.cpp:2118)
V  [libjvm.so+0x9f92bb]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x30b  (compileBroker.cpp:2344)
V  [libjvm.so+0x9fa568]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1969)
V  [libjvm.so+0xeab86c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17ab836]  Thread::call_run()+0xb6  (thread.cpp:221)
V  [libjvm.so+0x14b0867]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:853)

#  Internal Error (/workspace/open/src/hotspot/cpu/x86/assembler_x86.cpp:11719), pid=24569, tid=24587
#  assert(((!attributes->uses_vl()) || (attributes->get_vector_len() == AVX_512bit) || (!_legacy_mode_vl) || (attributes->is_legacy_mode()))) failed: XMM register should be 0-15

Stack: [0x00007f5e24cc8000,0x00007f5e24dc8000],  sp=0x00007f5e24dc3840,  free space=1006k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x645c6b]  Assembler::vex_prefix_and_encode(int, int, int, Assembler::VexSimdPrefix, Assembler::VexOpcode, InstructionAttr*)+0x28b  (assembler_x86.cpp:11719)
V  [libjvm.so+0x65d093]  Assembler::simd_prefix_and_encode(XMMRegister, XMMRegister, XMMRegister, Assembler::VexSimdPrefix, Assembler::VexOpcode, InstructionAttr*) [clone .constprop.0]+0x113  (assembler_x86.cpp:11766)
V  [libjvm.so+0x661157]  Assembler::vpmovsxbd(XMMRegister, XMMRegister, int)+0x77  (assembler_x86.cpp:5024)
V  [libjvm.so+0x828854]  C2_MacroAssembler::vconvert_b2x(BasicType, XMMRegister, XMMRegister, int)+0x84  (c2_MacroAssembler_x86.cpp:2809)
V  [libjvm.so+0x40f84b]  vcastBtoXNode::emit(CodeBuffer&, PhaseRegAlloc*) const+0x10b  (x86.ad:7003)
V  [libjvm.so+0x14d1336]  PhaseOutput::scratch_emit_size(Node const*)+0x376  (output.cpp:3366)
V  [libjvm.so+0x14c9a7a]  PhaseOutput::shorten_branches(unsigned int*)+0x34a  (output.cpp:544)
V  [libjvm.so+0x14db3ca]  PhaseOutput::Output()+0xa1a  (output.cpp:345)
V  [libjvm.so+0x9eb03c]  Compile::Code_Gen()+0x4ac  (compile.cpp:3031)
V  [libjvm.so+0x9edbb6]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1c36  (compile.cpp:894)
V  [libjvm.so+0x841a45]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5  (c2compiler.cpp:142)
V  [libjvm.so+0x9f98d8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928  (compileBroker.cpp:2310)
V  [libjvm.so+0x9fa568]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1969)
V  [libjvm.so+0xeab86c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17ab836]  Thread::call_run()+0xb6  (thread.cpp:221)
V  [libjvm.so+0x14b0867]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:853)

We might want to add a stress flag to trigger this and similar hash collisions more often.
Comments
> [~dlong] suggested to adjust the hash method to never return 0 Yes, since 0 is treated specially by C2.
08-04-2024

I just tried and we then fail already during the JDK build: # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/workspace/open/src/hotspot/share/opto/node.hpp:447), pid=2590147, tid=2590179 # assert(!VerifyHashTableKeys || _hash_lock == 0) failed: remove node from hash table before modifying it # # JRE version: Java(TM) SE Runtime Environment (23.0) (fastdebug build 23-internal-2024-04-08-0639099.tobias.hartmann.jdk2) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 23-internal-2024-04-08-0639099.tobias.hartmann.jdk2, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x4a9e84] Node::set_req(unsigned int, Node*)+0x2b4 Current CompileTask: C2:349 25 4 java.lang.String::charAt (25 bytes) Stack: [0x000014bd747a3000,0x000014bd748a3000], sp=0x000014bd7489ee00, free space=1007k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x4a9e84] Node::set_req(unsigned int, Node*)+0x2b4 (node.hpp:447) V [libjvm.so+0xd8c8d7] GraphKit::uncommon_trap(int, ciKlass*, char const*, bool, bool) [clone .part.0]+0x2d7 (graphKit.cpp:2163) V [libjvm.so+0x14f2ee3] Parse::adjust_map_after_if(BoolTest::mask, Node*, float, Parse::Block*)+0x2c3 (graphKit.hpp:750) V [libjvm.so+0x14f3f93] Parse::do_if(BoolTest::mask, Node*)+0x703 (parse2.cpp:1534) V [libjvm.so+0x14fcbd7] Parse::do_one_bytecode()+0x28b7 (parse2.cpp:2682) V [libjvm.so+0x14e827a] Parse::do_one_block()+0x20a (parse1.cpp:1606) V [libjvm.so+0x14e9736] Parse::do_all_blocks()+0x136 (parse1.cpp:724) V [libjvm.so+0x14eda55] Parse::Parse(JVMState*, ciMethod*, float)+0xb15 (parse1.cpp:628) V [libjvm.so+0x842329] ParseGenerator::generate(JVMState*)+0x169 (callGenerator.cpp:99) V [libjvm.so+0x84597a] PredictedCallGenerator::generate(JVMState*)+0x3aa (callGenerator.cpp:924) V [libjvm.so+0xb7e4a2] Parse::do_call()+0x602 (doCall.cpp:675) V [libjvm.so+0x14fa648] Parse::do_one_bytecode()+0x328 (parse2.cpp:2713) V [libjvm.so+0x14e827a] Parse::do_one_block()+0x20a (parse1.cpp:1606) V [libjvm.so+0x14e9736] Parse::do_all_blocks()+0x136 (parse1.cpp:724) V [libjvm.so+0x14eda55] Parse::Parse(JVMState*, ciMethod*, float)+0xb15 (parse1.cpp:628) V [libjvm.so+0x842329] ParseGenerator::generate(JVMState*)+0x169 (callGenerator.cpp:99) V [libjvm.so+0x9ea9ce] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x163e (compile.cpp:791) V [libjvm.so+0x83fd85] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5 (c2compiler.cpp:142) V [libjvm.so+0x9f6b88] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928 (compileBroker.cpp:2304) V [libjvm.so+0x9f7818] CompileBroker::compiler_thread_loop()+0x478 (compileBroker.cpp:1963) V [libjvm.so+0xea2e2c] JavaThread::thread_main_inner()+0xcc (javaThread.cpp:759) V [libjvm.so+0x17a3426] Thread::call_run()+0xb6 (thread.cpp:221) V [libjvm.so+0x149a307] thread_native_entry(Thread*)+0x127 (os_linux.cpp:853)
08-04-2024

Did you tried to always return not 0 value?
05-04-2024

ILW = Potential issues when node hash is zero in C2, extremely rare - never observed, no workaround but disable compilation = MLH = P4
05-04-2024