From c66dc0fdc2bbc5fce0a309613f5c95552da6f804 Mon Sep 17 00:00:00 2001 From: mchung Date: Thu, 10 Apr 2008 10:47:13 -0700 Subject: [PATCH] 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031) Summary: Add new methods in ManagementFactory class to obtain platform MXBeans Reviewed-by: alanb, dfuchs, emcmanus --- .../management/HotSpotDiagnosticMXBean.java | 9 +- .../lang/management/ClassLoadingMXBean.java | 8 +- .../lang/management/CompilationMXBean.java | 6 +- .../management/GarbageCollectorMXBean.java | 4 + .../lang/management/ManagementFactory.java | 201 +++++++- .../java/lang/management/MemoryMXBean.java | 6 +- .../lang/management/MemoryManagerMXBean.java | 6 +- .../lang/management/MemoryPoolMXBean.java | 6 +- .../management/OperatingSystemMXBean.java | 6 +- .../lang/management/PlatformComponent.java | 382 ++++++++++++++ .../management/PlatformManagedObject.java | 61 +++ .../java/lang/management/RuntimeMXBean.java | 6 +- .../java/lang/management/ThreadInfo.java | 10 +- .../java/lang/management/ThreadMXBean.java | 6 +- .../classes/java/util/logging/Logging.java | 5 + .../java/util/logging/LoggingMXBean.java | 9 +- .../sun/management/ClassLoadingImpl.java | 8 +- .../sun/management/CompilationImpl.java | 9 +- .../sun/management/GarbageCollectorImpl.java | 5 + .../classes/sun/management/GcInfoBuilder.java | 2 +- .../sun/management/GcInfoCompositeData.java | 20 +- .../sun/management/HotSpotDiagnostic.java | 8 +- .../sun/management/HotspotCompilation.java | 2 +- .../sun/management/HotspotInternal.java | 9 +- .../sun/management/LockDataConverter.java | 8 +- .../sun/management/ManagementFactory.java | 467 +----------------- .../management/ManagementFactoryHelper.java | 340 +++++++++++++ .../sun/management/MappedMXBeanType.java | 14 +- .../classes/sun/management/MemoryImpl.java | 23 +- .../sun/management/MemoryManagerImpl.java | 7 + .../MemoryNotifInfoCompositeData.java | 4 +- .../sun/management/MemoryPoolImpl.java | 18 +- .../management/MemoryUsageCompositeData.java | 4 +- .../management/MonitorInfoCompositeData.java | 4 +- .../NotificationEmitterSupport.java | 2 +- .../sun/management/OperatingSystemImpl.java | 7 + .../classes/sun/management/RuntimeImpl.java | 11 +- .../StackTraceElementCompositeData.java | 4 +- .../classes/sun/management/ThreadImpl.java | 27 +- .../management/ThreadInfoCompositeData.java | 4 +- src/share/classes/sun/management/Util.java | 70 +-- .../sun/management/VMManagementImpl.java | 4 +- .../sun/management/VMOptionCompositeData.java | 4 +- .../HotSpotDiagnosticMXBean/DumpHeap.java | 6 +- .../GetDiagnosticOptions.java | 5 +- .../HotSpotDiagnosticMXBean/GetVMOption.java | 6 +- .../HotSpotDiagnosticMXBean/SetVMOption.java | 7 +- .../ManagementFactory/GetPlatformMXBeans.java | 180 +++++++ .../PlatformMXBeanTest.java | 69 +++ 49 files changed, 1479 insertions(+), 610 deletions(-) create mode 100644 src/share/classes/java/lang/management/PlatformComponent.java create mode 100644 src/share/classes/java/lang/management/PlatformManagedObject.java create mode 100644 src/share/classes/sun/management/ManagementFactoryHelper.java create mode 100644 test/java/lang/management/ManagementFactory/GetPlatformMXBeans.java create mode 100644 test/java/lang/management/OperatingSystemMXBean/PlatformMXBeanTest.java diff --git a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java index 45c1b55a8..f736dc500 100644 --- a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java +++ b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java @@ -25,6 +25,8 @@ package com.sun.management; +import java.lang.management.PlatformManagedObject; + /** * Diagnostic management interface for the HotSpot Virtual Machine. * The diagnostic MBean is registered to the platform MBeanServer @@ -35,8 +37,13 @@ package com.sun.management; *
* com.sun.management:type=HotSpotDiagnostic *
+.* + * It can be obtained by calling the + * {@link PlatformManagedObject#getObjectName} method. + * + * @see ManagementFactory#getPlatformMXBeans(Class) */ -public interface HotSpotDiagnosticMXBean { +public interface HotSpotDiagnosticMXBean extends PlatformManagedObject { /** * Dumps the heap to the outputFile file in the same * format as the hprof heap dump. diff --git a/src/share/classes/java/lang/management/ClassLoadingMXBean.java b/src/share/classes/java/lang/management/ClassLoadingMXBean.java index 62f31e487..762e14cb2 100644 --- a/src/share/classes/java/lang/management/ClassLoadingMXBean.java +++ b/src/share/classes/java/lang/management/ClassLoadingMXBean.java @@ -35,7 +35,7 @@ package java.lang.management; * that can be obtained by calling * the {@link ManagementFactory#getClassLoadingMXBean} method or * from the {@link ManagementFactory#getPlatformMBeanServer - * platform MBeanServer} method. + * platform MBeanServer}. * *

The ObjectName for uniquely identifying the MXBean for * the class loading system within an MBeanServer is: @@ -44,6 +44,10 @@ package java.lang.management; * java.lang:type=ClassLoading} * * + * It can be obtained by calling the + * {@link PlatformManagedObject#getObjectName} method. + * + * @see ManagementFactory#getPlatformMXBeans(Class) * @see * JMX Specification. * @see @@ -52,7 +56,7 @@ package java.lang.management; * @author Mandy Chung * @since 1.5 */ -public interface ClassLoadingMXBean { +public interface ClassLoadingMXBean extends PlatformManagedObject { /** * Returns the total number of classes that have been loaded since diff --git a/src/share/classes/java/lang/management/CompilationMXBean.java b/src/share/classes/java/lang/management/CompilationMXBean.java index 94f97bb45..ea93a2b0c 100644 --- a/src/share/classes/java/lang/management/CompilationMXBean.java +++ b/src/share/classes/java/lang/management/CompilationMXBean.java @@ -44,6 +44,10 @@ package java.lang.management; * java.lang:type=Compilation} * * + * It can be obtained by calling the + * {@link PlatformManagedObject#getObjectName} method. + * + * @see ManagementFactory#getPlatformMXBeans(Class) * @see * JMX Specification. * @see @@ -52,7 +56,7 @@ package java.lang.management; * @author Mandy Chung * @since 1.5 */ -public interface CompilationMXBean { +public interface CompilationMXBean extends PlatformManagedObject { /** * Returns the name of the Just-in-time (JIT) compiler. * diff --git a/src/share/classes/java/lang/management/GarbageCollectorMXBean.java b/src/share/classes/java/lang/management/GarbageCollectorMXBean.java index f737a9c2e..50ee93d8d 100644 --- a/src/share/classes/java/lang/management/GarbageCollectorMXBean.java +++ b/src/share/classes/java/lang/management/GarbageCollectorMXBean.java @@ -48,9 +48,13 @@ package java.lang.management; * java.lang:type=GarbageCollector},name=collector's name * * + * It can be obtained by calling the + * {@link PlatformManagedObject#getObjectName} method. + * * A platform usually includes additional platform-dependent information * specific to a garbage collection algorithm for monitoring. * + * @see ManagementFactory#getPlatformMXBeans(Class) * @see MemoryMXBean * * @see diff --git a/src/share/classes/java/lang/management/ManagementFactory.java b/src/share/classes/java/lang/management/ManagementFactory.java index dff4f19a4..c9e12708e 100644 --- a/src/share/classes/java/lang/management/ManagementFactory.java +++ b/src/share/classes/java/lang/management/ManagementFactory.java @@ -24,17 +24,31 @@ */ package java.lang.management; +import javax.management.DynamicMBean; import javax.management.MBeanServer; import javax.management.MBeanServerConnection; +import javax.management.MBeanServerFactory; import javax.management.MBeanServerPermission; +import javax.management.NotificationEmitter; +import javax.management.ObjectInstance; import javax.management.ObjectName; +import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.MalformedObjectNameException; +import javax.management.MBeanRegistrationException; +import javax.management.NotCompliantMBeanException; +import javax.management.StandardEmitterMBean; +import javax.management.StandardMBean; +import java.util.Collections; +import java.util.ArrayList; import java.util.List; import java.security.AccessController; import java.security.Permission; import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import javax.management.JMX; +import sun.management.ManagementFactoryHelper; /** * The ManagementFactory class is a factory class for getting @@ -49,13 +63,16 @@ import javax.management.JMX; *