Monitoring Java Safepoint Time in JDK16+

Carter Kozak ckozak at ckozak.net
Fri Jun 18 14:56:26 UTC 2021


On Fri, Jun 18, 2021, at 02:47, David Holmes wrote:
> On 18/06/2021 4:35 pm, Alan Bateman wrote:
> > On 17/06/2021 22:44, David Holmes wrote:
> >>
> >> I must admit I'm a bit confused about these implementation-specific 
> >> MBeans. They are implementation-specific, so no part of the primary 
> >> java.management namespace, but they are provided so that they can be 
> >> used - so shutting them behind the modular doors (so to speak) really 
> >> doesn't make much sense to me.
> > The JDK-specific MBeans are in the com.sun.management package, exported 
> > by the jdk.management module.  The sun.management.* classes have always 
> > been JDK-internal implementation classes and were never mean to be used 
> > directly by code outside of the JDK. Directly referencing these classes 
> > would have been a warning at compile prior with JDK 8 and older. It 
> > changed an error at compile time in JDK 9.
> 
> Ah! I now see:
> 
>     /**
>       * This method is for testing only.
>       */
>      public static synchronized HotspotRuntimeMBean 
> getHotspotRuntimeMBean() {
>          if (hsRuntimeMBean == null) {
>              hsRuntimeMBean = new HotspotRuntime(jvm);
>          }
>          return hsRuntimeMBean;
>      }
> 
> in sun.management.ManagementFactoryHelper. So it seems there is no 
> actual _use_ of these platform-specific MBeans even within the JDK. So 
> their existence seems somewhat pointless.
> 
> Cheers,
> David
> 
> 
> > -Alan
> 

I think we've accurately described the problem, and why this mechanism cannot be relied upon in newer Java releases.
Do we also agree that the information it exposes is useful, and should be provided by the JVM in an accessible way?

While the current bean is implementation-specific, safepoints are a core concept required to understand java performance, much like the existing (exported) java.lang.management.GarbageCollectorMXBean information. Perhaps it would be reasonable to spec out a new java.lang.management.SafepointMXBean?

This is a relatively common use-case based on a quick github search (unfortunately it's difficult to sift out the hits across old openjdk repository copies).
https://github.com/apache/pulsar/blob/master/pulsar-common/src/main/java/org/apache/pulsar/common/stats/JvmDefaultGCMetricsLogger.java
https://github.com/CorfuDB/CorfuDB/blob/master/common/src/main/java/org/corfudb/common/metrics/micrometer/JVMMetrics.java
https://github.com/criteo/garmadon/blob/master/jvm-statistics/src/main/java/com/criteo/hadoop/garmadon/jvm/statistics/SafepointStatistics.java
https://github.com/palantir/jvm-diagnostics/blob/develop/jvm-diagnostics/src/main/java/com/palantir/jvm/diagnostics/JvmDiagnostics.java
https://github.com/prometheus/client_java/issues/576

Thanks,
Carter Kozak


More information about the serviceability-dev mailing list