我正在尝试使用 Graal 的原生镜像创建 Spigot 1.15 的原生镜像。我正在使用命令:
native-image -jar spigot-1.15.jar
但是编译失败并出现 NPE:https ://hasteb.in/qujocavi
native-image -H:+PrintClassInitialization -jar spigot-1.15.jar --report-unsupported-elements-at-runtime --initialize-at-run-time=net.minecraft.server.v1_15_R1
[spigot-1.15:12284] classlist: 6,064.54 ms, 1.41 GB
[spigot-1.15:12284] (cap): 2,575.63 ms, 1.41 GB
[spigot-1.15:12284] setup: 4,437.12 ms, 1.41 GB
Printing initializer configuration to C:\Dev\reports\initializer_configuration_20200222_133304.txt
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated
Unable to bootstrap registry 'minecraft:entity_type'
Registry 'minecraft:entity_type' was empty after loading
[spigot-1.15:12284] analysis: 17,393.28 ms, 1.79 GB
Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing net.minecraft.server.v1_15_R1.Raid.a(net.minecraft.server.v1_15_R1.Raid$Wave, java.util.Random, int, net.minecraft.server.v1_15_R1.DifficultyDamageScaler, boolean)
Parsing context:
parsing net.minecraft.server.v1_15_R1.Raid.b(Raid.java:481)
parsing net.minecraft.server.v1_15_R1.Raid.o(Raid.java:291)
parsing net.minecraft.server.v1_15_R1.PersistentRaid.a(PersistentRaid.java:43)
parsing net.minecraft.server.v1_15_R1.WorldServer.doTick(WorldServer.java:309)
parsing net.minecraft.server.v1_15_R1.MinecraftServer.b(MinecraftServer.java:1076)
parsing net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:393)
parsing net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:978)
parsing net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:823)
parsing com.oracle.svm.core.jdk.RuntimeSupport.executeHooks(RuntimeSupport.java:144)
parsing com.oracle.svm.core.jdk.RuntimeSupport.executeTearDownHooks(RuntimeSupport.java:121)
parsing com.oracle.svm.core.graal.snippets.CEntryPointSnippets.tearDownIsolate(CEntryPointSnippets.java:395)
at com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:138)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:323)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:300)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:107)
at com.oracle.graal.pointsto.flow.SpecialInvokeTypeFlow.onObservedUpdate(InvokeTypeFlow.java:421)
at com.oracle.graal.pointsto.flow.TypeFlow.notifyObservers(TypeFlow.java:344)
at com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:386)
at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:511)
at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:171)
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$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:177)
Caused by: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: org.graalvm.compiler.debug.GraalError: java.lang.reflect.InvocationTargetException
at parsing net.minecraft.server.v1_15_R1.Raid.a(Raid.java:701)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2582)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:94)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3402)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3204)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1085)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:979)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.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:197)
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:221)
at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:340)
at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:310)
... 13 more
Caused by: org.graalvm.compiler.debug.GraalError: java.lang.reflect.InvocationTargetException
at jdk.internal.vm.compiler/org.graalvm.compiler.debug.GraalError.shouldNotReachHere(GraalError.java:55)
at com.oracle.graal.pointsto.meta.AnalysisMethod.<init>(AnalysisMethod.java:149)
at com.oracle.graal.pointsto.meta.AnalysisUniverse.createMethod(AnalysisUniverse.java:412)
at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:400)
at com.oracle.graal.pointsto.infrastructure.WrappedConstantPool.lookupMethod(WrappedConstantPool.java:116)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.lookupMethodInPool(BytecodeParser.java:4285)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.lookupMethodInPool(SharedGraphBuilderPhase.java:107)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.lookupMethod(BytecodeParser.java:4279)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1656)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5288)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3397)
... 24 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.oracle.graal.pointsto.meta.AnalysisMethod.<init>(AnalysisMethod.java:147)
... 33 more
Caused by: java.lang.ExceptionInInitializerError
at net.minecraft.server.v1_15_R1.EntityTypes.a(EntityTypes.java:134)
at net.minecraft.server.v1_15_R1.EntityTypes.<clinit>(EntityTypes.java:16)
at net.minecraft.server.v1_15_R1.Raid$Wave.<clinit>(Raid.java:794)
at net.minecraft.server.v1_15_R1.Raid.$SWITCH_TABLE$net$minecraft$server$Raid$Wave(Raid.java:20)
... 38 more
Caused by: java.lang.NullPointerException: Missing default of DefaultedMappedRegistry: minecraft:pig
at org.bukkit.craftbukkit.libs.org.apache.commons.lang3.Validate.notNull(Validate.java:225)
at net.minecraft.server.v1_15_R1.IRegistry.a(SourceFile:140)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at net.minecraft.server.v1_15_R1.IRegistry.<clinit>(SourceFile:130)
... 42 more
我尝试使用--intiialize-at-run-time
参数,包括net.minecraft.server.v1_15_R1.IRegistry
在构建时避免类初始化,但我得到了同样的错误。
所以我的问题是如何将其编译为本机可执行文件?
native-image -jar spigot-1.15.jar
您可以通过在 spigotmc 上新下载的 spigot jar 上执行来重现该错误。