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 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method;
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 jdk.internal.access.JavaNioAccess;
43 import jdk.internal.access.SharedSecrets;
44
45 import java.util.ArrayList;
46 import java.util.List;
47
48 import java.lang.reflect.UndeclaredThrowableException;
49 import java.security.PrivilegedAction;
50 import java.util.Arrays;
51 import java.util.Collections;
52 import java.util.HashMap;
53 import java.util.Map;
54 import java.util.Optional;
55
56 /**
57 * ManagementFactoryHelper provides static factory methods to create
58 * instances of the management interface.
59 */
60 public class ManagementFactoryHelper {
61 static {
62 // make sure that the management lib is loaded within
63 // java.lang.management.ManagementFactory
323 @Override
324 public void setLoggerLevel(String loggerName, String levelName) {
325 loggingAccess.invoke("setLoggerLevel", loggerName, levelName);
326 }
327
328 @Override
329 public String getParentLoggerName(String loggerName) {
330 return loggingAccess.invoke("getParentLoggerName", loggerName);
331 }
332
333 private static PlatformLoggingImpl getInstance() {
334 return new PlatformLoggingImpl(new LoggingMXBeanAccess());
335 }
336
337 static final PlatformLoggingMXBean MBEAN = getInstance();
338 }
339
340 private static List<BufferPoolMXBean> bufferPools = null;
341 public static synchronized List<BufferPoolMXBean> getBufferPoolMXBeans() {
342 if (bufferPools == null) {
343 bufferPools = new ArrayList<>(2);
344 bufferPools.add(createBufferPoolMXBean(SharedSecrets.getJavaNioAccess()
345 .getDirectBufferPool()));
346 bufferPools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl
347 .getMappedBufferPool()));
348 bufferPools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl
349 .getSyncMappedBufferPool()));
350 }
351 return bufferPools;
352 }
353
354 private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool";
355
356 /**
357 * Creates management interface for the given buffer pool.
358 */
359 private static BufferPoolMXBean
360 createBufferPoolMXBean(final JavaNioAccess.BufferPool pool)
361 {
362 return new BufferPoolMXBean() {
363 private volatile ObjectName objname; // created lazily
364 @Override
365 public ObjectName getObjectName() {
366 ObjectName result = objname;
367 if (result == null) {
368 synchronized (this) {
369 result = objname;
370 if (result == null) {
371 result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME +
372 ",name=" + pool.getName());
373 objname = result;
374 }
375 }
376 }
377 return result;
378 }
379 @Override
380 public String getName() {
|
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 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method;
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 jdk.internal.access.SharedSecrets;
43 import jdk.internal.misc.VM;
44 import jdk.internal.misc.VM.BufferPool;
45
46 import java.util.ArrayList;
47 import java.util.List;
48
49 import java.lang.reflect.UndeclaredThrowableException;
50 import java.security.PrivilegedAction;
51 import java.util.Arrays;
52 import java.util.Collections;
53 import java.util.HashMap;
54 import java.util.Map;
55 import java.util.Optional;
56
57 /**
58 * ManagementFactoryHelper provides static factory methods to create
59 * instances of the management interface.
60 */
61 public class ManagementFactoryHelper {
62 static {
63 // make sure that the management lib is loaded within
64 // java.lang.management.ManagementFactory
324 @Override
325 public void setLoggerLevel(String loggerName, String levelName) {
326 loggingAccess.invoke("setLoggerLevel", loggerName, levelName);
327 }
328
329 @Override
330 public String getParentLoggerName(String loggerName) {
331 return loggingAccess.invoke("getParentLoggerName", loggerName);
332 }
333
334 private static PlatformLoggingImpl getInstance() {
335 return new PlatformLoggingImpl(new LoggingMXBeanAccess());
336 }
337
338 static final PlatformLoggingMXBean MBEAN = getInstance();
339 }
340
341 private static List<BufferPoolMXBean> bufferPools = null;
342 public static synchronized List<BufferPoolMXBean> getBufferPoolMXBeans() {
343 if (bufferPools == null) {
344 bufferPools = new ArrayList<>(3);
345 VM.getBufferPools().forEach(pool -> bufferPools.add(createBufferPoolMXBean(pool)));
346 }
347 return bufferPools;
348 }
349
350 private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool";
351
352 /**
353 * Creates management interface for the given buffer pool.
354 */
355 private static BufferPoolMXBean
356 createBufferPoolMXBean(final BufferPool pool)
357 {
358 return new BufferPoolMXBean() {
359 private volatile ObjectName objname; // created lazily
360 @Override
361 public ObjectName getObjectName() {
362 ObjectName result = objname;
363 if (result == null) {
364 synchronized (this) {
365 result = objname;
366 if (result == null) {
367 result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME +
368 ",name=" + pool.getName());
369 objname = result;
370 }
371 }
372 }
373 return result;
374 }
375 @Override
376 public String getName() {
|