oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.27k stars 1.63k forks source link

[native-image] sun.security.provider.X509Factory - Static field or an object referenced from a static field changed during native image generation #2389

Closed dimasukr closed 4 years ago

dimasukr commented 4 years ago

Describe issue Error during native image build. Very simple vertx-pg-client project - https://github.com/dimasukr/graalvm-vertx-repro/blob/master/src/main/java/App.java

Steps to reproduce the issue Please include both build steps as well as run steps

  1. git clone --depth 1 https://github.com/dimasukr/graalvm-vertx-repro.git
  2. sh docker_build.sh Or if no docker then:
    mvn package
    mkdir build
    cp ./target/bootstrap.jar ./build/
    cp ./docker/native-config/*.json ./build/
    cp ./docker/build_native.sh ./build/
    cd ./build
    sh ./build_native.sh

Describe GraalVM and your environment:

More details

Fatal error: com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.UserError$UserException: Image heap writing found an object whose class was not seen as instantiated during static analysis. Did a static field or an object referenced from a static field change during native image generation? For example, a lazily initialized cache could have been initialized during image generation, in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.
   object: sun.security.provider.X509Factory@2ad0dba6 of class: sun.security.provider.X509Factory
   reachable through:
     object: java.security.cert.CertificateFactory@6074f49f  of class: java.security.cert.CertificateFactory
     root: HostedField<SslContext.X509_CERT_FACTORY location: 4152   AnalysisField<SslContext.X509_CERT_FACTORY accessed: false reads: false written: true>>
       at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:70)
       at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:641)
       at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
       at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
       at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
       at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
       at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
       at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
       at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Caused by: com.oracle.svm.core.util.UserError$UserException: Image heap writing found an object whose class was not seen as instantiated during static analysis. Did a static field or an object referenced from a static field change during native image generation? For example, a lazily initialized cache could have been initialized during image generation, in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.
   object: sun.security.provider.X509Factory@2ad0dba6 of class: sun.security.provider.X509Factory
   reachable through:
     object: java.security.cert.CertificateFactory@6074f49f  of class: java.security.cert.CertificateFactory
     root: HostedField<SslContext.X509_CERT_FACTORY location: 4152   AnalysisField<SslContext.X509_CERT_FACTORY accessed: false reads: false written: true>>
       at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
       at com.oracle.svm.hosted.image.NativeImageHeap.requireType(NativeImageHeap.java:473)
       at com.oracle.svm.hosted.image.NativeImageHeap.addObjectToBootImageHeap(NativeImageHeap.java:363)
       at com.oracle.svm.hosted.image.NativeImageHeap.addObject(NativeImageHeap.java:312)
       at com.oracle.svm.hosted.image.NativeImageHeap.processAddObjectWorklist(NativeImageHeap.java:565)
       at com.oracle.svm.hosted.image.NativeImageHeap.addTrailingObjects(NativeImageHeap.java:200)
       at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:620)
       ... 7 more
dimasukr commented 4 years ago

Any ideas on workaround?

dimasukr commented 4 years ago

Same issue in 20.1.0

BornToRain commented 4 years ago

add --enable-all-security-services can fix this bug in 20.1.0.

dimasukr commented 4 years ago

Yes this helps but it doubles size of the image which is not ideal

cstancu commented 4 years ago

Yes, the security services API brings in quite a bit of code. You may be able to reduce that if you know exact security services that your app needs: https://github.com/oracle/graal/blob/master/substratevm/JCA-SECURITY-SERVICES.md#alternative-to---enable-all-security-services. We are also working on a solution to automate the discovery of needed security services based on code reachability.

dimasukr commented 4 years ago

I'm actually not using any security services and don't want to enable them at all. It is possible that vertx is using those somehow