GoogleCloudPlatform / native-image-support-java

Enables GraalVM Native Image support for Google Cloud Java Client Libraries.
Apache License 2.0
79 stars 21 forks source link

GraalVM 22.1.0 - UnsupportedFeatureException: Detected a PlatformManagedObject #393

Closed jamesnetherton closed 2 years ago

jamesnetherton commented 2 years ago

Building a native image with the Google Cloud libraries results in a build failure when using GraalVM 22.1.0:

Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a PlatformManagedObject (a MXBean defined by the virtual machine) in the image heap. This bean is introspecting the VM that runs the image builder, i.e., a VM instance that is no longer available at image runtime. Class of disallowed object: com.sun.management.internal.HotSpotDiagnostic  To see how this object got instantiated use --trace-object-instantiation=com.sun.management.internal.HotSpotDiagnostic. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    at com.oracle.graal.pointsto.util.AnalysisFuture.setException(AnalysisFuture.java:49)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:269)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$9(ImageHeapScanner.java:611)
    at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
    at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:2984)
    at com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:243)
    at com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:688)
    at com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:676)
    at com.oracle.graal.pointsto.PointsToAnalysis.runAnalysis(PointsToAnalysis.java:732)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:723)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:558)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a PlatformManagedObject (a MXBean defined by the virtual machine) in the image heap. This bean is introspecting the VM that runs the image builder, i.e., a VM instance that is no longer available at image runtime. Class of disallowed object: com.sun.management.internal.HotSpotDiagnostic  To see how this object got instantiated use --trace-object-instantiation=com.sun.management.internal.HotSpotDiagnostic. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.error(DisallowedImageHeapObjectFeature.java:173)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.checkDisallowedMBeanObjects(DisallowedImageHeapObjectFeature.java:162)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.replacer(DisallowedImageHeapObjectFeature.java:119)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:582)
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.replaceObject(AnalysisConstantReflectionProvider.java:257)
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.interceptValue(AnalysisConstantReflectionProvider.java:228)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.transformFieldValue(SVMImageHeapScanner.java:126)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:331)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:310)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$computeTypeData$1(ImageHeapScanner.java:153)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    ... 18 more
mpeddada1 commented 2 years ago

Thank you so much for filing this issue @jamesnetherton! We're aware of this issue and are currently looking into it. Could you provide us with a bit more information on what client libraries you're experiencing this with? What version of the libraries-bom/ the client libraries are you currently using?

jamesnetherton commented 2 years ago

Using libraries-bom 16.3.0 (just realized that is somewhat old now..). Here's the dependency tree for the affected modules in my project:

google-cloud-storage

[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ camel-quarkus-google-storage ---
[INFO] org.apache.camel.quarkus:camel-quarkus-google-storage:jar:2.10.0-SNAPSHOT
[INFO] +- com.google.cloud:native-image-support:jar:0.14.0:compile
[INFO] \- org.apache.camel:camel-google-storage:jar:3.17.0-SNAPSHOT:compile
[INFO]    \- com.google.cloud:google-cloud-storage:jar:1.113.8:compile
[INFO]       +- com.google.cloud:google-cloud-core:jar:1.94.0:compile
[INFO]       \- com.google.cloud:google-cloud-core-http:jar:1.94.0:compile

google-cloud-bigquery

[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ camel-quarkus-google-bigquery ---
[INFO] org.apache.camel.quarkus:camel-quarkus-google-bigquery:jar:2.10.0-SNAPSHOT
[INFO] +- com.google.cloud:native-image-support:jar:0.14.0:compile
[INFO] \- org.apache.camel:camel-google-bigquery:jar:3.17.0-SNAPSHOT:compile
[INFO]    \- com.google.cloud:google-cloud-bigquery:jar:1.126.3:compile
[INFO]       +- com.google.cloud:google-cloud-core:jar:1.94.0:compile
[INFO]       \- com.google.cloud:google-cloud-core-http:jar:1.94.0:compile

google-cloud-pubsub

[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ camel-quarkus-google-pubsub ---
[INFO] org.apache.camel.quarkus:camel-quarkus-google-pubsub:jar:2.10.0-SNAPSHOT
[INFO] +- com.google.cloud:native-image-support:jar:0.14.0:compile
[INFO] \- org.apache.camel:camel-google-pubsub:jar:3.17.0-SNAPSHOT:compile
[INFO]    \- com.google.cloud:google-cloud-pubsub:jar:1.110.3:compile
mpeddada1 commented 2 years ago

Thank you!

loicmathieu commented 2 years ago

I also have the issue, I notice that the GraalVM library is in scope provided. Google native image support is based on org.graalvm.nativeimage:svm. ~Where the new version of GraalVM relocate the artifact in org.graalvm.sdk:graal-sdk:jar:22.1.0.~

~So it appears the switch should be done to the new artifact also.~

loicmathieu commented 2 years ago

@jamesnetherton the issue should be fixed at Quarkus GCP extension side, you can track this issue: https://github.com/quarkusio/quarkus/issues/25501

suztomo commented 2 years ago

@loicmathieu Would you share your finding about relocation?

Where the new version of GraalVM relocate the artifact in org.graalvm.sdk:graal-sdk:jar:22.1.0

Does that mean certain classes are in a different Java package in org.graalvm.sdk:graal-sdk:jar:22.1.0?

loicmathieu commented 2 years ago

I have no idea, they change the Maven artifact but I don't know if the packages changed.

loicmathieu commented 2 years ago

@suztomo forget what I just said, there is two different artefact and org.graalvm.nativeimage:svm is not yet release for 22.1.

suztomo commented 2 years ago

@loicmathieu Thank you for clarification. That matches my understanding.

mpeddada1 commented 2 years ago

Hey all, 0.14.1 has been released with this fix.

loicmathieu commented 2 years ago

Thanks, I'll confirm tomorrow if it fixes the issue.