Description
Description
After upgrading to macOS 15.1 (and .NET 8.0.403?), dotnet/java-interop unit tests started crashing while trying to create a Java VM from managed code.
Reproduction Steps
-
Use macOS x64
-
Install Microsoft OpenJDK 17
-
Extract net8.0.8-sigbus.zip
-
Build and run the project:
dotnet run /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib
-
Check the shell exit status:
echo $?
Expected behavior
All messages printed:
start!
loaded lib /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib; c=107c85f00
calling JNI_CreateJavaVM
JNI_CreateJavaVM returned 0
In particular, JNI_CreateJavaVM returned
.
$?
should be 0.
Actual behavior
Not all messages are printed:
start!
loaded lib /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib; c=108366f00
calling JNI_CreateJavaVM
echo $?
prints 138, which means it exited via SIGBUS.
Regression?
This wasn't happening to me last week! (Note: within the last week I installed .NET 8.0.403, up from 8.0.204, and installed macOS 15.1, up from 15.0.)
Known Workarounds
No response
Configuration
- Which version of .NET is the code running on? 8.0.403
- What OS and version, and what distro if applicable? macOS 15.1
- What is the architecture (x64, x86, ARM, ARM64)? x64 (not arm64, not Rosetta. Real x64!)
- Do you know whether it is specific to that configuration?: No idea
Other information
Using self-contained builds shows that the issue was introduced between 8.0.7 and 8.0.8.
It works with 8.0.7:
% dotnet publish --sc -p:RuntimeFrameworkVersion=8.0.7
% ./bin/Release/net8.0/osx-x64/net8.0.8-sigbus /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib
start!
loaded lib /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib; c=106b15f00
calling JNI_CreateJavaVM
JNI_CreateJavaVM returned 0
It fails with 8.0.8:
% dotnet publish --sc -p:RuntimeFrameworkVersion=8.0.8
% ./bin/Release/net8.0/osx-x64/net8.0.8-sigbus /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib
start!
loaded lib /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/lib/libjli.dylib; c=10cd6df00
calling JNI_CreateJavaVM
zsh: bus error ./bin/Release/net8.0/osx-x64/net8.0.8-sigbus
Even better, the self-contained build shows "bus error" in the output!
See also a Discord discussion (which only spans ~3 hours…), which shows that the crash is from:
(lldb) p * (CONTEXT*)(ts64.__rsp-sizeof(CONTEXT) - ((ts64.__rsp-sizeof(CONTEXT))%16) - sizeof(EXCEPTION_RECORD))
…lots of output…
(lldb) p * (CONTEXT*)(ts64.__rsp-sizeof(CONTEXT) - ((ts64.__rsp-sizeof(CONTEXT))%16) - sizeof(EXCEPTION_RECORD) - sizeof(MachExceptionInfo))
error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory
i.e. the subtraction of sizeof(MachExceptionInfo)
from FramePointer
results in an invalid address: https://github.com/dotnet/runtime/blob/v8.0.4/src/coreclr/pal/src/exception/machexception.cpp#L899C5-L899C17