0

我正在通过运行构建本机 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

4

1 回答 1

1

终于知道怎么弄了。其他构建参数作为属性添加。例如。

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

或进入 application.properties 中src/resources

quarkus.native.additional-build-args=-H:+TraceClassInitialization

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

于 2020-02-18T09:45:56.893 回答