graal icon indicating copy to clipboard operation
graal copied to clipboard

Upgrading to graal-sdk 22.1.0 resulting in `MXBean` issue: `UnsupportedFeatureException`

Open mpeddada1 opened this issue 3 years ago • 5 comments

Describe the issue Upgrading to the latest graal-sdk (22.1.0) is causing a failure at image build time. Note that this used to work fine with 22.0.0.2.

Describe GraalVM and your environment:

The code experiencing the issue transitively brings in a dependency that contains the following pom.xml setup:

 </dependencies>
<dependency>
      <groupId>org.graalvm.nativeimage</groupId>
      <artifactId>svm</artifactId>
      <version>22.0.0.2</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.graalvm.sdk</groupId>
      <artifactId>graal-sdk</artifactId>
      <version>22.1.0</version>
      <scope>provided</scope>
    </dependency>
 </dependencies>

Java setup:

openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06)
OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06, mixed mode, sharing)
  • OS: Linux

More details Running the native image build with the --trace-class-initialization=com.sun.management.internal.HotSpotDiagnostic results in:

INFO] Executing: .../.sdkman/candidates/java/22.1.0.r11-grl/bin/native-image @/tmp/native-image5789583573657594787args org.graalvm.junit.platform.NativeImageJUnitLauncher
...
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  Object has been initialized by the com.oracle.svm.hosted.jfr.JfrFeature class initializer with a trace: 
 	at com.sun.management.internal.HotSpotDiagnostic.<init>(HotSpotDiagnostic.java:42)
	at com.sun.management.internal.PlatformMBeanProviderImpl.getDiagnosticMXBean(PlatformMBeanProviderImpl.java:274)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Unknown Source)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:566)
	at com.oracle.svm.hosted.jfr.JfrFeature.getDiagnosticBean(JfrFeature.java:154)
	at com.oracle.svm.hosted.jfr.JfrFeature.<clinit>(JfrFeature.java:125)
. Try to avoid initializing the class that stores the object in a static field 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$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:183)
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  Object has been initialized by the com.oracle.svm.hosted.jfr.JfrFeature class initializer with a trace: 
 	at com.sun.management.internal.HotSpotDiagnostic.<init>(HotSpotDiagnostic.java:42)
	at com.sun.management.internal.PlatformMBeanProviderImpl.getDiagnosticMXBean(PlatformMBeanProviderImpl.java:274)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Unknown Source)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:566)
	at com.oracle.svm.hosted.jfr.JfrFeature.getDiagnosticBean(JfrFeature.java:154)
	at com.oracle.svm.hosted.jfr.JfrFeature.<clinit>(JfrFeature.java:125)
. Try to avoid initializing the class that stores the object in a static field 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)

I was wondering if anyone had seen this error message before? There were a couple of recent changes made to JfrFeature.class, which may be related? This issue from a previous GraalVM version looks similar: https://github.com/oracle/graal/issues/2669.

mpeddada1 avatar May 05 '22 16:05 mpeddada1

FTR @mpeddada1 found that this issue is caused by registering java.lang.management.ManagementFactory and java.lang.management.RuntimeMXBean for reflection, removing these registrations seems to fix the issue (see https://github.com/GoogleCloudPlatform/native-image-support-java/pull/395). Note however that it might still be worth fixing this issue since there might be some legitimate case that requires those classes to be registered for reflection.

zakkak avatar May 17 '22 12:05 zakkak

I have the same error, is there any solution?

cyw3 avatar Jul 01 '22 08:07 cyw3

same issue here

gad2103 avatar Jul 11 '22 22:07 gad2103

Any update on this issue, please as we are still observing the issue with graal version 22.1.0?

hemalatha2808 avatar Jul 15 '22 05:07 hemalatha2808

same issue +1

zliu9125 avatar Aug 08 '22 12:08 zliu9125