< prev index next >

src/share/classes/java/lang/management/PlatformComponent.java

Print this page
rev 13428 : jfr backport

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -35,14 +35,17 @@
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
 import com.sun.management.HotSpotDiagnosticMXBean;
 import com.sun.management.UnixOperatingSystemMXBean;
+import com.sun.management.VMOption;
 
 import sun.management.ManagementFactoryHelper;
 import sun.management.Util;
 
+import jdk.management.jfr.FlightRecorderMXBean;
+
 /**
  * This enum class defines the list of platform components
  * that provides monitoring and management support.
  * Each enum represents one MXBean interface. A MXBean
  * instance could implement one or more MXBean interfaces.

@@ -268,12 +271,32 @@
         true, // singleton
         new MXBeanFetcher<HotSpotDiagnosticMXBean>() {
             public List<HotSpotDiagnosticMXBean> getMXBeans() {
                 return Collections.singletonList(ManagementFactoryHelper.getDiagnosticMXBean());
             }
-        });
+        }),
 
+    /**
+     * Flight Recorder.
+     */
+    FLIGHT_RECORDER(
+        "jdk.management.jfr.FlightRecorderMXBean",
+        "jdk.management.jfr", "FlightRecorder", defaultKeyProperties(),
+        true,
+        new MXBeanFetcher<FlightRecorderMXBean>() {
+            public List<FlightRecorderMXBean> getMXBeans() {
+                HotSpotDiagnosticMXBean hsDiagMBean = ManagementFactoryHelper.getDiagnosticMXBean();
+                VMOption opt = hsDiagMBean.getVMOption("EnableJFR");
+                if (Boolean.valueOf(opt.getValue())) {
+                    FlightRecorderMXBean m = ManagementFactoryHelper.getFlightRecorderMXBean();
+                    if (m != null) {
+                        return Collections.singletonList(m);
+                    }
+                }
+                return Collections.emptyList();
+            }
+        });
 
     /**
      * A task that returns the MXBeans for a component.
      */
     interface MXBeanFetcher<T extends PlatformManagedObject> {

@@ -377,26 +400,28 @@
         return (List<T>) fetcher.getMXBeans();
     }
 
     <T extends PlatformManagedObject> T getSingletonMXBean(Class<T> mxbeanInterface)
     {
-        if (!singleton)
+        if (!singleton) {
             throw new IllegalArgumentException(mxbeanInterfaceName +
                 " can have zero or more than one instances");
+        }
 
         List<T> list = getMXBeans(mxbeanInterface);
         assert list.size() == 1;
         return list.isEmpty() ? null : list.get(0);
     }
 
     <T extends PlatformManagedObject>
             T getSingletonMXBean(MBeanServerConnection mbs, Class<T> mxbeanInterface)
         throws java.io.IOException
     {
-        if (!singleton)
+        if (!singleton) {
             throw new IllegalArgumentException(mxbeanInterfaceName +
                 " can have zero or more than one instances");
+        }
 
         // ObjectName of a singleton MXBean contains only domain and type
         assert keyProperties.size() == 1;
         String on = domain + ":type=" + type;
         return ManagementFactory.newPlatformMXBeanProxy(mbs,

@@ -457,12 +482,13 @@
         PlatformComponent getPlatformComponent(Class<T> mxbeanInterface)
     {
         ensureInitialized();
         String cn = mxbeanInterface.getName();
         PlatformComponent pc = enumMap.get(cn);
-        if (pc != null && pc.getMXBeanInterface() == mxbeanInterface)
+        if (pc != null && pc.getMXBeanInterface() == mxbeanInterface) {
             return pc;
+        }
         return null;
     }
 
     private static final long serialVersionUID = 6992337162326171013L;
 }
< prev index next >