-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Bus Error on CMPXCHG in Scala 3 new lazy vals #5863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
szymon-rd
added a commit
to scala/scala3
that referenced
this issue
Feb 6, 2023
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.
Thank you for reporting this, we'll take a look into it shortly. |
Tracked internally on GR 44061 |
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 So the correct code is
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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: