Skip to content

Unable to compile an hello world example with GraalVM native-image on any 3.3.x using sbt-native-image #3051

@TonioGela

Description

@TonioGela

Hello 👋!

As per the title, I've tried compiling a dead stupid Hello World

object Main extends IOApp.Simple {
  def run: IO[Unit] = IO.println("Hello cats!")
}

using sbt-native-image 0.3.1 with these configurations

ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.13.8"

lazy val root = (project in file(".")).enablePlugins(NativeImagePlugin).settings(
  name := "cats-effect-3-quick-start",
  libraryDependencies += "org.typelevel" %% "cats-effect" % "<CE_VERSION>",
  Compile / mainClass := Some("com.example.Main"),
  nativeImageOptions ++= List("-H:+ReportExceptionStackTraces", "--no-fallback")
)
// GraalVM version is [email protected] as per sbt-native-image default

and while for CE_VERSION in 2.5.5 to 3.2.9 I get a native executable that works flawlessly, for CE_VERSIONs in 3.3.0 to 3.3.12 I consistently get these errors 👇

Stacktraces
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]    classlist:   3,666.84 ms,  0.96 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]        (cap):   2,111.30 ms,  0.96 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]        setup:   3,271.69 ms,  0.95 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]     (clinit):     243.10 ms,  1.46 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]   (typeflow):   6,919.81 ms,  1.46 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]    (objects):   6,171.18 ms,  1.46 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]   (features):     384.15 ms,  1.46 GB
[/Users/toniogela/Desktop/cats-effect-3-quick-start/target/native-image/cats-effect-3-quick-start:95767]     analysis:  14,156.76 ms,  1.46 GB
Error: Unsupported features in 4 methods
Detailed message:iveImage 21s
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1770187164.invoke_MT(Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:121)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object, Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1765514060.invoke_MT(Object, Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:122)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
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.findConstructor(MethodHandles.java:1264)
Call path from entry point to java.lang.invoke.MethodHandles$Lookup.findConstructor(Class, MethodType): 
        no path found from entry point to target method

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


com.oracle.svm.core.util.UserError$UserException: Unsupported features in 4 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1770187164.invoke_MT(Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:121)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object, Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1765514060.invoke_MT(Object, Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:122)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
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.findConstructor(MethodHandles.java:1264)
Call path from entry point to java.lang.invoke.MethodHandles$Lookup.findConstructor(Class, MethodType): 
        no path found from entry point to target method

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


        at com.oracle.svm.core.util.UserError.abort(UserError.java:79)
        at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:217)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:765)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:468)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported features in 4 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1770187164.invoke_MT(Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3040.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:121)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic(Object, Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
        at parsing java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
Call path from entry point to java.lang.invoke.LambdaForm$MH/1765514060.invoke_MT(Object, Object, Object, Object): 
        at java.lang.invoke.LambdaForm$MH/0x00000007c12f3440.invoke_MT(LambdaForm$MH)
        at cats.effect.Signal$2.handle(Signal.java:122)
        at cats.effect.Signal.handle(Signal.java:64)
        at cats.effect.IOApp.$anonfun$main$7(IOApp.scala:260)
        at cats.effect.IOApp.$anonfun$main$7$adapted(IOApp.scala:259)
        at cats.effect.IOApp$$Lambda$521/0x00000007c1261040.apply(Unknown Source)
        at cats.effect.IOFiber.onFatalFailure(IOFiber.scala:1513)
        at cats.effect.IOFiber.blockingR(IOFiber.scala:1367)
        at cats.effect.IOFiber.run(IOFiber.scala:144)
        at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:461)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
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.findConstructor(MethodHandles.java:1264)
Call path from entry point to java.lang.invoke.MethodHandles$Lookup.findConstructor(Class, MethodType): 
        no path found from entry point to target method

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


        at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:129)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:762)
        ... 8 more
Error: Image build request failed with exit status 1

According to the documentation, the 3.3.x releases should contain the extra metadata needed to handle the reflective calls, but if it does, I haven't still found a way to use them, at least with sbt-native-image. Once discovered (or fixed in case this is a bug), I'll be glad to add the how-to on that documentation page.

My test running the compiled jar using runAgent to get the metadata for native-image were unsuccessful (I can add the details if needed).

Tests done using scala-cli
scala-cli package --native-image hello-cats.scala --graalvm-jvm-id graalvm-java11:20.2.0 -f -- --no-fallback -H:+ReportExceptionStackTraces

led me to the same results using this file

//> using scala "2.13.8"
//> using lib "org.typelevel::cats-effect::3.3.12"

import cats.effect.IOApp
import cats.effect.IO

object Main extends IOApp.Simple {
  def run: IO[Unit] = IO.println("Hello cats!")
}

Lastly, adding --report-unsupported-elements-at-runtime will make the build succeed, but I get this exception at runtime:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class scala.concurrent.duration.Duration$
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:215)
	at cats.effect.unsafe.IORuntimeConfig$.DefaultShutdownHookTimeout(IORuntimeConfig.scala:94)
	at cats.effect.unsafe.IORuntimeConfigCompanionPlatform.$anonfun$Default$11(IORuntimeConfigCompanionPlatform.scala:45)
	at scala.util.Failure.getOrElse(Try.scala:219)
	at cats.effect.unsafe.IORuntimeConfigCompanionPlatform.<init>(IORuntimeConfigCompanionPlatform.scala:45)
	at cats.effect.unsafe.IORuntimeConfig$.<init>(IORuntimeConfig.scala:89)
	at cats.effect.unsafe.IORuntimeConfig$.<clinit>(IORuntimeConfig.scala:89)
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:351)
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:271)
	at cats.effect.IOApp.runtimeConfig(IOApp.scala:163)
	at cats.effect.IOApp.runtimeConfig$(IOApp.scala:163)
	at Main$.runtimeConfig(cats.scala:7)
	at cats.effect.IOApp.$anonfun$main$1(IOApp.scala:235)
	at cats.effect.unsafe.IORuntimeCompanionPlatform.installGlobal(IORuntimeCompanionPlatform.scala:137)
	at cats.effect.IOApp.main(IOApp.scala:210)
	at cats.effect.IOApp.main$(IOApp.scala:203)
	at Main$.main(cats.scala:7)
	at Main.main(cats.scala)

Let me know if further details need to be added

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions