I am building a native GraalVM native image by running:
./mvnw package -Pnative
This throws an error :
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. To see how this object got instantiated use -H:+TraceClassInitialization. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image run time by using the option --initialize-at-build-time=<class-name>.
I can see the native-image
command that it tried to run:
/Library/Java/JavaVirtualMachines/graalvm-ce-java8-19.3.1/Contents/Home/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -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=1 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar get-started-1.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace get-started-1.0-SNAPSHOT-runner
so I think I can add the -H:+TraceClassInitialization
error, but when I do run native-image
with or without the trace option I get a different error:
[get-started-1.0-SNAPSHOT-runner:52581] classlist: 7,548.63 ms
[get-started-1.0-SNAPSHOT-runner:52581] setup: 55.85 ms
Error: policy com.oracle.svm.core.genscavenge.CollectionPolicy cannot be instantiated.
com.oracle.svm.core.util.UserError$UserException: policy com.oracle.svm.core.genscavenge.CollectionPolicy cannot be instantiated.
which I am not sure is related. I am guessing that running through maven sets up some context, and wondering if there is a property on the pom.xml
file that I can set to ask for -H:+TraceClassInitialization
Eventually found out how. Additional build args are added as properties. eg.
<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.additional-build-args>-H:+TraceClassInitialization</quarkus.native.additional-build-args>
</properties>
or into application.properties in src/resources
quarkus.native.additional-build-args=-H:+TraceClassInitialization
Now I can work out which classed need to be pre-initialised. I am having difficulty setting the --initialize-at-build-time=
as it is already present with an empty list. Back to the documentation. If I can't find anything, then I will pose a fresh question.