我正在通过运行构建本机 GraalVM 本机映像:
./mvnw package -Pnative
这会引发错误:
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>.
我可以看到native-image
它尝试运行的命令:
/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
所以我想我可以添加-H:+TraceClassInitialization
错误,但是当我在native-image
有或没有跟踪选项的情况下运行时,我会得到一个不同的错误:
[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.
我不确定是否相关。我猜想通过 maven 运行会设置一些上下文,并且想知道pom.xml
文件上是否有我可以设置要求的属性-H:+TraceClassInitialization