You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the issue
The problem is occurring in the current implementation of LazyVals in Scala 3.3.0-RC2. I managed to minimize it into a snippet of Java code:
After running it, a segfault occurs. When run with GDB, it shows a Bus error. I investigated it a bit, and I found that the failing instruction is:
lockcmpxchg %esi,0x1b71e0(%r14)
Stepping after this instruction results in Thread 2 received signal SIGBUS, Bus error.
I am providing a minimized example that generates a slightly different assembly. But it is compiled from a similar bytecode and results in the same error. In our case, I investigated it a bit further and found that the address of the destination of cmpxchg is wrong and does not correspond to the storage we want to operate on.
It only fails for static fields - therefore, only objects in Scala suffer from this. Classes generate non-static fields that use Unsafe functions for non-static fields, and all addresses are correct.
Steps to reproduce the issue
Please include both build steps as well as run steps
Create a java class like the above one and call it ReproJava.java,
Compile it: javac ReproJava.java -d javaout,
Generate the native image: native-image -g -cp javaout FoooBarMain,
Execute the native image: ./foobarmain
Describe GraalVM and your environment:
java --version:
java 11.0.18 2023-01-17 LTS
Java(TM) SE Runtime Environment GraalVM EE 22.3.1 (build 11.0.18+9-LTS-jvmci-22.3-b11)
Java HotSpot(TM) 64-Bit Server VM GraalVM EE 22.3.1 (build 11.0.18+9-LTS-jvmci-22.3-b11, mixed mode, sharing)
native-image --version:
GraalVM 22.3.1 Java 11 EE (Java Version 11.0.18+9-LTS-jvmci-22.3-b11)
OS: macOS 11 with Intel. Reproduced also on macOS with ARM and Ubuntu.
The text was updated successfully, but these errors were encountered:
The new lazy vals implementation was not working in graalvm's native
image. The generated holder for the lazy value was static
post-compilation. It caused the generated code to perform CAS operate on
bad addresses and throw Bus Error.
Issue on oracle/graalvm: oracle/graal#5863
This PR removes the static modifier from the lazy val holder and makes
it accessible via `MODULE$` instead. It fixes the CAS on GraalVM and
does not have a performance impact, at least judging by the benchmark
I've added to this PR.
The example code is wrong, and happens to just accidentally work when running on the HotSpot VM: when accessing a static field with Unsafe, it is required that the accessed object is coming from staticFieldBase.
So the correct code is
Evaluating evaluating = new Evaluating();
long offset = unsafe.staticFieldOffset(FoooBar.class.getDeclaredField("foo"));
System.out.println(unsafe.compareAndSwapObject(unsafe.staticFieldBase(FoooBar.class), offset, null, evaluating));
System.out.println(FoooBar.foo);
Describe the issue
The problem is occurring in the current implementation of LazyVals in Scala 3.3.0-RC2. I managed to minimize it into a snippet of Java code:
After running it, a segfault occurs. When run with GDB, it shows a
Bus error
. I investigated it a bit, and I found that the failing instruction is:Stepping after this instruction results in
Thread 2 received signal SIGBUS, Bus error.
I am providing a minimized example that generates a slightly different assembly. But it is compiled from a similar bytecode and results in the same error. In our case, I investigated it a bit further and found that the address of the destination of cmpxchg is wrong and does not correspond to the storage we want to operate on.
It only fails for static fields - therefore, only objects in Scala suffer from this. Classes generate non-static fields that use Unsafe functions for non-static fields, and all addresses are correct.
Steps to reproduce the issue
Please include both build steps as well as run steps
ReproJava.java
,javac ReproJava.java -d javaout
,native-image -g -cp javaout FoooBarMain
,./foobarmain
Describe GraalVM and your environment:
java --version
:native-image --version
:The text was updated successfully, but these errors were encountered: