JDK-8316756 : C2 EA fails with "missing memory path" when encountering unsafe_arraycopy stub call
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-09-22
  • Updated: 2024-06-13
  • Resolved: 2024-01-17
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 22Fixed 23 b06Fixed
Related Reports
Relates :  
Relates :  
Description
When running the benchmark from the subject line (attached), I'm seeing the following crash:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (h:\openjdk\git-jdk2\src\hotspot\share\opto\escape.cpp:4029), pid=12256, tid=8644
#  assert(false) failed: EA: missing memory path
#
# JRE version: OpenJDK Runtime Environment (22.0) (fastdebug build 22-internal-adhoc.jorn.git-jdk2)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 22-internal-adhoc.jorn.git-jdk2, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Core dump will be written. Default location: H:\openjdk\git-jdk2\make\hs_err_pid12256.mdmp
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#

With the latest master branch from the openjdk/jdk repo. It has the following stack trace:

Current thread (0x00000271b0168ca0):  JavaThread "C2 CompilerThread4" daemon [_thread_in_native, id=8644, stack(0x0000007f41700000,0x0000007f41800000) (1024K)]


Current CompileTask:
C2:    585  776 %     4       org.openjdk.bench.java.lang.foreign.jmh_generated.MemorySegmentCopyUnsafe_panama_jmhTest::panama_avgt_jmhStub @ 13 (52 bytes)

Stack: [0x0000007f41700000,0x0000007f41800000]
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0xc81a01]  os::win32::platform_print_native_stack+0x101  (os_windows_x86.cpp:236)
V  [jvm.dll+0xfcef7d]  VMError::report+0x147d  (vmError.cpp:1000)
V  [jvm.dll+0xfd13c5]  VMError::report_and_die+0x645  (vmError.cpp:1814)
V  [jvm.dll+0xfd1ae4]  VMError::report_and_die+0x64  (vmError.cpp:1579)
V  [jvm.dll+0x553dbb]  report_vm_error+0x5b  (debug.cpp:191)
V  [jvm.dll+0x624cbc]  ConnectionGraph::split_unique_types+0x2a1c  (escape.cpp:4029)
V  [jvm.dll+0x617060]  ConnectionGraph::compute_escape+0x13a0  (escape.cpp:381)
V  [jvm.dll+0x61819e]  ConnectionGraph::do_analysis+0xae  (escape.cpp:116)
V  [jvm.dll+0x4dd63f]  Compile::Optimize+0x67f  (compile.cpp:2315)
V  [jvm.dll+0x4db1c5]  Compile::Compile+0x11d5  (compile.cpp:855)
V  [jvm.dll+0x3eff8b]  C2Compiler::compile_method+0x13b  (c2compiler.cpp:122)
V  [jvm.dll+0x4f6da6]  CompileBroker::invoke_compiler_on_method+0x846  (compileBroker.cpp:2284)
V  [jvm.dll+0x4f417c]  CompileBroker::compiler_thread_loop+0x31c  (compileBroker.cpp:1943)
V  [jvm.dll+0x801f79]  JavaThread::thread_main_inner+0x279  (javaThread.cpp:721)
V  [jvm.dll+0xf33a17]  Thread::call_run+0x1b7  (thread.cpp:225)
V  [jvm.dll+0xc7f462]  os::win32::thread_native_entry+0xa2  (os_windows.cpp:547)
C  [ucrtbase.dll+0x29363]  (no source info available)
C  [KERNEL32.DLL+0x1257d]  (no source info available)
C  [ntdll.dll+0x5aa68]  (no source info available)

I've tried creating a standalone reproducer without success This code does not use any novel compiler intrinsics. It is largely plain Java code but it contains a call to Unsafe::copyMemory and accesses to off-heap memory. I've also tried disabling inlining of the benchmark method and that makes the crash go away, there may be a bad interaction between the JMH wrapper and the benchmark code. FWIW, running with '-Djmh.blackhole.autoDetect=false' does not fix the crash. JHM version is the latest 1.38 (built from source, but I've reproduced with 1.34 as well)

I can reliably reproduce the crash.


Additional output before the crash:
225  StoreB  === 360 752 234 327  [[ 118 ]]  @rawptr:BotPTR, idx=Raw;  Memory: @rawptr:BotPTR, idx=Raw; !jvms: Unsafe::copyMemory @ bci:29 (line 806) ScopedMemoryAccess::copyMemoryInternal @ bci:28 (line 147) ScopedMemoryAccess::copyMemory @ bci:12 (line 129) AbstractMemorySegmentImpl::copy @ bci:197 (line 619) MemorySegment::copy @ bci:33 (line 1341) MemorySegment::copy @ bci:13 (line 1288) MemorySegment::copyFrom @ bci:10 (line 812) MemorySegmentCopyUnsafe::panama @ bci:44 (line 66)
 118  CallLeafNoFP  === 360 1 225 31 1 (226 227 134 1 ) [[ 62 233 ]] # unsafe_arraycopy void ( NotNull *+bot, NotNull *+bot, long, half ) !jvms: Unsafe::copyMemory @ bci:29 (line 806) ScopedMemoryAccess::copyMemoryInternal @ bci:28 (line 147) ScopedMemoryAccess::copyMemory @ bci:12 (line 129) AbstractMemorySegmentImpl::copy @ bci:197 (line 619) MemorySegment::copy @ bci:33 (line 1341) MemorySegment::copy @ bci:13 (line 1288) MemorySegment::copyFrom @ bci:10 (line 812) MemorySegmentCopyUnsafe::panama @ bci:44 (line 66)

Comments
[jdk21u-fix-request] Approval Request from Martin Should get backported for parity with 21.0.25-oracle. Applies cleanly and tier 1-4 have passed.
13-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/697 Date: 2024-06-12 09:27:16 +0000
12-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk22/pull/86 Date: 2024-01-17 08:33:53 +0000
17-01-2024

Changeset: b8917214 Author: Tobias Holenstein <tholenstein@openjdk.org> Date: 2024-01-17 08:07:04 +0000 URL: https://git.openjdk.org/jdk/commit/b89172149d6a900d11630a95be7278870421b435
17-01-2024

I added EA fix patch.
12-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17347 Date: 2024-01-10 13:35:17 +0000
11-01-2024

I attached a simple reproducer (Test.java). The issue is reproducible since JDK-8269119 in JDK 18 b14 (paging [~vlivanov]): java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,Test::test Test.java
03-10-2023

Might be similar to JDK-8311023 in that we just need to handle the LeafCall in EA code but I'm leaving this for someone else to investigate in more detail. Might be a good starter task for someone interested in looking into C2 EA.
03-10-2023

ILW = Crash in EA, only observable with JMH and Unsafe, use -XX:-EscapeAnalysis or disable compilation of affected method = HLM = P3
25-09-2023