oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources šŸš€
https://www.graalvm.org
Other
20.44k stars 1.64k forks source link

InternalError: Enclosing method not found - gRPC + Netty #3052

Open jamesward opened 3 years ago

jamesward commented 3 years ago

GraalVM 20.3.0-java11

My gRPC server runs fine under GraalVM and generates the config with the agent. But when I try to create a native image it fails:

Fatal error:java.lang.InternalError: java.lang.InternalError: Enclosing method not found
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:600)
        at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:483)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:350)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:509)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:115)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:541)
Caused by: java.lang.InternalError: Enclosing method not found
        at java.base/java.lang.Class.getEnclosingMethod(Class.java:1296)
        at java.base/sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50)
        at java.base/sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:77)
        at java.base/sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:95)
        at java.base/sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflectionFactory.java:110)
        at java.base/sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165)
        at java.base/sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.java:43)
        at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
        at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
        at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
        at java.base/sun.reflect.generics.repository.ClassRepository.computeSuperInterfaces(ClassRepository.java:117)
        at java.base/sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:95)
        at java.base/java.lang.Class.getGenericInterfaces(Class.java:1137)
        at com.oracle.svm.hosted.analysis.Inflation.fillGenericInfo(Inflation.java:341)
        at com.oracle.svm.hosted.analysis.Inflation.checkType(Inflation.java:138)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
        at com.oracle.svm.hosted.analysis.Inflation.checkObjectGraph(Inflation.java:124)
        at com.oracle.graal.pointsto.BigBang.checkObjectGraph(BigBang.java:626)
        at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:595)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:712)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:558)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:471)
        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)
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
        at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1647)
        at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1397)
        at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1358)
        at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1317)
        at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1829)

Not sure why. To reproduce:

  1. Get https://github.com/grpc/grpc-kotlin/tree/native-server (native-server branch)
  2. cd examples
  3. ./gradlew :native-server:nativeImage
fernando-valdez commented 3 years ago

Hi @jamesward, what OS are you using?

jamesward commented 3 years ago

I'm on Linux.

voigtste commented 3 years ago

Have the same topic with MacOS

voigtste commented 3 years ago

After debugging, I saw the root cause:

The graal analyzer is trying to resolve io.grpc.kotlin.ServerCalls$unaryServerMethodDefinition$2$$special$$inlined$map$1 The reflection result for the class (Kotlin generated) is public java.lang.Object io.grpc.kotlin.ServerCalls$unaryServerMethodDefinition$2$$special$$inlined$map$1.collect(kotlinx.coroutines.flow.FlowCollector,kotlin.coroutines.Continuation)

But it looks for "collect$$forInline".

Looks like some quirks with reflection in combination with kotlin flows.

So in general it is a Kotlin related topic, but I do not know how to fix that (with extra graal config) or something else.

StefanLobbenmeier commented 3 years ago

@voigtste did you check if https://github.com/HewlettPackard/kraal solves your issue?