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 23 * questions. 24 */ 25 26 package sun.management; 27 28 import java.lang.management.*; 29 30 import javax.management.MBeanServer; 31 import javax.management.ObjectName; 32 import javax.management.InstanceAlreadyExistsException; 33 import javax.management.InstanceNotFoundException; 34 import javax.management.MBeanRegistrationException; 35 import javax.management.NotCompliantMBeanException; 36 import javax.management.RuntimeOperationsException; 37 import java.nio.BufferPoolMXBean; 38 import java.security.AccessController; 39 import java.security.PrivilegedActionException; 40 import java.security.PrivilegedExceptionAction; 41 import sun.security.action.LoadLibraryAction; 42 43 import java.util.logging.PlatformLoggingMXBean; 44 import sun.util.logging.LoggingSupport; 45 46 import java.util.ArrayList; 47 import java.util.Collections; 48 import java.util.List; 49 import com.sun.management.OSMBeanFactory; 50 import com.sun.management.HotSpotDiagnosticMXBean; 51 52 import static java.lang.management.ManagementFactory.*; 53 54 /** 55 * ManagementFactoryHelper provides static factory methods to create 56 * instances of the management interface. 57 */ 58 public class ManagementFactoryHelper { 59 private ManagementFactoryHelper() {}; 60 61 private static VMManagement jvm; 62 63 private static ClassLoadingImpl classMBean = null; 122 public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() { 123 MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); 124 List<MemoryManagerMXBean> result = new ArrayList<MemoryManagerMXBean>(mgrs.length); 125 for (MemoryManagerMXBean m : mgrs) { 126 result.add(m); 127 } 128 return result; 129 } 130 131 public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() { 132 MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); 133 List<GarbageCollectorMXBean> result = new ArrayList<GarbageCollectorMXBean>(mgrs.length); 134 for (MemoryManagerMXBean m : mgrs) { 135 if (GarbageCollectorMXBean.class.isInstance(m)) { 136 result.add(GarbageCollectorMXBean.class.cast(m)); 137 } 138 } 139 return result; 140 } 141 142 public static List<PlatformLoggingMXBean> getLoggingMXBean() { 143 if (LoggingSupport.isAvailable()) { 144 return Collections.singletonList(createPlatformLoggingMXBean()); 145 } else { 146 return Collections.emptyList(); 147 } 148 } 149 150 private final static String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; 151 private static PlatformLoggingMXBean createPlatformLoggingMXBean() { 152 return new PlatformLoggingMXBean() { 153 private volatile ObjectName objname; // created lazily 154 @Override 155 public ObjectName getObjectName() { 156 ObjectName result = objname; 157 if (result == null) { 158 synchronized (this) { 159 if (objname == null) { 160 result = Util.newObjectName(LOGGING_MXBEAN_NAME); 161 objname = result; 162 } 163 } 164 } 165 return result; 166 } 167 168 @Override 169 public java.util.List<String> getLoggerNames() { 170 return LoggingSupport.getLoggerNames(); 171 } 172 173 @Override 174 public String getLoggerLevel(String loggerName) { 175 return LoggingSupport.getLoggerLevel(loggerName); 176 } 177 178 @Override 179 public void setLoggerLevel(String loggerName, String levelName) { 180 LoggingSupport.setLoggerLevel(loggerName, levelName); 181 } 182 183 @Override 184 public String getParentLoggerName(String loggerName) { 185 return LoggingSupport.getParentLoggerName(loggerName); 186 } 187 }; 188 } 189 190 public static List<BufferPoolMXBean> getBufferPoolMXBeans() { 191 List<BufferPoolMXBean> pools = new ArrayList<BufferPoolMXBean>(2); 192 pools.add(createBufferPoolMXBean(sun.misc.SharedSecrets.getJavaNioAccess() 193 .getDirectBufferPool())); 194 pools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl 195 .getMappedBufferPool())); 196 return pools; 197 } 198 199 private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool"; 200 201 /** 202 * Creates management interface for the given buffer pool. 203 */ 204 private static BufferPoolMXBean 205 createBufferPoolMXBean(final sun.misc.JavaNioAccess.BufferPool pool) 206 { 207 return new BufferPoolMXBean() { 208 private volatile ObjectName objname; // created lazily 209 @Override 210 public ObjectName getObjectName() { 211 ObjectName result = objname; 212 if (result == null) { 213 synchronized (this) { 214 if (objname == null) { 215 result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME + 216 ",name=" + pool.getName()); 217 objname = result; | 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 23 * questions. 24 */ 25 26 package sun.management; 27 28 import java.lang.management.*; 29 30 import javax.management.InstanceAlreadyExistsException; 31 import javax.management.InstanceNotFoundException; 32 import javax.management.MBeanServer; 33 import javax.management.MBeanRegistrationException; 34 import javax.management.NotCompliantMBeanException; 35 import javax.management.ObjectName; 36 import javax.management.RuntimeOperationsException; 37 import java.security.AccessController; 38 import java.security.PrivilegedActionException; 39 import java.security.PrivilegedExceptionAction; 40 import sun.security.action.LoadLibraryAction; 41 42 import sun.util.logging.LoggingSupport; 43 44 import java.util.ArrayList; 45 import java.util.Collections; 46 import java.util.List; 47 import com.sun.management.OSMBeanFactory; 48 import com.sun.management.HotSpotDiagnosticMXBean; 49 50 import static java.lang.management.ManagementFactory.*; 51 52 /** 53 * ManagementFactoryHelper provides static factory methods to create 54 * instances of the management interface. 55 */ 56 public class ManagementFactoryHelper { 57 private ManagementFactoryHelper() {}; 58 59 private static VMManagement jvm; 60 61 private static ClassLoadingImpl classMBean = null; 120 public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() { 121 MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); 122 List<MemoryManagerMXBean> result = new ArrayList<MemoryManagerMXBean>(mgrs.length); 123 for (MemoryManagerMXBean m : mgrs) { 124 result.add(m); 125 } 126 return result; 127 } 128 129 public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() { 130 MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); 131 List<GarbageCollectorMXBean> result = new ArrayList<GarbageCollectorMXBean>(mgrs.length); 132 for (MemoryManagerMXBean m : mgrs) { 133 if (GarbageCollectorMXBean.class.isInstance(m)) { 134 result.add(GarbageCollectorMXBean.class.cast(m)); 135 } 136 } 137 return result; 138 } 139 140 public static PlatformLoggingMXBean getPlatformLoggingMXBean() { 141 if (LoggingSupport.isAvailable()) { 142 return PlatformLoggingImpl.instance; 143 } else { 144 return null; 145 } 146 } 147 148 interface LoggingMXBean 149 extends PlatformLoggingMXBean, java.util.logging.LoggingMXBean { 150 } 151 152 static class PlatformLoggingImpl implements LoggingMXBean 153 { 154 final static PlatformLoggingMXBean instance = new PlatformLoggingImpl(); 155 final static String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; 156 157 private volatile ObjectName objname; // created lazily 158 @Override 159 public ObjectName getObjectName() { 160 ObjectName result = objname; 161 if (result == null) { 162 synchronized (this) { 163 if (objname == null) { 164 result = Util.newObjectName(LOGGING_MXBEAN_NAME); 165 objname = result; 166 } 167 } 168 } 169 return result; 170 } 171 172 @Override 173 public java.util.List<String> getLoggerNames() { 174 return LoggingSupport.getLoggerNames(); 175 } 176 177 @Override 178 public String getLoggerLevel(String loggerName) { 179 return LoggingSupport.getLoggerLevel(loggerName); 180 } 181 182 @Override 183 public void setLoggerLevel(String loggerName, String levelName) { 184 LoggingSupport.setLoggerLevel(loggerName, levelName); 185 } 186 187 @Override 188 public String getParentLoggerName(String loggerName) { 189 return LoggingSupport.getParentLoggerName(loggerName); 190 } 191 } 192 193 private static List<BufferPoolMXBean> bufferPools = null; 194 public static synchronized List<BufferPoolMXBean> getBufferPoolMXBeans() { 195 if (bufferPools == null) { 196 bufferPools = new ArrayList<>(2); 197 bufferPools.add(createBufferPoolMXBean(sun.misc.SharedSecrets.getJavaNioAccess() 198 .getDirectBufferPool())); 199 bufferPools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl 200 .getMappedBufferPool())); 201 } 202 return bufferPools; 203 } 204 205 private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool"; 206 207 /** 208 * Creates management interface for the given buffer pool. 209 */ 210 private static BufferPoolMXBean 211 createBufferPoolMXBean(final sun.misc.JavaNioAccess.BufferPool pool) 212 { 213 return new BufferPoolMXBean() { 214 private volatile ObjectName objname; // created lazily 215 @Override 216 public ObjectName getObjectName() { 217 ObjectName result = objname; 218 if (result == null) { 219 synchronized (this) { 220 if (objname == null) { 221 result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME + 222 ",name=" + pool.getName()); 223 objname = result; |