构建 graalvm 可执行文件时,H:+TraceClassInitialization 是否有 pom.xml 选项?

Is there a pom.xml option for H:+TraceClassInitialization when building a graalvm executable?

我正在通过 运行ning 构建原生 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.

我不确定这是否相关。我猜测 运行ning 通过 maven 设置了一些上下文,并且想知道 pom.xml 文件上是否有一个 属性 我可以设置为请求 -H:+TraceClassInitialization

终于找到方法了。额外的构建参数作为属性添加。例如。

  <properties>
    <quarkus.package.type>native</quarkus.package.type>
    <quarkus.native.additional-build-args>-H:+TraceClassInitialization</quarkus.native.additional-build-args>
  </properties>

src/resources

中的 application.properties
quarkus.native.additional-build-args=-H:+TraceClassInitialization

现在我可以算出哪些类需要预初始化了。我在设置 --initialize-at-build-time= 时遇到困难,因为它已经存在于一个空列表中。回到文档。如果我找不到任何东西,那么我会提出一个新的问题。