Skip to content

[Native Image] ImageLayerLoader unable to restore state of annotations #10101

@Sanne

Description

@Sanne

Describe the Issue

When ImageLayerLoader#createBaseLayerMethod is loading the layer's methodData it's defining annotations as well, but these annotations seem lacking their attributes.

In some cases not having these values leads to critical failures; for example GraalVM itself makes use of the annotation com.oracle.svm.core.AlwaysInline which strictly requires a value for its main attribute. This is used, for example, in Target_jdk_internal_foreign_SegmentFactories.

The lack of this attribute leads to the annotation being invalid, which in turn results in a critical compilation error:

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing com.oracle.svm.core.foreign.Util_java_lang_foreign_SymbolLookup$1.find(Target_java_lang_foreign_SymbolLookup.java:169) 
Parsing context:
   at com.oracle.svm.core.foreign.Target_jdk_internal_foreign_SystemLookup.find(Target_jdk_internal_foreign_SystemLookup.java:43)
   at root method.(Unknown Source)

	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:165)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:189)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultVirtualInvokeTypeFlow.onObservedUpdate(DefaultVirtualInvokeTypeFlow.java:119)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:870)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:600)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:166)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:152)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1735)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
	at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1650)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1459)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:191)
Caused by: jdk.graal.compiler.debug.GraalError: Error in record 57 (field -1)
	at jdk.graal.compiler/jdk.graal.compiler.util.ObjectCopier$Decoder.decode(ObjectCopier.java:555)
	at jdk.graal.compiler/jdk.graal.compiler.util.ObjectCopier.decode(ObjectCopier.java:404)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageLayerLoader.getAnalysisParsedGraph(ImageLayerLoader.java:820)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.lambda$getBaseLayerGraph$0(AnalysisMethod.java:1003)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.setGraph(AnalysisMethod.java:1023)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.getBaseLayerGraph(AnalysisMethod.java:1003)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsedHelper(AnalysisMethod.java:977)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:958)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysisGraphDecoder.java:181)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1215)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1198)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1053)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvokeWithCallTarget(PEGraphDecoder.java:1005)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:991)
	at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:926)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysisGraphDecoder.java:269)
	at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:654)
	at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:895)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:73)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:239)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:715)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:167)
	... 14 more
Caused by: com.oracle.svm.hosted.annotation.AnnotationMetadata$AnnotationExtractionError: Failed to process '@com.oracle.svm.core.AlwaysInline()': java.lang.reflect.InvocationTargetException
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.AnnotationValue.lambda$new$0(AnnotationValue.java:95)
	at java.base/java.util.HashMap.forEach(HashMap.java:1430)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.AnnotationValue.<init>(AnnotationValue.java:90)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:215)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:636)
	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:291)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:656)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:662)
	at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:667)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.getAnnotationData(SubstrateAnnotationExtractor.java:189)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor.hasAnnotation(SubstrateAnnotationExtractor.java:149)
	at org.graalvm.nativeimage/org.graalvm.nativeimage.AnnotationAccess.isAnnotationPresent(AnnotationAccess.java:82)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.cenum.CEnumCallWrapperSubstitutionProcessor.lookup(CEnumCallWrapperSubstitutionProcessor.java:54)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:121)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:121)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:121)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:417)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:396)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageLayerLoader.createBaseLayerMethod(ImageLayerLoader.java:749)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageLayerLoader.loadMethod(ImageLayerLoader.java:709)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageLayerLoader.getAnalysisMethod(ImageLayerLoader.java:755)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil$AnalysisMethodBuiltIn.decode(ImageLayerSnapshotUtil.java:355)
	at jdk.graal.compiler/jdk.graal.compiler.util.ObjectCopier$Decoder.decode(ObjectCopier.java:489)
	... 35 more

I do also wonder what other problems are likely going to be caused by this, I believe many of our frameworks would need to read the actual annotation attributes; it seems that the current code would fallback to their default values, which is not correct.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

openjdk version "24" 2025-03-18
OpenJDK Runtime Environment GraalVM CE 24-dev+23.1 (build 24+23-jvmci-b01)
OpenJDK 64-Bit Server VM GraalVM CE 24-dev+23.1 (build 24+23-jvmci-b01, mixed mode, sharing)

Built from e238132d615da50c4d380c76dbe548caf94e5834

Operating System and Version

Fedora Linux 41

Build Command

Core layer preparation:

/opt/graalvm-localbuild/bin/native-image -H:LayerCreate=libcore.nil,module=java.base,module=java.sql --no-fallback --link-at-build-time --initialize-at-run-time=sun.java2d --initialize-at-run-time=sun.font --initialize-at-run-time=sun.awt.X11 -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -H:-AddAllCharsets -o libcore.nil

Failing build:

/opt/graalvm-localbuild/bin/native-image -H:LayerUse=libcore.nil -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Duser.language=en -J-Duser.country=GB -J-Dlogging.initial-configurator.min-level=500 -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -H:+UnlockExperimentalVMOptions -H:IncludeLocales=en-GB -H:-UnlockExperimentalVMOptions -J-Dfile.encoding=UTF-8 --features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.DisableLoggingFeature -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-exports=java.security.jgss/sun.security.jgss=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -H:+UnlockExperimentalVMOptions -H:BuildOutputJSONFile=getting-started-1.0.0-SNAPSHOT-runner-build-output-stats.json -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+GenerateBuildArtifactsFile -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+AllowFoldMethods -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+ForeignAPISupport -H:-UnlockExperimentalVMOptions -J-Djava.awt.headless=true --no-fallback --link-at-build-time -H:+UnlockExperimentalVMOptions -H:+ReportExceptionStackTraces -H:-UnlockExperimentalVMOptions -H:-AddAllCharsets --enable-url-protocols=http -H:NativeLinkerOption=-no-pie --enable-monitoring=heapdump -H:+UnlockExperimentalVMOptions -H:-UseServiceLoaderFeature -H:-UnlockExperimentalVMOptions -J--add-exports=org.graalvm.nativeimage/org.graalvm.nativeimage.impl=ALL-UNNAMED --exclude-config io\.netty\.netty-codec /META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json --exclude-config io\.netty\.netty-handler /META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json --initialize-at-run-time=sun.awt --initialize-at-runtime=sun.font -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -jar getting-started-1.0.0-SNAPSHOT-runner.jar

Expected Behavior

To be able to use annotations as usual.

Actual Behavior

Failed build

Steps to Reproduce

I hope the description I provided is clear enough as I pointed to the specific code which is problematic.

Additional Context

No response

Build Log Output and Error Messages

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions