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

Possible regression in Native Image builds of Scala projects in 20.2 #2770

Closed
radeusgd opened this issue Aug 20, 2020 · 5 comments
Closed

Possible regression in Native Image builds of Scala projects in 20.2 #2770

radeusgd opened this issue Aug 20, 2020 · 5 comments
Assignees

Comments

@radeusgd
Copy link
Contributor

radeusgd commented Aug 20, 2020

Describe the issue
Builds of even very simple Scala applications that used to work on GraalVM 20.1.0 fail with GraalVM 20.2.0.

Steps to reproduce the issue

  1. Create a simple project with sbt new scala/scala-seed.g8 (make sure that the project uses Scala 2.13).
  2. Modify the Hello.scala file to contain
package example

object Hello {
  def main(args: Array[String]): Unit = {
    val seq = Seq("abc")
    println(seq)
  }
}
  1. Compile it with sbt compile.
  2. Find the classpath with sbt "show fullClasspath".
  3. Concat the directories to get the classpath string, for example CLASSPATH=/path/to/scala-library/scala-library-2.13.2.jar:target/scala-2.13/classes.
  4. Build Native Image with native-image -cp $CLASSPATH example.Hello example_binary -H:+ReportExceptionStackTraces --no-fallback --initialize-at-build-time.

On GraalVM 20.1.0 it works and runs correctly.

On GraalVM 20.2.0 it fails with:

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.LambdaForm$MH/348233151.invoke_MT(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.
Detailed message:
Trace: 
	at parsing scala.runtime.Statics.releaseFence(Statics.java:148)
Call path from entry point to scala.runtime.Statics.releaseFence(): 
	at scala.runtime.Statics.releaseFence(Statics.java:148)
	at scala.collection.immutable.List.prependedAll(List.scala:160)
	at scala.collection.immutable.List$.from(List.scala:651)
	at scala.collection.immutable.List$.from(List.scala:648)
	at scala.collection.IterableFactory.apply(Factory.scala:103)
	at scala.collection.IterableFactory.apply$(Factory.scala:103)
	at scala.collection.immutable.List$.apply(List.scala:648)
	at scala.collection.SeqFactory$Delegate.apply(Factory.scala:304)
	at example.Hello$.main(Hello.scala:5)
	at example.Hello.main(Hello.scala)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:149)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184)
	at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)

It looks like it is related to a bug that was reported to the Scala project a while ago, but it seems to have been resolved in GraalVM 19.3.0, so it looks like there might have been some kind of regression.

It also looks like it may be fixed by #2761, but I thought it may be worth reporting this as a bug, because it did work correctly in 20.1.0.

Describe GraalVM and your environment:

  • GraalVM version: CE 20.2.0
  • JDK major version: 11
  • OS: Ubuntu 18.04.4 LTS
  • Architecture: x64
> java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)

More details

Full trace of Native Image build:

[example_binary:2191]    classlist:   2,216.79 ms,  0.96 GB
[example_binary:2191]        (cap):     615.51 ms,  0.96 GB
[example_binary:2191]        setup:   1,985.75 ms,  0.96 GB
[example_binary:2191]     (clinit):     138.23 ms,  1.22 GB
[example_binary:2191]   (typeflow):   4,812.64 ms,  1.22 GB
[example_binary:2191]    (objects):   3,832.20 ms,  1.22 GB
[example_binary:2191]   (features):     251.92 ms,  1.22 GB
[example_binary:2191]     analysis:   9,372.59 ms,  1.22 GB
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.LambdaForm$MH/348233151.invoke_MT(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.
Detailed message:
Trace: 
	at parsing scala.runtime.Statics.releaseFence(Statics.java:148)
Call path from entry point to scala.runtime.Statics.releaseFence(): 
	at scala.runtime.Statics.releaseFence(Statics.java:148)
	at scala.collection.immutable.List.prependedAll(List.scala:160)
	at scala.collection.immutable.List$.from(List.scala:651)
	at scala.collection.immutable.List$.from(List.scala:648)
	at scala.collection.IterableFactory.apply(Factory.scala:103)
	at scala.collection.IterableFactory.apply$(Factory.scala:103)
	at scala.collection.immutable.List$.apply(List.scala:648)
	at scala.collection.SeqFactory$Delegate.apply(Factory.scala:304)
	at example.Hello$.main(Hello.scala:5)
	at example.Hello.main(Hello.scala)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:149)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184)
	at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)

com.oracle.svm.core.util.UserError$UserException: 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.LambdaForm$MH/348233151.invoke_MT(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.
Detailed message:
Trace: 
	at parsing scala.runtime.Statics.releaseFence(Statics.java:148)
Call path from entry point to scala.runtime.Statics.releaseFence(): 
	at scala.runtime.Statics.releaseFence(Statics.java:148)
	at scala.collection.immutable.List.prependedAll(List.scala:160)
	at scala.collection.immutable.List$.from(List.scala:651)
	at scala.collection.immutable.List$.from(List.scala:648)
	at scala.collection.IterableFactory.apply(Factory.scala:103)
	at scala.collection.IterableFactory.apply$(Factory.scala:103)
	at scala.collection.immutable.List$.apply(List.scala:648)
	at scala.collection.SeqFactory$Delegate.apply(Factory.scala:304)
	at example.Hello$.main(Hello.scala:5)
	at example.Hello.main(Hello.scala)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:149)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184)
	at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)

	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: 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.LambdaForm$MH/348233151.invoke_MT(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.
Detailed message:
Trace: 
	at parsing scala.runtime.Statics.releaseFence(Statics.java:148)
Call path from entry point to scala.runtime.Statics.releaseFence(): 
	at scala.runtime.Statics.releaseFence(Statics.java:148)
	at scala.collection.immutable.List.prependedAll(List.scala:160)
	at scala.collection.immutable.List$.from(List.scala:651)
	at scala.collection.immutable.List$.from(List.scala:648)
	at scala.collection.IterableFactory.apply(Factory.scala:103)
	at scala.collection.IterableFactory.apply$(Factory.scala:103)
	at scala.collection.immutable.List$.apply(List.scala:648)
	at scala.collection.SeqFactory$Delegate.apply(Factory.scala:304)
	at example.Hello$.main(Hello.scala:5)
	at example.Hello.main(Hello.scala)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:149)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184)
	at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)

	at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:126)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:762)
	... 8 more
Caused by: 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.LambdaForm$MH/348233151.invoke_MT(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.
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin.reportUnsupportedFeature(IntrinsifyMethodHandlesInvocationPlugin.java:761)
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin.access$1100(IntrinsifyMethodHandlesInvocationPlugin.java:161)
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin$Transplanter.bailout(IntrinsifyMethodHandlesInvocationPlugin.java:729)
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin$Transplanter.graph(IntrinsifyMethodHandlesInvocationPlugin.java:540)
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin.processInvokeWithMethodHandle(IntrinsifyMethodHandlesInvocationPlugin.java:479)
	at com.oracle.svm.hosted.phases.IntrinsifyMethodHandlesInvocationPlugin.handleInvoke(IntrinsifyMethodHandlesInvocationPlugin.java:232)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.tryNodePluginForInvocation(BytecodeParser.java:2206)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1871)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genDynamicInvokeHelper(BytecodeParser.java:1760)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeVirtual(BytecodeParser.java:1708)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeVirtual(BytecodeParser.java:1693)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5338)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3413)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3220)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1090)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:984)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:84)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:74)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:214)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:223)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:357)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:313)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:302)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:103)
	at com.oracle.graal.pointsto.flow.StaticInvokeTypeFlow.update(InvokeTypeFlow.java:434)
	at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:552)
	at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:173)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
	... 5 more
Error: Image build request failed with exit status 1
@plokhotnyuk
Copy link

@radeusgd As a workaround you can use a substitution for the releaseFence call like here.

@radeusgd
Copy link
Contributor Author

@plokhotnyuk Thanks, that seems to help indeed!

@munishchouhan munishchouhan self-assigned this Aug 21, 2020
@munishchouhan
Copy link
Contributor

As you already have a work around, once #2761 is implemented,
please try again and report it if you still get the error
Closing it for now.

@munishchouhan
Copy link
Contributor

Reopen the issue to get the bug fix in 20.2

@cstancu
Copy link
Member

cstancu commented Sep 22, 2020

The underlying issue here is incomplete MethodHandle support. That is under development and is being tracked by #2761.

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