Skip to content
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

Cannot compile native image with scala 2.13.1 #2019

Closed
abhijat opened this issue Dec 23, 2019 · 6 comments
Closed

Cannot compile native image with scala 2.13.1 #2019

abhijat opened this issue Dec 23, 2019 · 6 comments
Assignees

Comments

@abhijat
Copy link

abhijat commented Dec 23, 2019

I cannot compile a native image with scala 2.13.1 - the project is a simple println hello world style program.

Please see details of the build below:

JVM version:

~/dev/scala/scala-at-light-speed  ((basics)) 
 abhijat $ java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-jvmci-19.3-b05-LTS)
OpenJDK 64-Bit GraalVM CE 19.3.0 (build 11.0.5+10-jvmci-19.3-b05-LTS, mixed mode, sharing)

Code:

package com.abhijat

object Playground {
  def main(args: Array[String]): Unit = {
    println("hello")
  }
}

build.sbt

name := "scala-at-light-speed"
version := "0.1"
scalaVersion := "2.13.1"

project/plugins.sbt (for generating an uber jar)

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

The error log seen when invoking the following build command is attached

native-image -jar target/scala-2.13/scala-at-light-speed-assembly-0.1.jar -H:+ReportExceptionStackTraces --verbose --no-fallback

graalvm-failure.txt

The program compiles and runs as expected with scala 2.12.10.

The errors primarily look like this:

Error: Unsupported features in 2 methods
Detailed message:
Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported type java.lang.invoke.MemberName is reachable: All methods from java.lang.invoke should have been replaced during image building.
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Trace: 
	at parsing java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102)
Call path from entry point to java.lang.invoke.MethodHandles$Lookup.findStatic(Class, String, MethodType): 
	no path found from entry point to target method
@vjovanov
Copy link
Member

Have you tried adding --report-unsupported-elements-at-runtime as a workaround?

@plokhotnyuk
Copy link

plokhotnyuk commented Dec 25, 2019

@vjovanov I've reported the same issue but in the scala repo. W/A with --report-unsupported-elements-at-runtime doesn't help, but using of the --initialize-at-build-time option solves this case: scala/bug#11837

@vjovanov vjovanov self-assigned this Feb 4, 2020
@cstancu
Copy link
Member

cstancu commented Feb 6, 2020

Can you please try with the latest snapshot and --report-unsupported-elements-at-runtime? There has been some work trying to improve this e9b1b83.

@abhijat
Copy link
Author

abhijat commented Feb 12, 2020

Thanks for looking into this.

With the following version of jdk (which is the latest I have available in sdkman):

$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment GraalVM CE 19.3.1 (build 11.0.6+9-jvmci-19.3-b07)
OpenJDK 64-Bit Server VM GraalVM CE 19.3.1 (build 11.0.6+9-jvmci-19.3-b07, mixed mode, sharing)

And the option --report-unsupported-elements-at-runtime , the build completes without error:

$ native-image -jar target/scala-2.13/graalex-assembly-0.1.jar -H:+ReportExceptionStackTraces --verbose --no-fallback --report-unsupported-elements-at-runtime
Build on Server(pid: 28959, port: 41641)
SendBuildRequest [
-task=com.oracle.svm.hosted.NativeImageGeneratorRunner
-imagecp
/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/objectfile.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/javacpp-shadowed.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/svm-llvm.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/llvm-platform-specific-shadowed.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/llvm-wrapper-shadowed.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/svm.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/graal-llvm.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/builder/pointsto.jar:/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/library-support.jar:/home/abhijat/dev/scala/graalex/target/scala-2.13/graalex-assembly-0.1.jar
-H:Path=/home/abhijat/dev/scala/graalex
-H:Class=com.abhijat.Main
-H:Name=graalex-assembly-0.1
-H:+ReportExceptionStackTraces
-H:FallbackThreshold=0
-H:+ReportUnsupportedElementsAtRuntime
-H:CLibraryPath=/home/abhijat/.sdkman/candidates/java/19.3.1.r11-grl/lib/svm/clibraries/linux-amd64
]
[graalex-assembly-0.1:28959]    classlist:     923.36 ms
[graalex-assembly-0.1:28959]        (cap):     481.53 ms
[graalex-assembly-0.1:28959]        setup:     815.52 ms
[graalex-assembly-0.1:28959]   (typeflow):   7,700.51 ms
[graalex-assembly-0.1:28959]    (objects):   9,321.23 ms
[graalex-assembly-0.1:28959]   (features):     314.06 ms
[graalex-assembly-0.1:28959]     analysis:  17,836.55 ms
[graalex-assembly-0.1:28959]     (clinit):     352.65 ms
[graalex-assembly-0.1:28959]     universe:     909.35 ms
[graalex-assembly-0.1:28959]      (parse):     947.06 ms
[graalex-assembly-0.1:28959]     (inline):   2,067.98 ms
[graalex-assembly-0.1:28959]    (compile):  11,255.12 ms
[graalex-assembly-0.1:28959]      compile:  14,917.37 ms
[graalex-assembly-0.1:28959]        image:   1,167.69 ms
[graalex-assembly-0.1:28959]        write:     207.00 ms
[graalex-assembly-0.1:28959]      [total]:  36,881.37 ms

I get an exception at runtime though:

$ ./graalex-assembly-0.1 
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported constructor java.lang.invoke.MemberName.<init>(Class, String, MethodType, byte) is reachable: All methods from java.lang.invoke should have been replaced during image building.
	at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:101)
	at java.lang.invoke.MemberName.<init>(MemberName.java:812)
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030)
	at java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102)
	at scala.runtime.Statics$VM.mkHandle(Statics.java:161)
	at scala.runtime.Statics$VM.<clinit>(Statics.java:155)
	at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
	at java.lang.Class.ensureInitialized(DynamicHub.java:475)
	at scala.runtime.Statics.releaseFence(Statics.java:148)
	at scala.collection.immutable.Vector.<init>(Vector.scala:135)
	at scala.collection.immutable.Vector$.<clinit>(Vector.scala:83)
	at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
	at java.lang.Class.ensureInitialized(DynamicHub.java:475)
	at scala.collection.immutable.IndexedSeq$.<init>(Seq.scala:114)
	at scala.collection.immutable.IndexedSeq$.<clinit>(Seq.scala:114)
	at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
	at java.lang.Class.ensureInitialized(DynamicHub.java:475)
	at scala.package$.<clinit>(package.scala:64)
	at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
	at java.lang.Class.ensureInitialized(DynamicHub.java:475)
	at scala.Predef$.<clinit>(Predef.scala:154)
	at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
	at java.lang.Class.ensureInitialized(DynamicHub.java:475)
	at com.abhijat.Main$.main(Main.scala:5)
	at com.abhijat.Main.main(Main.scala)

Is there another version of the JDK you wanted me to try this with?

The code and build definitions are largely the same as before:

package com.abhijat

object Main {
  def main(args: Array[String]): Unit = {
    println("hello")
  }
}

build.sbt

name := "graalex"

version := "0.1"

scalaVersion := "2.13.1"

plugin used to generate uberjar

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

@plokhotnyuk
Copy link

plokhotnyuk commented Feb 12, 2020

@cstancu Sorry for delayed response.

I have managed to solve the problem with GraalVM CE 19.3.1. The most viable solution that works for both Java 8 and Java 11 versions is using substitutions like here with the --initialize-at-build-time option turned on for the native image build.

More options are available for the Java 11 version: please see this ticket for details.

@cstancu
Copy link
Member

cstancu commented Sep 25, 2020

Thank you for finding a solution and for reporting back. The underlying issue here is incomplete MethodHandle support. That is under development and is being tracked by #2761. Once that is done hopefully no substitutions will be required.

@cstancu cstancu closed this as completed Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants