JDK-8333697 : C2: Hit MemLimit in PhaseCFG::global_code_motion
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23,24
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-06-06
  • Updated: 2024-11-19
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 25
25Unresolved
Related Reports
Relates :  
Relates :  
Description
I've observed that we hit the MemLimit with vmTestbase/vm/mlvm/meth/stress/compiler/i2c_c2i/Test.java in a seemingly unrelated patch over and over again but never with mainline. I've now observed it again with a completely different patch. I'm therefore filing this bug to further investigate since I don't think that my patches have anything to do with it.

Additional VM flags required:

-Xcomp -ea -esa -XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -server -XX:-TieredCompilation -XX:+DeoptimizeALot

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/opt/mach5/mesos/work_dir/slaves/a4a7850a-7c35-410a-b879-d77fbb2f6087-S15438/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/cac83830-bb2d-420d-b575-debda39cf5a6/runs/092497a8-b7ab-448c-acd2-5d0fd1e146cc/workspace/open/src/hotspot/share/compiler/compilationMemoryStatistic.cpp:559), pid=4003, tid=4104
#  fatal error: c2 java/lang/invoke/LambdaForm$MH+0x00007f3af3efb000::invoke((Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;): Hit MemLimit (limit: 1073741824 now: 1073752152)


Stack: [0x00007f3b338fa000,0x00007f3b339fa000],  sp=0x00007f3b339f4d30,  free space=1003k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x18a3fa2]  VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x482  (compilationMemoryStatistic.cpp:559)
V  [libjvm.so+0xa96855]  report_fatal(VMErrorType, char const*, int, char const*, ...)+0x105  (debug.cpp:214)
V  [libjvm.so+0x9c5eed]  CompilationMemoryStatistic::on_arena_change(long, Arena const*)+0x3fd  (compilationMemoryStatistic.cpp:559)
V  [libjvm.so+0x5f2efc]  Arena::grow(unsigned long, AllocFailStrategy::AllocFailEnum)+0x10c  (arena.cpp:299)
V  [libjvm.so+0xe09bdf]  IndexSet::initialize(unsigned int)+0x20f  (arena.hpp:119)
V  [libjvm.so+0xdf1016]  PhaseIFG::init(unsigned int)+0xf6  (ifg.cpp:56)
V  [libjvm.so+0xd697aa]  PhaseCFG::global_code_motion()+0x78a  (gcm.cpp:1577)
V  [libjvm.so+0xd6c171]  PhaseCFG::do_global_code_motion()+0x51  (gcm.cpp:1644)
V  [libjvm.so+0x9ec994]  Compile::Code_Gen()+0x2a4  (compile.cpp:2966)
V  [libjvm.so+0x9ef6ac]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1bdc  (compile.cpp:886)
V  [libjvm.so+0x844875]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5  (c2compiler.cpp:142)
V  [libjvm.so+0x9fb3e8]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928  (compileBroker.cpp:2303)
V  [libjvm.so+0x9fc078]  CompileBroker::compiler_thread_loop()+0x478  (compileBroker.cpp:1961)
V  [libjvm.so+0xea461c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:759)
V  [libjvm.so+0x17c0dd6]  Thread::call_run()+0xb6  (thread.cpp:225)
V  [libjvm.so+0x14a7ed7]  thread_native_entry(Thread*)+0x127  (os_linux.cpp:846)
Comments
I'm deferring this to JDK 25 for now. Feel free to still fix in JDK 24 if the fix is ready in time.
19-11-2024

After fixing this issue, please remove the -XX:CompileCommand=MemLimit,*.*,0 from TestFindInstMemRecursion.java (added in https://github.com/openjdk/jdk/pull/20238, for JDK-8324345) and verify that the test still passes.
05-08-2024

I've attached a simple test (Test.java) that results in a similar failure: Current CompileTask: C2:47493 10866 b javax.swing.plaf.basic.BasicLookAndFeel::initComponentDefaults (14883 bytes) Stack: [0x00007f22e91f3000,0x00007f22e92f3000], sp=0x00007f22e92edb00, free space=1002k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x1899f36] VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x486 (compilationMemoryStatistic.cpp:559) V [libjvm.so+0xa8a475] report_fatal(VMErrorType, char const*, int, char const*, ...)+0x105 (debug.cpp:214) V [libjvm.so+0x9b816e] CompilationMemoryStatistic::on_arena_change(long, Arena const*)+0x3fe (compilationMemoryStatistic.cpp:559) V [libjvm.so+0x5df6dc] Arena::grow(unsigned long, AllocFailStrategy::AllocFailEnum)+0x10c (arena.cpp:295) V [libjvm.so+0xdfcada] IndexSet::initialize(unsigned int, Arena*)+0x13a (arena.hpp:122) V [libjvm.so+0x122cf76] PhaseLive::getfreeset()+0x56 (live.cpp:214) V [libjvm.so+0x122dcfb] PhaseLive::compute(unsigned int)+0x2fb (live.cpp:102) V [libjvm.so+0xd5c831] PhaseCFG::global_code_motion()+0x7c1 (gcm.cpp:1581) V [libjvm.so+0xd5f1c1] PhaseCFG::do_global_code_motion()+0x51 (gcm.cpp:1644) V [libjvm.so+0x9debd4] Compile::Code_Gen()+0x2a4 (compile.cpp:2948) V [libjvm.so+0x9e1a2c] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1bec (compile.cpp:885) V [libjvm.so+0x833b95] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5 (c2compiler.cpp:142) V [libjvm.so+0x9ed588] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928 (compileBroker.cpp:2303) V [libjvm.so+0x9ee218] CompileBroker::compiler_thread_loop()+0x478 (compileBroker.cpp:1961) V [libjvm.so+0xe97b1c] JavaThread::thread_main_inner()+0xcc (javaThread.cpp:757) V [libjvm.so+0x17b6646] Thread::call_run()+0xb6 (thread.cpp:225) V [libjvm.so+0x149fd57] thread_native_entry(Thread*)+0x127 (os_linux.cpp:858) Lock stack of current Java thread (top to bottom):
16-07-2024

Roland, I'm assigning this to you for now since you mentioned that you'll take a look. Feel free to un-assign again.
26-06-2024

Another failure: Current CompileTask: C2:103813 9152 javax.swing.plaf.basic.BasicLookAndFeel::initComponentDefaults (14883 bytes) Stack: [0x00007fae5440b000,0x00007fae5450b000], sp=0x00007fae54505ac0, free space=1002k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x1895156] VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x486 (compilationMemoryStatistic.cpp:559) V [libjvm.so+0xa892c5] report_fatal(VMErrorType, char const*, int, char const*, ...)+0x105 V [libjvm.so+0x9b727e] CompilationMemoryStatistic::on_arena_change(long, Arena const*)+0x3fe V [libjvm.so+0x5de85c] Arena::grow(unsigned long, AllocFailStrategy::AllocFailEnum)+0x10c V [libjvm.so+0xdfb617] IndexSet::populate_free_list()+0xf7 V [libjvm.so+0xdfba15] IndexSet::alloc_block_containing(unsigned int)+0x115 V [libjvm.so+0x122c46d] PhaseLive::add_liveout(Block_List&, Block*, IndexSet*, VectorSet&)+0x2fd V [libjvm.so+0x122d2fd] PhaseLive::compute(unsigned int)+0x9fd V [libjvm.so+0xd5bffc] PhaseCFG::global_code_motion()+0x7bc V [libjvm.so+0xd5e991] PhaseCFG::do_global_code_motion()+0x51 V [libjvm.so+0x9ddd54] Compile::Code_Gen()+0x2a4 V [libjvm.so+0x9e0bd3] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1c23 V [libjvm.so+0x832825] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x1d5 V [libjvm.so+0x9ec798] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x928 V [libjvm.so+0x9ed428] CompileBroker::compiler_thread_loop()+0x478 V [libjvm.so+0xe96e0c] JavaThread::thread_main_inner()+0xcc V [libjvm.so+0x17b1b76] Thread::call_run()+0xb6 V [libjvm.so+0x149b867] thread_native_entry(Thread*)+0x127 Lock stack of current Java thread (top to bottom):
26-06-2024

ILW = Excessive memory usage which might be expected, single test with two non-mainline patches and only observed with DeoptimizeALot, no workaround = MLH = P4
06-06-2024