< prev index next >

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

Print this page
rev 13428 : jfr backport
   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  31 import javax.management.InstanceAlreadyExistsException;
  32 import javax.management.InstanceNotFoundException;
  33 import javax.management.MBeanServer;
  34 import javax.management.MBeanRegistrationException;
  35 import javax.management.NotCompliantMBeanException;
  36 import javax.management.ObjectName;
  37 import javax.management.RuntimeOperationsException;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedActionException;
  40 import java.security.PrivilegedExceptionAction;
  41 
  42 import sun.util.logging.LoggingSupport;
  43 
  44 import java.util.ArrayList;
  45 import java.util.Collections;
  46 import java.util.HashMap;
  47 import java.util.List;
  48 import com.sun.management.DiagnosticCommandMBean;
  49 import com.sun.management.HotSpotDiagnosticMXBean;
  50 



  51 import static java.lang.management.ManagementFactory.*;
  52 
  53 /**
  54  * ManagementFactoryHelper provides static factory methods to create
  55  * instances of the management interface.
  56  */
  57 public class ManagementFactoryHelper {
  58     private ManagementFactoryHelper() {};
  59 
  60     private static VMManagement jvm;
  61 
  62     private static ClassLoadingImpl    classMBean = null;
  63     private static MemoryImpl          memoryMBean = null;
  64     private static ThreadImpl          threadMBean = null;
  65     private static RuntimeImpl         runtimeMBean = null;
  66     private static CompilationImpl     compileMBean = null;
  67     private static OperatingSystemImpl osMBean = null;

  68 
  69     public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
  70         if (classMBean == null) {
  71             classMBean = new ClassLoadingImpl(jvm);
  72         }
  73         return classMBean;
  74     }
  75 
  76     public static synchronized MemoryMXBean getMemoryMXBean() {
  77         if (memoryMBean == null) {
  78             memoryMBean = new MemoryImpl(jvm);
  79         }
  80         return memoryMBean;
  81     }
  82 
  83     public static synchronized ThreadMXBean getThreadMXBean() {
  84         if (threadMBean == null) {
  85             threadMBean = new ThreadImpl(jvm);
  86         }
  87         return threadMBean;


  89 
  90     public static synchronized RuntimeMXBean getRuntimeMXBean() {
  91         if (runtimeMBean == null) {
  92             runtimeMBean = new RuntimeImpl(jvm);
  93         }
  94         return runtimeMBean;
  95     }
  96 
  97     public static synchronized CompilationMXBean getCompilationMXBean() {
  98         if (compileMBean == null && jvm.getCompilerName() != null) {
  99             compileMBean = new CompilationImpl(jvm);
 100         }
 101         return compileMBean;
 102     }
 103 
 104     public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
 105         if (osMBean == null) {
 106             osMBean = new OperatingSystemImpl(jvm);
 107         }
 108         return osMBean;







 109     }
 110 
 111     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
 112         MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
 113         List<MemoryPoolMXBean> list = new ArrayList<>(pools.length);
 114         for (MemoryPoolMXBean p : pools) {
 115             list.add(p);
 116         }
 117         return list;
 118     }
 119 
 120     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
 121         MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
 122         List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length);
 123         for (MemoryManagerMXBean m : mgrs) {
 124             result.add(m);
 125         }
 126         return result;
 127     }
 128 


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  31 import javax.management.InstanceAlreadyExistsException;
  32 import javax.management.InstanceNotFoundException;
  33 import javax.management.MBeanServer;
  34 import javax.management.MBeanRegistrationException;
  35 import javax.management.NotCompliantMBeanException;
  36 import javax.management.ObjectName;
  37 import javax.management.RuntimeOperationsException;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedActionException;
  40 import java.security.PrivilegedExceptionAction;
  41 
  42 import sun.util.logging.LoggingSupport;
  43 
  44 import java.util.ArrayList;
  45 import java.util.Collections;
  46 import java.util.HashMap;
  47 import java.util.List;
  48 import com.sun.management.DiagnosticCommandMBean;
  49 import com.sun.management.HotSpotDiagnosticMXBean;
  50 
  51 import jdk.management.jfr.FlightRecorderMXBean;
  52 import jdk.management.jfr.FlightRecorderMXBeanImpl;
  53 
  54 import static java.lang.management.ManagementFactory.*;
  55 
  56 /**
  57  * ManagementFactoryHelper provides static factory methods to create
  58  * instances of the management interface.
  59  */
  60 public class ManagementFactoryHelper {
  61     private ManagementFactoryHelper() {};
  62 
  63     private static VMManagement jvm;
  64 
  65     private static ClassLoadingImpl    classMBean = null;
  66     private static MemoryImpl          memoryMBean = null;
  67     private static ThreadImpl          threadMBean = null;
  68     private static RuntimeImpl         runtimeMBean = null;
  69     private static CompilationImpl     compileMBean = null;
  70     private static OperatingSystemImpl osMBean = null;
  71     private static FlightRecorderMXBeanImpl  flightRecorderMBean = null;
  72 
  73     public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
  74         if (classMBean == null) {
  75             classMBean = new ClassLoadingImpl(jvm);
  76         }
  77         return classMBean;
  78     }
  79 
  80     public static synchronized MemoryMXBean getMemoryMXBean() {
  81         if (memoryMBean == null) {
  82             memoryMBean = new MemoryImpl(jvm);
  83         }
  84         return memoryMBean;
  85     }
  86 
  87     public static synchronized ThreadMXBean getThreadMXBean() {
  88         if (threadMBean == null) {
  89             threadMBean = new ThreadImpl(jvm);
  90         }
  91         return threadMBean;


  93 
  94     public static synchronized RuntimeMXBean getRuntimeMXBean() {
  95         if (runtimeMBean == null) {
  96             runtimeMBean = new RuntimeImpl(jvm);
  97         }
  98         return runtimeMBean;
  99     }
 100 
 101     public static synchronized CompilationMXBean getCompilationMXBean() {
 102         if (compileMBean == null && jvm.getCompilerName() != null) {
 103             compileMBean = new CompilationImpl(jvm);
 104         }
 105         return compileMBean;
 106     }
 107 
 108     public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
 109         if (osMBean == null) {
 110             osMBean = new OperatingSystemImpl(jvm);
 111         }
 112         return osMBean;
 113     }
 114 
 115     public static synchronized FlightRecorderMXBean getFlightRecorderMXBean() {
 116         if (flightRecorderMBean == null) {
 117             flightRecorderMBean = new FlightRecorderMXBeanImpl();
 118         }
 119         return flightRecorderMBean;
 120     }
 121 
 122     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
 123         MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
 124         List<MemoryPoolMXBean> list = new ArrayList<>(pools.length);
 125         for (MemoryPoolMXBean p : pools) {
 126             list.add(p);
 127         }
 128         return list;
 129     }
 130 
 131     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
 132         MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
 133         List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length);
 134         for (MemoryManagerMXBean m : mgrs) {
 135             result.add(m);
 136         }
 137         return result;
 138     }
 139 


< prev index next >