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.4k stars 1.64k forks source link

Fatal error when building native image with GraalVM 22.3.0 #5707

Open gabilang opened 1 year ago

gabilang commented 1 year ago

Getting following fatal error while building native image with the JAR added here

Generating executable with Native image
========================================================================================================================
GraalVM Native Image: Generating 'transaction_native_image' (executable)...
========================================================================================================================
[1/7] Initializing...                                                                                    (9.7s @ 0.46GB)
 Version info: 'GraalVM 22.3.0 Java 11 CE'
 Java version info: '11.0.17+8-jvmci-22.3-b08'
 C compiler: gcc (linux, x86_64, 11.3.0)
 Garbage collector: Serial GC
 2 user-specific feature(s)
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.ballerina.stdlib.crypto.svm.BouncyCastleFeature
[2/7] Performing analysis...  []                                                                        (10.7s @ 1.21GB)
   3,898 (73.06%) of  5,335 classes reachable
   5,974 (35.44%) of 16,858 fields reachable
  15,771 (64.92%) of 24,293 methods reachable
     216 classes,     0 fields, and     0 methods registered for reflection

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing gabilan.transaction_native_image/0.$_init.$lambda$main$(java.lang.Object[]) 
Parsing context:
   at gabilan.transaction_native_image.0.$_init.$lambda$main$(transaction_native_image)
   at gabilan.transaction_native_image.0.$_init$$Lambda$762/0x00000007c205b040.apply(Unknown Source)
   at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
   at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:324)
   at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:291)
   at io.ballerina.runtime.internal.scheduling.Scheduler$$Lambda$844/0x00000007c208d040.run(Unknown Source)
   at java.lang.Shutdown.runHooks(Shutdown.java:130)
   at java.lang.Shutdown.shutdown(Shutdown.java:186)
   at com.oracle.svm.core.jdk.RuntimeSupport.shutdown(RuntimeSupport.java:154)

        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:153)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:104)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:83)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraph(MethodTypeFlow.java:65)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.update(DefaultStaticInvokeTypeFlow.java:64)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:488)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:2984)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:243)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:541)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:529)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:143)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:745)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Caused by: org.graalvm.compiler.debug.GraalError: Frame states being merged are incompatible: mismatch in rethrowException flag
 This frame state: [locals: [1,600,601,602,603,879,605,606,607,608,#,609,610,16,37295,613,614,615,616,617,_,619,620,37297,622,623,624,625,626,627,628,629,630,631,37298,37299,37300,37301,37302,37303,37304,37305,37306,_,_,37308,37309,37310,_,_,_,645,_,646,647,#,648,#,649,650,651,652,_,_,_,654,_,_,_,_,_,_] stack: [37366] locks: [] rethrowException]
Other frame state: [locals: [1,600,601,602,603,38864,605,606,607,608,#,609,610,38865,38866,613,614,615,616,617,_,619,620,38867,622,623,624,625,626,627,628,629,630,631,38866,38868,38869,38870,38871,38872,38873,38874,38875,_,_,38866,38876,38877,_,_,_,645,_,646,647,#,648,#,649,650,651,652,_,_,_,654,_,_,_,_,_,_] stack: [38878] locks: []]
Parser context: gabilan.transaction_native_image.0.main.main(main.bal:0) [bci: 2927, intrinsic: false]
2927: ldc           #255        // 1
2929: istore        13
2931: getstatic     #50         // gabilan.transaction_native_image/0.constants.$_string_constants.$bString8:io.ballerina.runtime.api.values.BString
2934: astore        5
2936: aload         18

        at jdk.internal.vm.compiler/org.graalvm.compiler.java.FrameStateBuilder.checkCompatibleWith(FrameStateBuilder.java:399)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.FrameStateBuilder.merge(FrameStateBuilder.java:431)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.createTarget(BytecodeParser.java:3133)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.createTarget(BytecodeParser.java:3033)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.createExceptionDispatch(BytecodeParser.java:3288)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3188)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1138)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
        at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:97)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:84)
        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:446)
        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 org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:135)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:685)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysis.java:180)
        at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1162)
        at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1145)
        at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1003)
        at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:957)
        at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:817)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysis.java:240)
        at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:548)
        at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:833)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:98)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:179)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:349)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:93)
        ... 19 more
------------------------------------------------------------------------------------------------------------------------
                        1.1s (5.1% of total time) in 16 GCs | Peak RSS: 2.35GB | CPU load: 4.75
========================================================================================================================
Failed generating 'transaction_native_image' after 20.9s.
Error: Image build request failed with exit status 1
error: unable to create native image
thomaswue commented 1 year ago

How were those bytecodes in the JAR file generated? Was it a certain javac version or some other means? It looks like a very strange and possibly invalid bytecode pattern. Possibly a finally block that needs to rethrow an exception has the same target bci as some other regular execution.

gabilang commented 1 year ago

This JAR contains bytecodes which are instrumented with ASM bytecode manipulation framework. Created this since, the jar (provided here is a simplified version) is running as expected with JVM and gives above error for native image build with GraalVm.