Skip to content

Commit

Permalink
Fix ClassCastException on J9 (#506)
Browse files Browse the repository at this point in the history
fixes #505
  • Loading branch information
felixbarny authored Mar 4, 2019
1 parent 39c4d1b commit 4fb3928
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ public double get() {

try {
// only refer to hotspot specific class via reflection to avoid linkage errors
Class.forName("com.sun.management.ThreadMXBean");
// in reference to JMH's GC profiler (gc.alloc.rate)
registry.add("jvm.gc.alloc", Collections.<String, String>emptyMap(),
(DoubleSupplier) Class.forName(getClass().getName() + "$HotspotAllocationSupplier").getEnumConstants()[0]);
final Class<?> sunBeanClass = Class.forName("com.sun.management.ThreadMXBean");
// J9 does contain com.sun.management.ThreadMXBean in classpath
// but the actual MBean it uses (com.ibm.lang.management.internal.ExtendedThreadMXBeanImpl) does not implement it
if (sunBeanClass.isInstance(ManagementFactory.getThreadMXBean())) {
// in reference to JMH's GC profiler (gc.alloc.rate)
registry.add("jvm.gc.alloc", Collections.<String, String>emptyMap(),
(DoubleSupplier) Class.forName(getClass().getName() + "$HotspotAllocationSupplier").getEnumConstants()[0]);
}
} catch (ClassNotFoundException ignore) {
}
}
Expand Down

0 comments on commit 4fb3928

Please sign in to comment.