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.03k stars 1.6k forks source link

MBean / MXBean issue during native build #2669

Closed simonDeHero closed 3 years ago

simonDeHero commented 4 years ago

Describe the issue I am building a smallish Spring Webapp (REST, JPA, Feign client to call other service, putting messages to AWS SQS). I get the following errors:

...
[opa:4649]     (clinit):   6,387.72 ms, 28.56 GB
[opa:4649]   (typeflow): 118,720.35 ms, 28.56 GB
[opa:4649]    (objects): 231,576.89 ms, 28.56 GB
[opa:4649]   (features):  95,322.29 ms, 28.56 GB
[opa:4649]     analysis: 467,939.15 ms, 28.56 GB
Error: Unsupported features in 7 methods
Detailed message:
Error: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field java.lang.management.ManagementFactory.platformMBeanServer
Error: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: org.apache.tomcat.util.modeler.NoDescriptorRegistry$NoJmxMBeanServer  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field org.apache.catalina.mbeans.MBeanUtils.mserver
Error: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: org.apache.tomcat.util.modeler.NoDescriptorRegistry$NoJmxMBeanServer  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field org.apache.tomcat.util.modeler.NoDescriptorRegistry.mBeanServer of
        constant org.apache.tomcat.util.modeler.NoDescriptorRegistry@32217484 reached by 
    reading field org.apache.catalina.mbeans.MBeanUtils.registry
Error: 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 run time. Class of disallowed object: com.sun.management.internal.HotSpotDiagnostic  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field com.sun.management.internal.PlatformMBeanProviderImpl.hsDiagMBean
Error: 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 run time. Class of disallowed object: jdk.management.jfr.FlightRecorderMXBeanImpl  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field jdk.management.jfr.internal.FlightRecorderMXBeanProvider.flightRecorderMXBean
Error: 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 run time. Class of disallowed object: sun.management.ManagementFactoryHelper$1  Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. 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-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    indexing into array
        constant java.lang.Object[]@59768343 reached by 
    reading field java.util.ArrayList.elementData of
        constant java.util.ArrayList@62c83247 reached by 
    reading field sun.management.ManagementFactoryHelper.bufferPools
...

I also tried to initialize the relevant classes at run-time, but then i got different errors:

...
[opa:4345]     analysis: 243,161.57 ms, 13.39 GB
Error: Classes that should be initialized at run time got initialized during image building:
 com.sun.management.internal.HotSpotDiagnostic the class was requested to be initialized at run time (from the command line). com.sun.management.internal.HotSpotDiagnostic has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of com.sun.management.internal.HotSpotDiagnostic
org.apache.catalina.mbeans.MBeanUtils the class was requested to be initialized at run time (from the command line). org.apache.catalina.mbeans.MBeanUtils has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of org.apache.catalina.mbeans.MBeanUtils
com.sun.jmx.mbeanserver.JmxMBeanServer the class was requested to be initialized at run time (from the command line). com.sun.jmx.mbeanserver.JmxMBeanServer has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of com.sun.jmx.mbeanserver.JmxMBeanServer
...

so it seems, that i am stuck, because initializing during build does not work, and also initializing at run-time does not work either.

Steps to reproduce the issue I am really sorry, i cannot share the code

Describe GraalVM and your environment:

More details my build command (snippet):

/opt/graalvm-ce-java11-20.2.0-dev/bin/native-image \
  --verbose \
  --no-server -J-Xmx32G\
  --no-fallback \
  --initialize-at-build-time \
  --enable-all-security-services \
  -H:+TraceClassInitialization \
  --delay-class-initialization-to-runtime=org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping \
  --initialize-at-run-time=org.apache.tomcat.jni.OS \
  --initialize-at-run-time=org.apache.tomcat.util.net.openssl.OpenSSLEngine \
  --initialize-at-run-time=org.springframework.web.reactive.result.method.RequestMappingInfo \
  --initialize-at-run-time=org.springframework.web.reactive.result.condition.PatternsRequestCondition \
  --initialize-at-run-time=org.apache.juli.AsyncFileHandler \
  -H:Name=opa \
  -H:+ReportExceptionStackTraces \
  -Dspring.native.remove-unused-autoconfig=true \
  -Dspring.native.missing-selector-hints=warning \
  -Dspring.native.verbose=true \
  -cp BOOT-INF/classes:$LIBPATH:/home/ubuntu/graalbuild/spring-graal-native-0.7.0.BUILD-SNAPSHOT.jar:/home/ubuntu/graalbuild/spring-webflux-5.2.7.RELEASE.jar \
simonDeHero commented 3 years ago

bump :-)

cstancu commented 3 years ago

@vjovanov would your recent changes to class initialization help avoid these MBean issues? @simonDeHero you could try rebuilding with a dev version that contains https://github.com/oracle/graal/issues/2650.

simonDeHero commented 3 years ago

thx! i will try then with 20.2, when it is released

vjovanov commented 3 years ago

Yes, my changes could help with this issue. Let me know if it worked out.

cstancu commented 3 years ago

Please reopen if still an issue.

chuailiwu commented 1 year ago

version OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) still is an issue.