< prev index next >

src/share/classes/sun/management/ExtendedPlatformComponent.java

Print this page
rev 13762 : 8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

@@ -23,13 +23,16 @@
  * questions.
  */
 
 package sun.management;
 
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.lang.management.PlatformManagedObject;
+import java.lang.reflect.Method;
 
 /**
  * Class to allow for an extended set of platform MXBeans
  */
 public final class ExtendedPlatformComponent {

@@ -38,17 +41,39 @@
     /**
      * Get the extended set of platform MXBeans that should be registered in the
      * platform MBeanServer, or an empty list if there are no such MXBeans.
      */
     public static List<? extends PlatformManagedObject> getMXBeans() {
+        PlatformManagedObject o = getFlightRecorderBean();
+        if (o != null) {
+            return Collections.singletonList(o);
+        } else {
         return Collections.emptyList();
     }
+    }
 
     /**
      * Returns the extended platform MXBean implementing the given
      * mxbeanInterface, or null if there is no such MXBean.
      */
     public static <T extends PlatformManagedObject>
             T getMXBean(Class<T> mxbeanInterface) {
+
+        if ("jdk.management.jfr.FlightRecorderMXBean".equals(mxbeanInterface.getName())) {
+            return (T)getFlightRecorderBean();
+        }
         return null;
     }
+
+    private static PlatformManagedObject getFlightRecorderBean() {
+        PlatformManagedObject object = null;
+        try {
+            Class provider = Class.forName("jdk.management.jfr.internal.FlightRecorderMXBeanProvider");
+            Method m = provider.getDeclaredMethod("getFlightRecorderMXBean");
+
+            object =  (PlatformManagedObject)m.invoke(null);
+        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+            // no jfr?
+        }
+        return object;
+    }
 }
< prev index next >