-
Notifications
You must be signed in to change notification settings - Fork 21
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
Regression with Scala 2.13: cannot compile GraalVM native-image #11634
Comments
is this a bug in Scala? |
IMHO, yes. Some of these errors appear due to |
are you saying that in order for this to work, we can't use |
There are implementation options to make And for edge cases some cooperation with the GraalVM team will be required for sure. I have managed to fix compilation error for Others calls to |
Tentatively milestoned for 2.13.2, since it should certainly at least be assessed further. |
Great that you managed to override the call to |
What's the problem with |
I meant |
Anyway, that still seems a little too common for graal not to support natively? Quick google led to a similar, resolved issue: oracle/graal#877 |
@adriaanm checked with GraalVM CE 19.2.0.1 and still got the same error... now I'm waiting for the next release: 19.2.1 or 19.3.0 to check again... |
Thanks for checking. Looks like the bug I linked to was reported fixed on the Java 11 version, which would be the upcoming 19.3, IUC. |
GraalVM 19.3.0 fixed this for me. |
Sweet! Thanks for reporting :-) |
Btw, I've found that it isn't necessary to substitute the It's simply necessary to initialize the underlying
I'm thinking we should consider adding that file ourselves in the library jar, so it's pre-configured for all native-image users. |
Should the config files for |
Yeah, that's the consideration: should Graal native-image support come out the box or rely on some other artifact? In terms of pollution, creating a separate artifact likely pollutes much more than the 59 bytes that |
@dwijnand I've tried to build an image with your file in this branch and it doesn't work for me:
Steps to reproduce: $ sbt clean +assembly
$ /usr/lib/jvm/graalvm-ce-java8/bin/java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b07)
OpenJDK 64-Bit GraalVM CE 19.3.0.2 (build 25.232-b07-jvmci-19.3-b06, mixed mode)
$ /usr/lib/jvm/graalvm-ce-java8/bin/native-image --no-server --no-fallback --allow-incomplete-classpath -jar target/scala-2.13/jsoniter-scala-examples-assembly-0.1.0-SNAPSHOT.jar Have I missed something? |
@plokhotnyuk I'm not sure, it worked for me:
I'm running graalvm-ce-java11-19.3.1, maybe it's because of that?
|
@dwijnand yeap, your |
In case anyone has hit on a similar issue with GraalVM 20.1.0, Scala 2.12.12 and // build.sbt
lazy val myProject
.in(file("my-project"))
.settings(
+ libraryDependencies += "org.graalvm.nativeimage" % "svm" % "20.1.0" % "compile-internal",
)
.enablePlugins(GraalVMNativeImagePlugin)
+ // my-project/src/main/scala/myproject/internal/substites/Target_scala_collection_immutable_VM.java
+ package myproject.internal.substitutes;
+
+ import com.oracle.svm.core.annotate.Substitute;
+ import com.oracle.svm.core.annotate.TargetClass;
+
+ @TargetClass(className = "scala.collection.immutable.VM")
+ final class Target_scala_runtime_Statics {
+
+ @Substitute
+ public static void releaseFence() {
+ UnsafeUtils.UNSAFE.storeFence();
+ }
+ }
+ // my-project/src/main/scala/myproject/internal/substites/UnsafeUtils.java
+ package myproject.internal.substitutes;+
+ import java.lang.reflect.Field;+
+ class UnsafeUtils {
+ static final sun.misc.Unsafe UNSAFE;+
+ static {
+ try {
+ Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
+ field.setAccessible(true);
+ UNSAFE = (sun.misc.Unsafe) field.get(null);
+ } catch (Throwable ex) {
+ throw new ExceptionInInitializerError(ex);
+ }
+ }
+ } Big thanks to @plokhotnyuk for finding this workaround, which I found in plokhotnyuk/jsoniter-scala@e089f06 |
I published the workaround above as an independent library:
The jar is 4kb and has no external dependencies besides scala-library. You can download the jar and add it manually to the classpath if you prefer https://repo1.maven.org/maven2/org/scalameta/svm-subs_2.13/19.3.2/svm-subs_2.13-19.3.2.jar This workaround is only needed for 2.12.12+ and 2.13.3+ |
@olafurpg Very neat, thanks! |
In case anyone is interested, I published a new plugin called sbt-native-image (https://github.com/scalameta/sbt-native-image) that automatically adds the correct svm-subs dependency and provides other nice features like automatic GraalVM installation |
Hey everyone - are we sure this issue should be closed? My first experience with GraalVM and Scala hit upon it very quickly (using GraalVM 21.0.0). I was able to circumvent issues by using the |
An example which successfully compiles to native binaries from Scala 2.11 & 2.12 uber-jars cannot be compiled from Scala 2.13 uber-jar due some internal changes in Scala collection implementation.
Error output from the native-image tool is:
Steps to reproduce:
switch-examples-to-scala-2.13
branchThe text was updated successfully, but these errors were encountered: