6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
authormchung
Thu, 10 Apr 2008 10:47:13 -0700
changeset 401 ef01e0dccd63
parent 399 bcc2354430ff
child 402 24efa1293da7
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
jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java
jdk/src/share/classes/java/lang/management/ClassLoadingMXBean.java
jdk/src/share/classes/java/lang/management/CompilationMXBean.java
jdk/src/share/classes/java/lang/management/GarbageCollectorMXBean.java
jdk/src/share/classes/java/lang/management/ManagementFactory.java
jdk/src/share/classes/java/lang/management/MemoryMXBean.java
jdk/src/share/classes/java/lang/management/MemoryManagerMXBean.java
jdk/src/share/classes/java/lang/management/MemoryPoolMXBean.java
jdk/src/share/classes/java/lang/management/OperatingSystemMXBean.java
jdk/src/share/classes/java/lang/management/PlatformComponent.java
jdk/src/share/classes/java/lang/management/PlatformManagedObject.java
jdk/src/share/classes/java/lang/management/RuntimeMXBean.java
jdk/src/share/classes/java/lang/management/ThreadInfo.java
jdk/src/share/classes/java/lang/management/ThreadMXBean.java
jdk/src/share/classes/java/util/logging/Logging.java
jdk/src/share/classes/java/util/logging/LoggingMXBean.java
jdk/src/share/classes/sun/management/ClassLoadingImpl.java
jdk/src/share/classes/sun/management/CompilationImpl.java
jdk/src/share/classes/sun/management/GarbageCollectorImpl.java
jdk/src/share/classes/sun/management/GcInfoBuilder.java
jdk/src/share/classes/sun/management/GcInfoCompositeData.java
jdk/src/share/classes/sun/management/HotSpotDiagnostic.java
jdk/src/share/classes/sun/management/HotspotCompilation.java
jdk/src/share/classes/sun/management/HotspotInternal.java
jdk/src/share/classes/sun/management/LockDataConverter.java
jdk/src/share/classes/sun/management/ManagementFactory.java
jdk/src/share/classes/sun/management/ManagementFactoryHelper.java
jdk/src/share/classes/sun/management/MappedMXBeanType.java
jdk/src/share/classes/sun/management/MemoryImpl.java
jdk/src/share/classes/sun/management/MemoryManagerImpl.java
jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java
jdk/src/share/classes/sun/management/MemoryPoolImpl.java
jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java
jdk/src/share/classes/sun/management/MonitorInfoCompositeData.java
jdk/src/share/classes/sun/management/NotificationEmitterSupport.java
jdk/src/share/classes/sun/management/OperatingSystemImpl.java
jdk/src/share/classes/sun/management/RuntimeImpl.java
jdk/src/share/classes/sun/management/StackTraceElementCompositeData.java
jdk/src/share/classes/sun/management/ThreadImpl.java
jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java
jdk/src/share/classes/sun/management/Util.java
jdk/src/share/classes/sun/management/VMManagementImpl.java
jdk/src/share/classes/sun/management/VMOptionCompositeData.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticOptions.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java
jdk/test/java/lang/management/ManagementFactory/GetPlatformMXBeans.java
jdk/test/java/lang/management/OperatingSystemMXBean/PlatformMXBeanTest.java
--- a/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -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 @@
  * <blockquote>
  *    <tt>com.sun.management:type=HotSpotDiagnostic</tt>
  * </blockquote>
+.*
+ * 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 <tt>outputFile</tt> file in the same
      * format as the hprof heap dump.
--- a/jdk/src/share/classes/java/lang/management/ClassLoadingMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/ClassLoadingMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -35,7 +35,7 @@
  * that can be obtained by calling
  * the {@link ManagementFactory#getClassLoadingMXBean} method or
  * from the {@link ManagementFactory#getPlatformMBeanServer
- * platform <tt>MBeanServer</tt>} method.
+ * platform <tt>MBeanServer</tt>}.
  *
  * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
  * the class loading system within an <tt>MBeanServer</tt> is:
@@ -44,6 +44,10 @@
  *        <tt>java.lang:type=ClassLoading</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -52,7 +56,7 @@
  * @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
--- a/jdk/src/share/classes/java/lang/management/CompilationMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/CompilationMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -44,6 +44,10 @@
  *         <tt>java.lang:type=Compilation</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -52,7 +56,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface CompilationMXBean {
+public interface CompilationMXBean extends PlatformManagedObject {
     /**
      * Returns the name of the Just-in-time (JIT) compiler.
      *
--- a/jdk/src/share/classes/java/lang/management/GarbageCollectorMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/GarbageCollectorMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -48,9 +48,13 @@
  *    <tt>java.lang:type=GarbageCollector</tt>}<tt>,name=</tt><i>collector's name</i>
  * </blockquote>
  *
+ * 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 <a href="../../../javax/management/package-summary.html">
--- a/jdk/src/share/classes/java/lang/management/ManagementFactory.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/ManagementFactory.java	Thu Apr 10 10:47:13 2008 -0700
@@ -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 <tt>ManagementFactory</tt> class is a factory class for getting
@@ -49,13 +63,16 @@
  * <ul>
  * <li><i>Direct access to an MXBean interface</i>
  *     <ol type="a">
- *     <li>Get the MXBean instance through the static factory method
+ *     <li>Get the MXBean instance through the static factory method,
+ *         or the {@link #getPlatformMXBeans(Class)} method
  *         and access the MXBean locally of the running
  *         virtual machine.
  *         </li>
  *     <li>Construct an MXBean proxy instance that forwards the
  *         method calls to a given {@link MBeanServer MBeanServer} by calling
- *         {@link #newPlatformMXBeanProxy newPlatfromMXBeanProxy}.
+ *         the {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method
+ *         or the {@link #getPlatformMXBeans(MBeanServerConnection, Class)}
+ *         method.
  *         A proxy is typically constructed to remotely access
  *         an MXBean of another running virtual machine.
  *         </li>
@@ -83,6 +100,10 @@
  * a set of basic data types described below.
  * See <a href="../../../javax/management/MXBean.html#MXBean-spec">
  * the specification of MXBeans</a> for details.
+ * All platform MXBean interfaces extend {@link PlatformManagedObject}s
+ * and new methods may be added in these interfaces
+ * in future Java SE releases.
+ * <p>
  * A JMX management application and the platform <tt>MBeanServer</tt>
  * can interoperate without requiring classes for MXBean specific
  * data types.
@@ -191,7 +212,10 @@
  * <h4><a name="MXBeanNames">MXBean Names</a></h4>
  * Each platform MXBean for a Java virtual machine has a unique
  * {@link javax.management.ObjectName ObjectName} for
- * registration in the platform <tt>MBeanServer</tt>.
+ * registration in the platform <tt>MBeanServer</tt> that can
+ * be obtained by calling the {@link PlatformManagedObject#getObjectName}
+ * method.
+ *
  * A Java virtual machine has a single instance of the following management
  * interfaces:
  *
@@ -275,7 +299,7 @@
  * </blockquote>
  *
  * @see <a href="../../../javax/management/package-summary.html">
- *      JMX Specification.</a>
+ *      JMX Specification</a>
  * @see <a href="package-summary.html#examples">
  *      Ways to Access Management Metrics</a>
  * @see java.util.logging.LoggingMXBean
@@ -368,7 +392,7 @@
      * the Java virtual machine.
      */
     public static ClassLoadingMXBean getClassLoadingMXBean() {
-        return sun.management.ManagementFactory.getClassLoadingMXBean();
+        return ManagementFactoryHelper.getClassLoadingMXBean();
     }
 
     /**
@@ -378,7 +402,7 @@
      * @return a {@link MemoryMXBean} object for the Java virtual machine.
      */
     public static MemoryMXBean getMemoryMXBean() {
-        return sun.management.ManagementFactory.getMemoryMXBean();
+        return ManagementFactoryHelper.getMemoryMXBean();
     }
 
     /**
@@ -388,7 +412,7 @@
      * @return a {@link ThreadMXBean} object for the Java virtual machine.
      */
     public static ThreadMXBean getThreadMXBean() {
-        return sun.management.ManagementFactory.getThreadMXBean();
+        return ManagementFactoryHelper.getThreadMXBean();
     }
 
     /**
@@ -399,7 +423,7 @@
 
      */
     public static RuntimeMXBean getRuntimeMXBean() {
-        return sun.management.ManagementFactory.getRuntimeMXBean();
+        return ManagementFactoryHelper.getRuntimeMXBean();
     }
 
     /**
@@ -412,7 +436,7 @@
      *   no compilation system.
      */
     public static CompilationMXBean getCompilationMXBean() {
-        return sun.management.ManagementFactory.getCompilationMXBean();
+        return ManagementFactoryHelper.getCompilationMXBean();
     }
 
     /**
@@ -423,7 +447,7 @@
      * the Java virtual machine.
      */
     public static OperatingSystemMXBean getOperatingSystemMXBean() {
-        return sun.management.ManagementFactory.getOperatingSystemMXBean();
+        return ManagementFactoryHelper.getOperatingSystemMXBean();
     }
 
     /**
@@ -436,7 +460,7 @@
      *
      */
     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
-        return sun.management.ManagementFactory.getMemoryPoolMXBeans();
+        return ManagementFactoryHelper.getMemoryPoolMXBeans();
     }
 
     /**
@@ -449,7 +473,7 @@
      *
      */
     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
-        return sun.management.ManagementFactory.getMemoryManagerMXBeans();
+        return ManagementFactoryHelper.getMemoryManagerMXBeans();
     }
 
 
@@ -465,7 +489,7 @@
      *
      */
     public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
-        return sun.management.ManagementFactory.getGarbageCollectorMXBeans();
+        return ManagementFactoryHelper.getGarbageCollectorMXBeans();
     }
 
     private static MBeanServer platformMBeanServer;
@@ -518,8 +542,25 @@
         }
 
         if (platformMBeanServer == null) {
-            platformMBeanServer =
-                sun.management.ManagementFactory.createPlatformMBeanServer();
+            platformMBeanServer = MBeanServerFactory.createMBeanServer();
+            for (PlatformComponent pc : PlatformComponent.values()) {
+                List<? extends PlatformManagedObject> list =
+                    pc.getMXBeans(pc.getMXBeanInterface());
+                for (PlatformManagedObject o : list) {
+                    // Each PlatformComponent represents one management
+                    // interface. Some MXBean may extend another one.
+                    // The MXBean instances for one platform component
+                    // (returned by pc.getMXBeans()) might be also
+                    // the MXBean instances for another platform component.
+                    // e.g. com.sun.management.GarbageCollectorMXBean
+                    //
+                    // So need to check if an MXBean instance is registered
+                    // before registering into the platform MBeanServer
+                    if (!platformMBeanServer.isRegistered(o.getObjectName())) {
+                        addMXBean(platformMBeanServer, o);
+                    }
+                }
+            }
         }
         return platformMBeanServer;
     }
@@ -657,6 +698,136 @@
         }
     }
 
+    /**
+     * Returns the list of platform MXBeans that implement
+     * the given {@code mxbeanInterface} in the running Java
+     * virtual machine.
+     * The returned list may contain zero, one, or more instances.
+     * The number of instances in the returned list is defined
+     * in the specification of the given management interface.
+     *
+     * @param mxbeanInterface a management interface for a platform
+     *                        MXBean
+     *
+     * @return the list of platform MXBeans that implements
+     * {@code mxbeanInterface}.
+     *
+     * @throws IllegalArgumentException if {@code mxbeanInterface}
+     * is not a management interface for the platform.
+     *
+     * @since 1.7
+     */
+    public static <T extends PlatformManagedObject> List<T>
+            getPlatformMXBeans(Class<T> mxbeanInterface) {
+        String className = mxbeanInterface.getName();
+        for (PlatformComponent component: PlatformComponent.values()) {
+            // comparing the class name first instead of the Class instance
+            // to avoid causing unnecessary class loading of
+            // the other MXBean interfaces
+            if (className.equals(component.getMXBeanInterfaceName())) {
+                if (component.getMXBeanInterface() == mxbeanInterface) {
+                    return component.getMXBeans(mxbeanInterface);
+                }
+            }
+        }
+        throw new IllegalArgumentException(mxbeanInterface.getName() +
+            " is not implemented by any of the platform MXBeans.");
+    }
+
+    /**
+     * Returns the list of the platform MXBean proxies for
+     * forwarding the method calls of the {@code mxbeanInterface}
+     * through the given {@code MBeanServerConnection}.
+     * The returned list may contain zero, one, or more instances.
+     * The number of instances in the returned list is defined
+     * in the specification of the given management interface.
+     *
+     * @param connection the {@code MBeanServerConnection} to forward to.
+     * @param mxbeanInterface a management interface for a platform
+     *                        MXBean
+     *
+     * @return the list of platform MXBean proxies for
+     * forwarding the method calls of the {@code mxbeanInterface}
+     * through the given {@code MBeanServerConnection}.
+     *
+     * @throws IllegalArgumentException if {@code mxbeanInterface}
+     * is not a management interface for the platform.
+     *
+     * @throws java.io.IOException if a communication problem
+     * occurred when accessing the {@code MBeanServerConnection}.
+     *
+     * @since 1.7
+     */
+    public static <T extends PlatformManagedObject>
+        List<T> getPlatformMXBeans(MBeanServerConnection connection,
+                                   Class<T> mxbeanInterface)
+        throws java.io.IOException
+    {
+        String className = mxbeanInterface.getName();
+        for (PlatformComponent component: PlatformComponent.values()) {
+            // comparing the class name first instead of the Class instance
+            // to avoid causing unnecessary class loading of
+            // the other MXBean interfaces
+            if (className.equals(component.getMXBeanInterfaceName())) {
+                if (component.getMXBeanInterface() == mxbeanInterface) {
+                    return component.getMXBeans(connection,
+                                                mxbeanInterface);
+                }
+            }
+        }
+        throw new IllegalArgumentException(mxbeanInterface.getName() +
+            " is not implemented by any of the platform MXBeans.");
+    }
+
+    /**
+     * Returns a list of {@code Class} objects, subinterface of
+     * {@link PlatformManagedObject}, representing
+     * all management interfaces for
+     * monitoring and managing the Java platform.
+     *
+     * @return a list of {@code Class} objects, subinterface of
+     * {@link PlatformManagedObject} representing
+     * the management interfaces for
+     * monitoring and managing the Java platform.
+     *
+     * @since 1.7
+     */
+    public static List<Class<? extends PlatformManagedObject>> getAllPlatformMXBeanInterfaces() {
+        List<Class<? extends PlatformManagedObject>> result =
+            new ArrayList<Class<? extends PlatformManagedObject>>();
+        for (PlatformComponent component: PlatformComponent.values()) {
+            result.add(component.getMXBeanInterface());
+        }
+        return result;
+    }
+
     private static final String NOTIF_EMITTER =
         "javax.management.NotificationEmitter";
+
+    /**
+     * Registers an MXBean.
+     */
+    private static void addMXBean(final MBeanServer mbs, final PlatformManagedObject pmo) {
+        // Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
+        final DynamicMBean dmbean;
+        if (pmo instanceof NotificationEmitter) {
+            dmbean = new StandardEmitterMBean(pmo, null, true, (NotificationEmitter) pmo);
+        } else {
+            dmbean = new StandardMBean(pmo, null, true);
+        }
+
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
+                public Void run() throws InstanceAlreadyExistsException,
+                                         MBeanRegistrationException,
+                                         NotCompliantMBeanException {
+                    mbs.registerMBean(dmbean, pmo.getObjectName());
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw new RuntimeException(e.getException());
+        }
+    }
+
 }
--- a/jdk/src/share/classes/java/lang/management/MemoryMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/MemoryMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -46,6 +46,9 @@
  *           <tt>java.lang:type=Memory</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
  * <h4> Memory </h4>
  * The memory system of the Java virtual machine manages
  * the following kinds of memory:
@@ -190,6 +193,7 @@
  * emitter.addNotificationListener(listener, null, null);
  * </pre></blockquote>
  *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -198,7 +202,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface MemoryMXBean {
+public interface MemoryMXBean extends PlatformManagedObject {
     /**
      * Returns the approximate number of objects for which
      * finalization is pending.
--- a/jdk/src/share/classes/java/lang/management/MemoryManagerMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/MemoryManagerMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -45,6 +45,10 @@
  *    <tt>java.lang:type=MemoryManager</tt>}<tt>,name=</tt><i>manager's name</i>
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see MemoryMXBean
  *
  * @see <a href="../../../javax/management/package-summary.html">
@@ -55,7 +59,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface MemoryManagerMXBean {
+public interface MemoryManagerMXBean extends PlatformManagedObject {
     /**
      * Returns the name representing this memory manager.
      *
--- a/jdk/src/share/classes/java/lang/management/MemoryPoolMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/MemoryPoolMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -46,6 +46,9 @@
  *    <tt>java.lang:type=MemoryPool</tt>}<tt>,name=</tt><i>pool's name</i>
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
  * <h4>Memory Type</h4>
  * <p>The Java virtual machine has a heap for object allocation and also
  * maintains non-heap memory for the method area and the Java virtual
@@ -349,6 +352,7 @@
  * described above for the <a href="#UsageThreshold">usage threshold</a>
  * in a similar fashion.
  *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -357,7 +361,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface MemoryPoolMXBean {
+public interface MemoryPoolMXBean extends PlatformManagedObject {
     /**
      * Returns the name representing this memory pool.
      *
--- a/jdk/src/share/classes/java/lang/management/OperatingSystemMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/OperatingSystemMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -44,10 +44,14 @@
  *      <tt>java.lang:type=OperatingSystem</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
  * <p> This interface defines several convenient methods for accessing
  * system properties about the operating system on which the Java
  * virtual machine is running.
  *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -56,7 +60,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface OperatingSystemMXBean {
+public interface OperatingSystemMXBean extends PlatformManagedObject {
     /**
      * Returns the operating system name.
      * This method is equivalent to <tt>System.getProperty("os.name")</tt>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/lang/management/PlatformComponent.java	Thu Apr 10 10:47:13 2008 -0700
@@ -0,0 +1,382 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.lang.management;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.LoggingMXBean;
+import java.util.logging.LogManager;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import com.sun.management.HotSpotDiagnosticMXBean;
+import com.sun.management.UnixOperatingSystemMXBean;
+
+import sun.management.ManagementFactoryHelper;
+
+/**
+ * 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.
+ *
+ * For example, com.sun.management.GarbageCollectorMXBean
+ * extends java.lang.management.GarbageCollectorMXBean
+ * and there is one set of garbage collection MXBean instances,
+ * each of which implements both c.s.m. and j.l.m. interfaces.
+ * There are two separate enums GARBAGE_COLLECTOR
+ * and SUN_GARBAGE_COLLECTOR so that ManagementFactory.getPlatformMXBeans(Class)
+ * will return the list of MXBeans of the specified type.
+ *
+ * To add a new MXBean interface for the Java platform,
+ * add a new enum constant and implement the MXBeanFetcher.
+ */
+enum PlatformComponent {
+
+    /**
+     * Class loading system of the Java virtual machine.
+     */
+    CLASS_LOADING(
+        "java.lang.management.ClassLoadingMXBean",
+        "java.lang", "ClassLoading", defaultKeyProperties(),
+        new MXBeanFetcher<ClassLoadingMXBean>() {
+            public List<ClassLoadingMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getClassLoadingMXBean());
+            }
+        }),
+
+    /**
+     * Compilation system of the Java virtual machine.
+     */
+    COMPILATION(
+        "java.lang.management.CompilationMXBean",
+        "java.lang", "Compilation", defaultKeyProperties(),
+        new MXBeanFetcher<CompilationMXBean>() {
+            public List<CompilationMXBean> getMXBeans() {
+                CompilationMXBean m = ManagementFactoryHelper.getCompilationMXBean();
+                if (m == null) {
+                   return Collections.emptyList();
+                } else {
+                   return Collections.singletonList(m);
+                }
+            }
+        }),
+
+    /**
+     * Memory system of the Java virtual machine.
+     */
+    MEMORY(
+        "java.lang.management.MemoryMXBean",
+        "java.lang", "Memory", defaultKeyProperties(),
+        new MXBeanFetcher<MemoryMXBean>() {
+            public List<MemoryMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getMemoryMXBean());
+            }
+        }),
+
+    /**
+     * Garbage Collector in the Java virtual machine.
+     */
+    GARBAGE_COLLECTOR(
+        "java.lang.management.GarbageCollectorMXBean",
+        "java.lang", "GarbageCollector", keyProperties("name"),
+        new MXBeanFetcher<GarbageCollectorMXBean>() {
+            public List<GarbageCollectorMXBean> getMXBeans() {
+                return ManagementFactoryHelper.
+                           getGarbageCollectorMXBeans();
+            }
+        }),
+
+    /**
+     * Memory manager in the Java virtual machine.
+     */
+    MEMORY_MANAGER(
+        "java.lang.management.MemoryManagerMXBean",
+        "java.lang", "MemoryManager", keyProperties("name"),
+        new MXBeanFetcher<MemoryManagerMXBean>() {
+            public List<MemoryManagerMXBean> getMXBeans() {
+                return ManagementFactoryHelper.getMemoryManagerMXBeans();
+            }
+        },
+        GARBAGE_COLLECTOR),
+
+    /**
+     * Memory pool in the Java virtual machine.
+     */
+    MEMORY_POOL(
+        "java.lang.management.MemoryPoolMXBean",
+        "java.lang", "MemoryPool", keyProperties("name"),
+        new MXBeanFetcher<MemoryPoolMXBean>() {
+            public List<MemoryPoolMXBean> getMXBeans() {
+                return ManagementFactoryHelper.getMemoryPoolMXBeans();
+            }
+        }),
+
+    /**
+     * Operating system on which the Java virtual machine is running
+     */
+    OPERATING_SYSTEM(
+        "java.lang.management.OperatingSystemMXBean",
+        "java.lang", "OperatingSystem", defaultKeyProperties(),
+        new MXBeanFetcher<OperatingSystemMXBean>() {
+            public List<OperatingSystemMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getOperatingSystemMXBean());
+            }
+        }),
+
+    /**
+     * Runtime system of the Java virtual machine.
+     */
+    RUNTIME(
+        "java.lang.management.RuntimeMXBean",
+        "java.lang", "Runtime", defaultKeyProperties(),
+        new MXBeanFetcher<RuntimeMXBean>() {
+            public List<RuntimeMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getRuntimeMXBean());
+            }
+        }),
+
+    /**
+     * Threading system of the Java virtual machine.
+     */
+    THREADING(
+        "java.lang.management.ThreadMXBean",
+        "java.lang", "Threading", defaultKeyProperties(),
+        new MXBeanFetcher<ThreadMXBean>() {
+            public List<ThreadMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getThreadMXBean());
+            }
+        }),
+
+
+    /**
+     * Logging facility.
+     */
+    LOGGING(
+        "java.util.logging.LoggingMXBean",
+        "java.util.logging", "Logging", defaultKeyProperties(),
+        new MXBeanFetcher<LoggingMXBean>() {
+            public List<LoggingMXBean> getMXBeans() {
+                return Collections.singletonList(LogManager.getLoggingMXBean());
+            }
+        }),
+
+    // Sun Platform Extension
+
+    /**
+     * Sun extension garbage collector that performs collections in cycles.
+     */
+    SUN_GARBAGE_COLLECTOR(
+        "com.sun.management.GarbageCollectorMXBean",
+        "java.lang", "GarbageCollector", keyProperties("name"),
+        new MXBeanFetcher<com.sun.management.GarbageCollectorMXBean>() {
+            public List<com.sun.management.GarbageCollectorMXBean> getMXBeans() {
+                return getGcMXBeanList(com.sun.management.GarbageCollectorMXBean.class);
+            }
+        }),
+
+    /**
+     * Sun extension operating system on which the Java virtual machine
+     * is running.
+     */
+    SUN_OPERATING_SYSTEM(
+        "com.sun.management.OperatingSystemMXBean",
+        "java.lang", "OperatingSystem", defaultKeyProperties(),
+        new MXBeanFetcher<com.sun.management.OperatingSystemMXBean>() {
+            public List<com.sun.management.OperatingSystemMXBean> getMXBeans() {
+                return getOSMXBeanList(com.sun.management.OperatingSystemMXBean.class);
+            }
+        }),
+
+    /**
+     * Unix operating system.
+     */
+    SUN_UNIX_OPERATING_SYSTEM(
+        "com.sun.management.UnixOperatingSystemMXBean",
+        "java.lang", "OperatingSystem", defaultKeyProperties(),
+        new MXBeanFetcher<UnixOperatingSystemMXBean>() {
+            public List<UnixOperatingSystemMXBean> getMXBeans() {
+                return getOSMXBeanList(com.sun.management.UnixOperatingSystemMXBean.class);
+            }
+        }),
+
+    /**
+     * Diagnostic support for the HotSpot Virtual Machine.
+     */
+    HOTSPOT_DIAGNOSTIC(
+        "com.sun.management.HotSpotDiagnosticMXBean",
+        "com.sun.management", "HotSpotDiagnostic", defaultKeyProperties(),
+        new MXBeanFetcher<HotSpotDiagnosticMXBean>() {
+            public List<HotSpotDiagnosticMXBean> getMXBeans() {
+                return Collections.singletonList(ManagementFactoryHelper.getDiagnosticMXBean());
+            }
+        });
+
+
+    /**
+     * A task that returns the MXBeans for a component.
+     */
+    interface MXBeanFetcher<T extends PlatformManagedObject> {
+        public List<T> getMXBeans();
+    }
+
+    /*
+     * Returns a list of the GC MXBeans of the given type.
+     */
+    private static <T extends GarbageCollectorMXBean>
+            List<T> getGcMXBeanList(Class<T> gcMXBeanIntf) {
+        List<GarbageCollectorMXBean> list =
+            ManagementFactoryHelper.getGarbageCollectorMXBeans();
+        List<T> result = new ArrayList<T>(list.size());
+        for (GarbageCollectorMXBean m : list) {
+            if (gcMXBeanIntf.isInstance(m)) {
+                result.add(gcMXBeanIntf.cast(m));
+            }
+        }
+        return result;
+    }
+
+    /*
+     * Returns the OS mxbean instance of the given type.
+     */
+    private static <T extends OperatingSystemMXBean>
+            List<T> getOSMXBeanList(Class<T> osMXBeanIntf) {
+        OperatingSystemMXBean m =
+            ManagementFactoryHelper.getOperatingSystemMXBean();
+        if (osMXBeanIntf.isInstance(m)) {
+            return Collections.singletonList(osMXBeanIntf.cast(m));
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    private final String mxbeanInterfaceName;
+    private final String domain;
+    private final String type;
+    private final Set<String> keyProperties;
+    private final MXBeanFetcher fetcher;
+    private final PlatformComponent[] subComponents;
+
+    private PlatformComponent(String intfName,
+                              String domain, String type,
+                              Set<String> keyProperties,
+                              MXBeanFetcher fetcher) {
+        this.mxbeanInterfaceName = intfName;
+        this.domain = domain;
+        this.type = type;
+        this.keyProperties = keyProperties;
+        this.fetcher = fetcher;
+        this.subComponents = new PlatformComponent[0];
+    }
+    private PlatformComponent(String intfName,
+                              String domain, String type,
+                              Set<String> keyProperties,
+                              MXBeanFetcher fetcher,
+                              PlatformComponent... subComponents) {
+        this.mxbeanInterfaceName = intfName;
+        this.domain = domain;
+        this.type = type;
+        this.keyProperties = keyProperties;
+        this.fetcher = fetcher;
+        this.subComponents = subComponents;
+    }
+
+    private static Set<String> defaultKeyProps;
+    private static Set<String> defaultKeyProperties() {
+        if (defaultKeyProps == null) {
+            defaultKeyProps = Collections.singleton("type");
+        }
+        return defaultKeyProps;
+    }
+
+    private static Set<String> keyProperties(String... keyNames) {
+        Set<String> set = new HashSet<String>();
+        set.add("type");
+        for (String s : keyNames) {
+            set.add(s);
+        }
+        return set;
+    }
+
+    String getMXBeanInterfaceName() {
+        return mxbeanInterfaceName;
+    }
+
+    @SuppressWarnings("unchecked")
+    Class<? extends PlatformManagedObject> getMXBeanInterface() {
+        try {
+            // Lazy loading the MXBean interface only when it is needed
+            return (Class<? extends PlatformManagedObject>)
+                       Class.forName(mxbeanInterfaceName, false, null);
+        } catch (ClassNotFoundException x) {
+            throw new AssertionError(x);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    <T extends PlatformManagedObject>
+        List<T> getMXBeans(Class<T> mxbeanInterface)
+    {
+        return fetcher.getMXBeans();
+    }
+
+    <T extends PlatformManagedObject>
+        List<T> getMXBeans(MBeanServerConnection mbs, Class<T> mxbeanInterface)
+        throws java.io.IOException
+    {
+        List<T> result = new ArrayList<T>();
+        for (ObjectName on : getObjectNames(mbs)) {
+            result.add(ManagementFactory.
+                newPlatformMXBeanProxy(mbs,
+                                       on.getCanonicalName(),
+                                       mxbeanInterface)
+            );
+        }
+        return result;
+    }
+
+    private Set<ObjectName> getObjectNames(MBeanServerConnection mbs)
+        throws java.io.IOException
+    {
+        String domainAndType = domain + ":type=" + type;
+        if (keyProperties.size() > 1) {
+            // if there are more than 1 key properties (i.e. other than "type")
+            domainAndType += ",*";
+        }
+        ObjectName on = com.sun.jmx.mbeanserver.Util.newObjectName(domainAndType);
+        Set<ObjectName> set =  mbs.queryNames(on, null);
+        for (PlatformComponent pc : subComponents) {
+            set.addAll(pc.getObjectNames(mbs));
+        }
+        return set;
+    }
+
+    private static final long serialVersionUID = 6992337162326171013L;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/lang/management/PlatformManagedObject.java	Thu Apr 10 10:47:13 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.lang.management;
+
+import javax.management.ObjectName;
+
+/**
+ * A platform managed object is a {@linkplain javax.management.MXBean JMX MXBean}
+ * for monitoring and managing a component in the Java platform.
+ * Each platform managed object has a unique
+ * <a href="ManagementFactory.html#MXBean">object name</a>
+ * for the {@linkplain ManagementFactory.getPlatformMBeanServer
+ * platform MBeanServer} access.
+ * All platform MXBeans will implement this interface.
+ *
+ * <p>
+ * Note:
+ * The platform MXBean interfaces (i.e. all subinterfaces
+ * of {@code PlatformManagedObject}) are implemented
+ * by the Java platform only.  New methods may be added in these interfaces
+ * in future Java SE releases.
+ * In addition, this {@code PlatformManagedObject} interface is only
+ * intended for the management interfaces for the platform to extend but
+ * not for applications.
+ *
+ * @see <a href="ManagementFactory.html#MXBean">Platform MXBeans</a>
+ * @since 1.7
+ */
+public interface PlatformManagedObject {
+    /**
+     * Returns an {@link ObjectName ObjectName} instance representing
+     * the object name of this platform managed object.
+     *
+     * @return an {@link ObjectName ObjectName} instance representing
+     * the object name of this platform managed object.
+     */
+    public ObjectName getObjectName();
+}
--- a/jdk/src/share/classes/java/lang/management/RuntimeMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/RuntimeMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -44,9 +44,13 @@
  *           <tt>java.lang:type=Runtime</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
  * <p> This interface defines several convenient methods for accessing
  * system properties about the Java virtual machine.
  *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -55,7 +59,7 @@
  * @author  Mandy Chung
  * @since   1.5
  */
-public interface RuntimeMXBean {
+public interface RuntimeMXBean extends PlatformManagedObject {
     /**
      * Returns the name representing the running Java virtual machine.
      * The returned name string can be any arbitrary string and
--- a/jdk/src/share/classes/java/lang/management/ThreadInfo.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/ThreadInfo.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,7 @@
 package java.lang.management;
 
 import javax.management.openmbean.CompositeData;
+import sun.management.ManagementFactoryHelper;
 import sun.management.ThreadInfoCompositeData;
 import static java.lang.Thread.State.*;
 
@@ -220,12 +221,9 @@
                             LockInfo[] lockedSynchronizers) {
         this.threadId = t.getId();
         this.threadName = t.getName();
-        this.threadState =
-            sun.management.ManagementFactory.toThreadState(state);
-        this.suspended =
-            sun.management.ManagementFactory.isThreadSuspended(state);
-        this.inNative =
-            sun.management.ManagementFactory.isThreadRunningNative(state);
+        this.threadState = ManagementFactoryHelper.toThreadState(state);
+        this.suspended = ManagementFactoryHelper.isThreadSuspended(state);
+        this.inNative = ManagementFactoryHelper.isThreadRunningNative(state);
         this.blockedCount = blockedCount;
         this.blockedTime = blockedTime;
         this.waitedCount = waitedCount;
--- a/jdk/src/share/classes/java/lang/management/ThreadMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/lang/management/ThreadMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -46,6 +46,9 @@
  *           <tt>java.lang:type=Threading</tt>}
  * </blockquote>
  *
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
  * <h4>Thread ID</h4>
  * Thread ID is a positive long value returned by calling the
  * {@link java.lang.Thread#getId} method for a thread.
@@ -108,6 +111,7 @@
  * {@link #findDeadlockedThreads} methods to find deadlocks in
  * the running application.
  *
+ * @see ManagementFactory#getPlatformMXBeans(Class)
  * @see <a href="../../../javax/management/package-summary.html">
  *      JMX Specification.</a>
  * @see <a href="package-summary.html#examples">
@@ -117,7 +121,7 @@
  * @since   1.5
  */
 
-public interface ThreadMXBean {
+public interface ThreadMXBean extends PlatformManagedObject {
     /**
      * Returns the current number of live threads including both
      * daemon and non-daemon threads.
--- a/jdk/src/share/classes/java/util/logging/Logging.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/util/logging/Logging.java	Thu Apr 10 10:47:13 2008 -0700
@@ -29,6 +29,8 @@
 import java.util.List;
 import java.util.ArrayList;
 
+import javax.management.ObjectName;
+
 /**
  * Logging is the implementation class of LoggingMXBean.
  *
@@ -115,4 +117,7 @@
         }
     }
 
+    public ObjectName getObjectName() {
+        return com.sun.jmx.mbeanserver.Util.newObjectName(LogManager.LOGGING_MXBEAN_NAME);
+    }
 }
--- a/jdk/src/share/classes/java/util/logging/LoggingMXBean.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/java/util/logging/LoggingMXBean.java	Thu Apr 10 10:47:13 2008 -0700
@@ -25,6 +25,8 @@
 
 package java.util.logging;
 
+import java.lang.management.PlatformManagedObject;
+
 /**
  * The management interface for the logging facility.
  *
@@ -43,14 +45,17 @@
  *           <tt>java.util.logging:type=Logging</tt>}
  * </blockquote>
  *
- * @see java.lang.management.ManagementFactory
+ * It can be obtained by calling the
+ * {@link PlatformManagedObject#getObjectName} method.
+ *
+ * @see java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
  *
  * @author  Ron Mann
  * @author  Mandy Chung
  * @since   1.5
  *
  */
-public interface LoggingMXBean {
+public interface LoggingMXBean extends PlatformManagedObject {
 
     /**
      * Returns the list of currently registered loggers. This method
--- a/jdk/src/share/classes/sun/management/ClassLoadingImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/ClassLoadingImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,8 @@
 package sun.management;
 
 import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+import javax.management.ObjectName;
 
 /**
  * Implementation class for the class loading subsystem.
@@ -62,9 +64,13 @@
     }
 
     public void setVerbose(boolean value) {
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         setVerboseClass(value);
     }
     native static void setVerboseClass(boolean value);
+
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME);
+    }
 }
--- a/jdk/src/share/classes/sun/management/CompilationImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/CompilationImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,8 @@
 package sun.management;
 
 import java.lang.management.CompilationMXBean;
+import java.lang.management.ManagementFactory;
+import javax.management.ObjectName;
 
 /**
  * Implementation class for the compilation subsystem.
@@ -46,7 +48,7 @@
         this.jvm = vm;
         this.name = jvm.getCompilerName();
         if (name == null) {
-            throw new InternalError("Null compiler name");
+            throw new AssertionError("Null compiler name");
         }
     }
 
@@ -67,4 +69,9 @@
         return jvm.getTotalCompileTime();
     }
 
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
+    }
+
+
 }
--- a/jdk/src/share/classes/sun/management/GarbageCollectorImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/GarbageCollectorImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -34,6 +34,7 @@
 import javax.management.openmbean.CompositeData;
 import javax.management.MBeanInfo;
 import javax.management.MBeanAttributeInfo;
+import javax.management.ObjectName;
 
 import java.util.List;
 import java.util.ListIterator;
@@ -88,4 +89,8 @@
         return info;
     }
 
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, getName());
+    }
+
 }
--- a/jdk/src/share/classes/sun/management/GcInfoBuilder.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/GcInfoBuilder.java	Thu Apr 10 10:47:13 2008 -0700
@@ -145,7 +145,7 @@
                         allItemTypes[i] = SimpleType.DOUBLE;
                         break;
                     default:
-                        throw new InternalError(
+                        throw new AssertionError(
                             "Unsupported type [" + gcExtItemTypes[i] + "]");
                 }
             }
--- a/jdk/src/share/classes/sun/management/GcInfoCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/GcInfoCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -80,19 +80,19 @@
             };
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
 
         // Get the item values for the extension attributes
         final int gcExtItemCount = builder.getGcExtItemCount();
         if (gcExtItemCount == 0 &&
             gcExtItemValues != null && gcExtItemValues.length != 0) {
-            throw new InternalError("Unexpected Gc Extension Item Values");
+            throw new AssertionError("Unexpected Gc Extension Item Values");
         }
 
         if (gcExtItemCount > 0 && (gcExtItemValues == null ||
              gcExtItemCount != gcExtItemValues.length)) {
-            throw new InternalError("Unmatched Gc Extension Item Values");
+            throw new AssertionError("Unmatched Gc Extension Item Values");
         }
 
         Object[] values = new Object[baseGcInfoItemValues.length +
@@ -111,7 +111,7 @@
                                             values);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -141,10 +141,10 @@
                 MappedMXBeanType.getMappedType(m.getGenericReturnType());
         } catch (NoSuchMethodException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -186,10 +186,10 @@
             return cast(memoryUsageMapType.toJavaTypeData(td));
         } catch (InvalidObjectException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -205,10 +205,10 @@
             return cast(memoryUsageMapType.toJavaTypeData(td));
         } catch (InvalidObjectException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java	Thu Apr 10 10:47:13 2008 -0700
@@ -28,6 +28,8 @@
 import java.util.*;
 import java.io.IOException;
 import java.lang.reflect.Method;
+import javax.management.ObjectName;
+
 import com.sun.management.HotSpotDiagnosticMXBean;
 import com.sun.management.VMOption;
 
@@ -72,7 +74,7 @@
             throw new NullPointerException("value cannot be null");
         }
 
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
         Flag flag = Flag.getFlag(name);
         if (flag == null) {
             throw new IllegalArgumentException("VM option \"" +
@@ -113,4 +115,8 @@
                 v.getClass().getName());
         }
     }
+
+    public ObjectName getObjectName() {
+        return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic");
+    }
 }
--- a/jdk/src/share/classes/sun/management/HotspotCompilation.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/HotspotCompilation.java	Thu Apr 10 10:47:13 2008 -0700
@@ -131,7 +131,7 @@
         }
 
         // FIXME: should tolerate if counter doesn't exist
-        throw new InternalError("Counter " + name + " does not exist");
+        throw new AssertionError("Counter " + name + " does not exist");
     }
 
     private void initCompilerCounters() {
--- a/jdk/src/share/classes/sun/management/HotspotInternal.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/HotspotInternal.java	Thu Apr 10 10:47:13 2008 -0700
@@ -39,6 +39,9 @@
 public class HotspotInternal
     implements HotspotInternalMBean, MBeanRegistration {
 
+    private final static String HOTSPOT_INTERNAL_MBEAN_NAME =
+        "sun.management:type=HotspotInternal";
+    private static ObjectName objName = Util.newObjectName(HOTSPOT_INTERNAL_MBEAN_NAME);
     private MBeanServer server = null;
 
     /**
@@ -52,16 +55,16 @@
                                   ObjectName name) throws java.lang.Exception {
         // register all internal MBeans when this MBean is instantiated
         // and to be registered in a MBeanServer.
-        ManagementFactory.registerInternalMBeans(server);
+        ManagementFactoryHelper.registerInternalMBeans(server);
         this.server = server;
-        return ManagementFactory.getHotspotInternalObjectName();
+        return objName;
     }
 
     public void postRegister(Boolean registrationDone) {};
 
     public void preDeregister() throws java.lang.Exception {
         // unregister all internal MBeans when this MBean is unregistered.
-        ManagementFactory.unregisterInternalMBeans(server);
+        ManagementFactoryHelper.unregisterInternalMBeans(server);
     }
 
     public void postDeregister() {};
--- a/jdk/src/share/classes/sun/management/LockDataConverter.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/LockDataConverter.java	Thu Apr 10 10:47:13 2008 -0700
@@ -73,7 +73,7 @@
         try {
             return (CompositeData) getAttribute("LockInfo");
         } catch (Exception e) {
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -81,7 +81,7 @@
         try {
             return (CompositeData[]) getAttribute("LockedSynchronizers");
         } catch (Exception e) {
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -89,7 +89,7 @@
         try {
             setAttribute(new Attribute("LockInfo", cd));
         } catch (Exception e) {
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
         return getLockInfo();
     }
@@ -98,7 +98,7 @@
         try {
             setAttribute(new Attribute("LockedSynchronizers", cd));
         } catch (Exception e) {
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
         return getLockedSynchronizers();
     }
--- a/jdk/src/share/classes/sun/management/ManagementFactory.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/ManagementFactory.java	Thu Apr 10 10:47:13 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  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
@@ -25,445 +25,17 @@
 
 package sun.management;
 
-import java.lang.management.*;
-import java.util.logging.LogManager;
-
-import javax.management.DynamicMBean;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.MBeanInfo;
-import javax.management.NotificationEmitter;
-import javax.management.ObjectName;
-import javax.management.ObjectInstance;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanRegistrationException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.MalformedObjectNameException;
-import javax.management.RuntimeOperationsException;
-import javax.management.StandardEmitterMBean;
-import javax.management.StandardMBean;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import sun.security.action.LoadLibraryAction;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.ListIterator;
-import com.sun.management.OSMBeanFactory;
-import com.sun.management.HotSpotDiagnosticMXBean;
-
-import static java.lang.management.ManagementFactory.*;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.GarbageCollectorMXBean;
 
 /**
- * ManagementFactory provides static factory methods to create
- * instances of the management interface.
+ * ManagementFactory class provides the methods that the HotSpot VM
+ * will invoke. So the class and method names cannot be renamed.
  */
-public class ManagementFactory {
+class ManagementFactory {
     private ManagementFactory() {};
 
-    private static VMManagement jvm;
-
-    private static boolean mbeansCreated = false;
-    private static ClassLoadingImpl    classMBean = null;
-    private static MemoryImpl          memoryMBean = null;
-    private static ThreadImpl          threadMBean = null;
-    private static RuntimeImpl         runtimeMBean = null;
-    private static CompilationImpl     compileMBean = null;
-    private static OperatingSystemImpl osMBean = null;
-
-    public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
-        if (classMBean == null) {
-            classMBean = new ClassLoadingImpl(jvm);
-        }
-        return classMBean;
-    }
-
-    public static synchronized MemoryMXBean getMemoryMXBean() {
-        if (memoryMBean == null) {
-            memoryMBean = new MemoryImpl(jvm);
-        }
-        return memoryMBean;
-    }
-
-    public static synchronized ThreadMXBean getThreadMXBean() {
-        if (threadMBean == null) {
-            threadMBean = new ThreadImpl(jvm);
-        }
-        return threadMBean;
-    }
-
-    public static synchronized RuntimeMXBean getRuntimeMXBean() {
-        if (runtimeMBean == null) {
-            runtimeMBean = new RuntimeImpl(jvm);
-        }
-        return runtimeMBean;
-    }
-
-    public static synchronized CompilationMXBean getCompilationMXBean() {
-        if (compileMBean == null && jvm.getCompilerName() != null) {
-            compileMBean = new CompilationImpl(jvm);
-        }
-        return compileMBean;
-    }
-
-    public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
-        if (osMBean == null) {
-            osMBean = (OperatingSystemImpl)
-                          OSMBeanFactory.getOperatingSystemMXBean(jvm);
-        }
-        return osMBean;
-    }
-
-    public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
-        MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
-        List<MemoryPoolMXBean> list = new ArrayList<MemoryPoolMXBean>(pools.length);
-        for (int i = 0; i < pools.length; i++) {
-            MemoryPoolMXBean p = pools[i];
-            list.add(p);
-        }
-        return list;
-    }
-
-    public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
-        MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
-        List<MemoryManagerMXBean> result = new ArrayList<MemoryManagerMXBean>(mgrs.length);
-        for (int i = 0; i < mgrs.length; i++) {
-            MemoryManagerMXBean m = mgrs[i];
-            result.add(m);
-        }
-        return result;
-    }
-
-    public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
-        MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
-        List<GarbageCollectorMXBean> result = new ArrayList<GarbageCollectorMXBean>(mgrs.length);
-        for (int i = 0; i < mgrs.length; i++) {
-            if (mgrs[i] instanceof GarbageCollectorMXBean) {
-                GarbageCollectorMXBean gc = (GarbageCollectorMXBean) mgrs[i];
-                result.add(gc);
-            }
-        }
-        return result;
-    }
-
-    private static HotSpotDiagnostic hsDiagMBean = null;
-    private static HotspotRuntime hsRuntimeMBean = null;
-    private static HotspotClassLoading hsClassMBean = null;
-    private static HotspotThread hsThreadMBean = null;
-    private static HotspotCompilation hsCompileMBean = null;
-    private static HotspotMemory hsMemoryMBean = null;
-
-    public static synchronized HotSpotDiagnosticMXBean getDiagnosticMXBean() {
-        if (hsDiagMBean == null) {
-            hsDiagMBean = new HotSpotDiagnostic();
-        }
-        return hsDiagMBean;
-    }
-
-    /**
-
-    /**
-     * This method is for testing only.
-     */
-    public static synchronized HotspotRuntimeMBean getHotspotRuntimeMBean() {
-        if (hsRuntimeMBean == null) {
-            hsRuntimeMBean = new HotspotRuntime(jvm);
-        }
-        return hsRuntimeMBean;
-    }
-
-    /**
-     * This method is for testing only.
-     */
-    public static synchronized HotspotClassLoadingMBean getHotspotClassLoadingMBean() {
-        if (hsClassMBean == null) {
-            hsClassMBean = new HotspotClassLoading(jvm);
-        }
-        return hsClassMBean;
-    }
-
-    /**
-     * This method is for testing only.
-     */
-    public static synchronized HotspotThreadMBean getHotspotThreadMBean() {
-        if (hsThreadMBean == null) {
-            hsThreadMBean = new HotspotThread(jvm);
-        }
-        return hsThreadMBean;
-    }
-
-    /**
-     * This method is for testing only.
-     */
-    public static synchronized HotspotMemoryMBean getHotspotMemoryMBean() {
-        if (hsMemoryMBean == null) {
-            hsMemoryMBean = new HotspotMemory(jvm);
-        }
-        return hsMemoryMBean;
-    }
-
-    /**
-     * This method is for testing only.
-     */
-    public static synchronized HotspotCompilationMBean getHotspotCompilationMBean() {
-        if (hsCompileMBean == null) {
-            hsCompileMBean = new HotspotCompilation(jvm);
-        }
-        return hsCompileMBean;
-    }
-
-    private static Permission monitorPermission =
-        new ManagementPermission("monitor");
-    private static Permission controlPermission =
-        new ManagementPermission("control");
-
-    /**
-     * Check that the current context is trusted to perform monitoring
-     * or management.
-     * <p>
-     * If the check fails we throw a SecurityException, otherwise
-     * we return normally.
-     *
-     * @exception  SecurityException  if a security manager exists and if
-     *             the caller does not have ManagementPermission("control").
-     */
-    static void checkAccess(Permission p)
-         throws SecurityException {
-        SecurityManager sm = System.getSecurityManager();
-        if (sm != null) {
-            sm.checkPermission(p);
-        }
-    }
-
-    static void checkMonitorAccess() throws SecurityException {
-        checkAccess(monitorPermission);
-    }
-    static void checkControlAccess() throws SecurityException {
-        checkAccess(controlPermission);
-    }
-
-    /**
-     * Registers an MXBean and throws exception if an instance with the same
-     * name exists.
-     *
-     * This method makes a DynamicMBean out of an MXBean by wrapping it with a
-     * StandardMBean (StandardEmitterMBean if the supplied emitter is not null),
-     * so it can be registered in an MBeanServer which does not have support for
-     * MXBeans.
-     */
-    private static void addMXBean(MBeanServer mbs, Object mbean,
-                                  String mbeanName, NotificationEmitter emitter) {
-        // Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
-        //
-        final DynamicMBean dmbean;
-        if (emitter == null) {
-            dmbean = new StandardMBean(mbean, null, true);
-        } else {
-            dmbean = new StandardEmitterMBean(mbean, null, true, emitter);
-        }
-        addMBean(mbs, dmbean, mbeanName, false);
-    }
-
-    /**
-     * Registers a Standard MBean or a Dynamic MBean and throws
-     * exception if an instance with the same name exists.
-     */
-    private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) {
-        addMBean(mbs, mbean, mbeanName, false);
-    }
-
-    private static void addMBean(MBeanServer mbs, Object mbean,
-                                 String mbeanName, boolean ignoreConflicts) {
-        try {
-            final ObjectName objName = new ObjectName(mbeanName);
-
-            // inner class requires these fields to be final
-            final MBeanServer mbs0 = mbs;
-            final Object mbean0 = mbean;
-            final boolean ignore = ignoreConflicts;
-            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
-                public Object run() throws InstanceAlreadyExistsException,
-                                           MBeanRegistrationException,
-                                           NotCompliantMBeanException {
-                    try {
-                        ObjectInstance o = mbs0.registerMBean(mbean0,
-                                                              objName);
-                        return null;
-                    } catch (InstanceAlreadyExistsException e) {
-                        // if an instance with the object name exists in
-                        // the MBeanServer ignore the exception
-                        // if ignoreConflicts is true;
-                        // otherwise, throws exception.
-                        if (!ignore) {
-                             throw e;
-                        }
-                    }
-                    return null;
-                }
-            });
-        } catch (PrivilegedActionException e) {
-            throw Util.newException(e.getException());
-        } catch (MalformedObjectNameException e) {
-            // should not reach here
-            throw Util.newException(e);
-        }
-    }
-
-    public static MBeanServer createPlatformMBeanServer() {
-        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
-        // Register all the platform MBeans to this MBeanServer
-        addMXBean(mbs, getClassLoadingMXBean(),
-                  CLASS_LOADING_MXBEAN_NAME, null);
-        addMXBean(mbs, getMemoryMXBean(),
-                  MEMORY_MXBEAN_NAME, (NotificationEmitter) getMemoryMXBean());
-        addMXBean(mbs, getOperatingSystemMXBean(),
-                  OPERATING_SYSTEM_MXBEAN_NAME, null);
-        addMXBean(mbs, getRuntimeMXBean(),
-                  RUNTIME_MXBEAN_NAME, null);
-        addMXBean(mbs, getThreadMXBean(),
-                  THREAD_MXBEAN_NAME, null);
-        addMXBean(mbs, getDiagnosticMXBean(),
-                  HOTSPOT_DIAGNOSTIC_MXBEAN_NAME, null);
-
-        // CompilationMBean may not exist
-        if (getCompilationMXBean() != null) {
-            addMXBean(mbs, getCompilationMXBean(),
-                      COMPILATION_MXBEAN_NAME, null);
-        }
-
-        // Register MBeans for memory pools and memory managers
-        addMemoryManagers(mbs);
-        addMemoryPools(mbs);
-
-        // Register platform extension
-        addMXBean(mbs, LogManager.getLoggingMXBean(),
-                  LogManager.LOGGING_MXBEAN_NAME, null);
-
-        return mbs;
-    }
-
-    private final static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
-        "com.sun.management:type=HotSpotDiagnostic";
-
-    private final static String HOTSPOT_CLASS_LOADING_MBEAN_NAME =
-        "sun.management:type=HotspotClassLoading";
-
-    private final static String HOTSPOT_COMPILATION_MBEAN_NAME =
-        "sun.management:type=HotspotCompilation";
-
-    private final static String HOTSPOT_MEMORY_MBEAN_NAME =
-        "sun.management:type=HotspotMemory";
-
-    private static final String HOTSPOT_RUNTIME_MBEAN_NAME =
-        "sun.management:type=HotspotRuntime";
-
-    private final static String HOTSPOT_THREAD_MBEAN_NAME =
-        "sun.management:type=HotspotThreading";
-
-    private final static String HOTSPOT_INTERNAL_MBEAN_NAME =
-        "sun.management:type=HotspotInternal";
-
-    private static ObjectName hsInternalObjName = null;
-    static synchronized ObjectName getHotspotInternalObjectName() {
-        if (hsInternalObjName == null) {
-            try {
-                hsInternalObjName = new ObjectName(HOTSPOT_INTERNAL_MBEAN_NAME);
-            } catch (MalformedObjectNameException e) {
-                // should not reach here
-                throw Util.newException(e);
-            }
-        }
-        return hsInternalObjName;
-    }
-
-    static void registerInternalMBeans(MBeanServer mbs) {
-        // register all internal MBeans if not registered
-        // No exception is thrown if a MBean with that object name
-        // already registered (i.e. ignore if name conflicts).
-        addMBean(mbs, getHotspotClassLoadingMBean(),
-            HOTSPOT_CLASS_LOADING_MBEAN_NAME, true);
-        addMBean(mbs, getHotspotMemoryMBean(),
-            HOTSPOT_MEMORY_MBEAN_NAME, true);
-        addMBean(mbs, getHotspotRuntimeMBean(),
-            HOTSPOT_RUNTIME_MBEAN_NAME, true);
-        addMBean(mbs, getHotspotThreadMBean(),
-            HOTSPOT_THREAD_MBEAN_NAME, true);
-
-        // CompilationMBean may not exist
-        if (getCompilationMXBean() != null) {
-            addMBean(mbs, getHotspotCompilationMBean(),
-                HOTSPOT_COMPILATION_MBEAN_NAME, true);
-        }
-    }
-
-    private static void unregisterMBean(MBeanServer mbs, String mbeanName) {
-        try {
-            final ObjectName objName = new ObjectName(mbeanName);
-
-            // inner class requires these fields to be final
-            final MBeanServer mbs0 = mbs;
-            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
-                public Object run() throws MBeanRegistrationException,
-                                           RuntimeOperationsException  {
-                    try {
-                        mbs0.unregisterMBean(objName);
-                    } catch (InstanceNotFoundException e) {
-                        // ignore exception if not found
-                    }
-                    return null;
-                }
-            });
-        } catch (PrivilegedActionException e) {
-            throw Util.newException(e.getException());
-        } catch (MalformedObjectNameException e) {
-            // should not reach here
-            throw Util.newException(e);
-        }
-    }
-
-    static void unregisterInternalMBeans(MBeanServer mbs) {
-        // unregister all internal MBeans
-        unregisterMBean(mbs, HOTSPOT_CLASS_LOADING_MBEAN_NAME);
-        unregisterMBean(mbs, HOTSPOT_MEMORY_MBEAN_NAME);
-        unregisterMBean(mbs, HOTSPOT_RUNTIME_MBEAN_NAME);
-        unregisterMBean(mbs, HOTSPOT_THREAD_MBEAN_NAME);
-
-        // CompilationMBean may not exist
-        if (getCompilationMXBean() != null) {
-            unregisterMBean(mbs, HOTSPOT_COMPILATION_MBEAN_NAME);
-        }
-    }
-
-    private static synchronized void addMemoryPools(MBeanServer mbs) {
-
-        // Get a list of memory pools
-        MemoryPoolMXBean[] newPools = MemoryImpl.getMemoryPools();
-
-        for (int i = 0; i < newPools.length; i++) {
-            String poolObjNameString = Util.getMBeanObjectName(newPools[i]);
-            addMXBean(mbs, newPools[i], poolObjNameString, null);
-        }
-    }
-
-    // Register all memory managers with the MBeanServer;
-    private static synchronized void addMemoryManagers(MBeanServer mbs) {
-
-        // Get a list of memory managers
-        MemoryManagerMXBean[] newMgrs = MemoryImpl.getMemoryManagers();
-
-        for (int i = 0; i < newMgrs.length; i++) {
-            String mgrObjNameString = Util.getMBeanObjectName(newMgrs[i]);
-            addMXBean(mbs, newMgrs[i], mgrObjNameString, null);
-        }
-    }
-
     // Invoked by the VM
     private static MemoryPoolMXBean createMemoryPool
         (String name, boolean isHeap, long uThreshold, long gcThreshold) {
@@ -480,29 +52,4 @@
         // ignore type parameter which is for future extension
         return new GarbageCollectorImpl(name);
     }
-
-    static {
-        AccessController.doPrivileged(new LoadLibraryAction("management"));
-        jvm = new VMManagementImpl();
-    }
-
-    public static boolean isThreadSuspended(int state) {
-        return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0);
-    }
-
-    public static boolean isThreadRunningNative(int state) {
-        return ((state & JMM_THREAD_STATE_FLAG_NATIVE) != 0);
-    }
-
-    public static Thread.State toThreadState(int state) {
-        // suspended and native bits may be set in state
-        int threadStatus = state & ~JMM_THREAD_STATE_FLAG_MASK;
-        return sun.misc.VM.toThreadState(threadStatus);
-    }
-
-    // These values are defined in jmm.h
-    private static final int JMM_THREAD_STATE_FLAG_MASK = 0xFFF00000;
-    private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;
-    private static final int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000;
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/management/ManagementFactoryHelper.java	Thu Apr 10 10:47:13 2008 -0700
@@ -0,0 +1,340 @@
+/*
+ * Copyright 2003-2006 Sun Microsystems, Inc.  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.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.management;
+
+import java.lang.management.*;
+import java.util.logging.LogManager;
+
+import javax.management.DynamicMBean;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanInfo;
+import javax.management.NotificationEmitter;
+import javax.management.ObjectName;
+import javax.management.ObjectInstance;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.RuntimeOperationsException;
+import javax.management.StandardEmitterMBean;
+import javax.management.StandardMBean;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import sun.security.action.LoadLibraryAction;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.ListIterator;
+import com.sun.management.OSMBeanFactory;
+import com.sun.management.HotSpotDiagnosticMXBean;
+
+import static java.lang.management.ManagementFactory.*;
+
+/**
+ * ManagementFactoryHelper provides static factory methods to create
+ * instances of the management interface.
+ */
+public class ManagementFactoryHelper {
+    private ManagementFactoryHelper() {};
+
+    private static VMManagement jvm;
+
+    private static boolean mbeansCreated = false;
+    private static ClassLoadingImpl    classMBean = null;
+    private static MemoryImpl          memoryMBean = null;
+    private static ThreadImpl          threadMBean = null;
+    private static RuntimeImpl         runtimeMBean = null;
+    private static CompilationImpl     compileMBean = null;
+    private static OperatingSystemImpl osMBean = null;
+
+    public static synchronized ClassLoadingMXBean getClassLoadingMXBean() {
+        if (classMBean == null) {
+            classMBean = new ClassLoadingImpl(jvm);
+        }
+        return classMBean;
+    }
+
+    public static synchronized MemoryMXBean getMemoryMXBean() {
+        if (memoryMBean == null) {
+            memoryMBean = new MemoryImpl(jvm);
+        }
+        return memoryMBean;
+    }
+
+    public static synchronized ThreadMXBean getThreadMXBean() {
+        if (threadMBean == null) {
+            threadMBean = new ThreadImpl(jvm);
+        }
+        return threadMBean;
+    }
+
+    public static synchronized RuntimeMXBean getRuntimeMXBean() {
+        if (runtimeMBean == null) {
+            runtimeMBean = new RuntimeImpl(jvm);
+        }
+        return runtimeMBean;
+    }
+
+    public static synchronized CompilationMXBean getCompilationMXBean() {
+        if (compileMBean == null && jvm.getCompilerName() != null) {
+            compileMBean = new CompilationImpl(jvm);
+        }
+        return compileMBean;
+    }
+
+    public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
+        if (osMBean == null) {
+            osMBean = (OperatingSystemImpl)
+                          OSMBeanFactory.getOperatingSystemMXBean(jvm);
+        }
+        return osMBean;
+    }
+
+    public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
+        MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
+        List<MemoryPoolMXBean> list = new ArrayList<MemoryPoolMXBean>(pools.length);
+        for (MemoryPoolMXBean p : pools) {
+            list.add(p);
+        }
+        return list;
+    }
+
+    public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
+        MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
+        List<MemoryManagerMXBean> result = new ArrayList<MemoryManagerMXBean>(mgrs.length);
+        for (MemoryManagerMXBean m : mgrs) {
+            result.add(m);
+        }
+        return result;
+    }
+
+    public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
+        MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
+        List<GarbageCollectorMXBean> result = new ArrayList<GarbageCollectorMXBean>(mgrs.length);
+        for (MemoryManagerMXBean m : mgrs) {
+            if (GarbageCollectorMXBean.class.isInstance(m)) {
+                 result.add(GarbageCollectorMXBean.class.cast(m));
+            }
+        }
+        return result;
+    }
+
+    private static HotSpotDiagnostic hsDiagMBean = null;
+    private static HotspotRuntime hsRuntimeMBean = null;
+    private static HotspotClassLoading hsClassMBean = null;
+    private static HotspotThread hsThreadMBean = null;
+    private static HotspotCompilation hsCompileMBean = null;
+    private static HotspotMemory hsMemoryMBean = null;
+
+    public static synchronized HotSpotDiagnosticMXBean getDiagnosticMXBean() {
+        if (hsDiagMBean == null) {
+            hsDiagMBean = new HotSpotDiagnostic();
+        }
+        return hsDiagMBean;
+    }
+
+    /**
+
+    /**
+     * This method is for testing only.
+     */
+    public static synchronized HotspotRuntimeMBean getHotspotRuntimeMBean() {
+        if (hsRuntimeMBean == null) {
+            hsRuntimeMBean = new HotspotRuntime(jvm);
+        }
+        return hsRuntimeMBean;
+    }
+
+    /**
+     * This method is for testing only.
+     */
+    public static synchronized HotspotClassLoadingMBean getHotspotClassLoadingMBean() {
+        if (hsClassMBean == null) {
+            hsClassMBean = new HotspotClassLoading(jvm);
+        }
+        return hsClassMBean;
+    }
+
+    /**
+     * This method is for testing only.
+     */
+    public static synchronized HotspotThreadMBean getHotspotThreadMBean() {
+        if (hsThreadMBean == null) {
+            hsThreadMBean = new HotspotThread(jvm);
+        }
+        return hsThreadMBean;
+    }
+
+    /**
+     * This method is for testing only.
+     */
+    public static synchronized HotspotMemoryMBean getHotspotMemoryMBean() {
+        if (hsMemoryMBean == null) {
+            hsMemoryMBean = new HotspotMemory(jvm);
+        }
+        return hsMemoryMBean;
+    }
+
+    /**
+     * This method is for testing only.
+     */
+    public static synchronized HotspotCompilationMBean getHotspotCompilationMBean() {
+        if (hsCompileMBean == null) {
+            hsCompileMBean = new HotspotCompilation(jvm);
+        }
+        return hsCompileMBean;
+    }
+
+    /**
+     * Registers a given MBean if not registered in the MBeanServer;
+     * otherwise, just return.
+     */
+    private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) {
+        try {
+            final ObjectName objName = Util.newObjectName(mbeanName);
+
+            // inner class requires these fields to be final
+            final MBeanServer mbs0 = mbs;
+            final Object mbean0 = mbean;
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
+                public Void run() throws MBeanRegistrationException,
+                                         NotCompliantMBeanException {
+                    try {
+                        mbs0.registerMBean(mbean0, objName);
+                        return null;
+                    } catch (InstanceAlreadyExistsException e) {
+                        // if an instance with the object name exists in
+                        // the MBeanServer ignore the exception
+                    }
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw Util.newException(e.getException());
+        }
+    }
+
+    private final static String HOTSPOT_CLASS_LOADING_MBEAN_NAME =
+        "sun.management:type=HotspotClassLoading";
+
+    private final static String HOTSPOT_COMPILATION_MBEAN_NAME =
+        "sun.management:type=HotspotCompilation";
+
+    private final static String HOTSPOT_MEMORY_MBEAN_NAME =
+        "sun.management:type=HotspotMemory";
+
+    private static final String HOTSPOT_RUNTIME_MBEAN_NAME =
+        "sun.management:type=HotspotRuntime";
+
+    private final static String HOTSPOT_THREAD_MBEAN_NAME =
+        "sun.management:type=HotspotThreading";
+
+    static void registerInternalMBeans(MBeanServer mbs) {
+        // register all internal MBeans if not registered
+        // No exception is thrown if a MBean with that object name
+        // already registered
+        addMBean(mbs, getHotspotClassLoadingMBean(),
+            HOTSPOT_CLASS_LOADING_MBEAN_NAME);
+        addMBean(mbs, getHotspotMemoryMBean(),
+            HOTSPOT_MEMORY_MBEAN_NAME);
+        addMBean(mbs, getHotspotRuntimeMBean(),
+            HOTSPOT_RUNTIME_MBEAN_NAME);
+        addMBean(mbs, getHotspotThreadMBean(),
+            HOTSPOT_THREAD_MBEAN_NAME);
+
+        // CompilationMBean may not exist
+        if (getCompilationMXBean() != null) {
+            addMBean(mbs, getHotspotCompilationMBean(),
+                HOTSPOT_COMPILATION_MBEAN_NAME);
+        }
+    }
+
+    private static void unregisterMBean(MBeanServer mbs, String mbeanName) {
+        try {
+            final ObjectName objName = Util.newObjectName(mbeanName);
+
+            // inner class requires these fields to be final
+            final MBeanServer mbs0 = mbs;
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
+                public Void run() throws MBeanRegistrationException,
+                                           RuntimeOperationsException  {
+                    try {
+                        mbs0.unregisterMBean(objName);
+                    } catch (InstanceNotFoundException e) {
+                        // ignore exception if not found
+                    }
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw Util.newException(e.getException());
+        }
+    }
+
+    static void unregisterInternalMBeans(MBeanServer mbs) {
+        // unregister all internal MBeans
+        unregisterMBean(mbs, HOTSPOT_CLASS_LOADING_MBEAN_NAME);
+        unregisterMBean(mbs, HOTSPOT_MEMORY_MBEAN_NAME);
+        unregisterMBean(mbs, HOTSPOT_RUNTIME_MBEAN_NAME);
+        unregisterMBean(mbs, HOTSPOT_THREAD_MBEAN_NAME);
+
+        // CompilationMBean may not exist
+        if (getCompilationMXBean() != null) {
+            unregisterMBean(mbs, HOTSPOT_COMPILATION_MBEAN_NAME);
+        }
+    }
+
+    static {
+        AccessController.doPrivileged(new LoadLibraryAction("management"));
+        jvm = new VMManagementImpl();
+    }
+
+    public static boolean isThreadSuspended(int state) {
+        return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0);
+    }
+
+    public static boolean isThreadRunningNative(int state) {
+        return ((state & JMM_THREAD_STATE_FLAG_NATIVE) != 0);
+    }
+
+    public static Thread.State toThreadState(int state) {
+        // suspended and native bits may be set in state
+        int threadStatus = state & ~JMM_THREAD_STATE_FLAG_MASK;
+        return sun.misc.VM.toThreadState(threadStatus);
+    }
+
+    // These values are defined in jmm.h
+    private static final int JMM_THREAD_STATE_FLAG_MASK = 0xFFF00000;
+    private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000;
+    private static final int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000;
+
+}
--- a/jdk/src/share/classes/sun/management/MappedMXBeanType.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MappedMXBeanType.java	Thu Apr 10 10:47:13 2008 -0700
@@ -735,14 +735,14 @@
             throws OpenDataException, InvalidObjectException {
 
             if (fromMethod == null) {
-                throw new InternalError("Does not support data conversion");
+                throw new AssertionError("Does not support data conversion");
             }
 
             try {
                 return fromMethod.invoke(null, data);
             } catch (IllegalAccessException e) {
                 // should never reach here
-                throw Util.newAssertionError(e);
+                throw new AssertionError(e);
             } catch (InvocationTargetException e) {
                 final OpenDataException ode =
                     new OpenDataException("Failed to invoke " +
@@ -785,7 +785,7 @@
             t = new InProgress();
         } catch (OpenDataException e) {
             // Should not reach here
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
         inProgress = t;
     }
@@ -807,9 +807,9 @@
                 } catch (ClassNotFoundException e) {
                     // the classes that these predefined types declare
                     // must exist!
-                    throw Util.newAssertionError(e);
+                    throw new AssertionError(e);
                 } catch (OpenDataException e) {
-                    throw Util.newAssertionError(e);
+                    throw new AssertionError(e);
                 }
 
                 if (c.getName().startsWith("java.lang.")) {
@@ -821,12 +821,12 @@
                         // OK: must not be a primitive wrapper
                     } catch (IllegalAccessException e) {
                         // Should not reach here
-                       throw Util.newAssertionError(e);
+                       throw new AssertionError(e);
                     }
                 }
             }
         } catch (OpenDataException e) {
-            throw Util.newAssertionError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/MemoryImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MemoryImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -25,13 +25,13 @@
 
 package sun.management;
 
+import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryMXBean;
 import java.lang.management.MemoryUsage;
 import java.lang.management.MemoryNotificationInfo;
 import java.lang.management.MemoryManagerMXBean;
 import java.lang.management.MemoryPoolMXBean;
 import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
 import javax.management.MBeanNotificationInfo;
 import javax.management.Notification;
 import javax.management.NotificationEmitter;
@@ -88,7 +88,7 @@
     }
 
     public void setVerbose(boolean value) {
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         setVerboseGC(value);
     }
@@ -150,19 +150,6 @@
         return ++seqNumber;
     }
 
-    private static ObjectName objname = null;
-    private static synchronized ObjectName getObjectName() {
-        if (objname != null) return objname;
-
-        try {
-            objname = new ObjectName(java.lang.management.ManagementFactory.MEMORY_MXBEAN_NAME);
-        } catch (MalformedObjectNameException e) {
-            // should never reach here
-            throw Util.newInternalError(e);
-        }
-        return objname;
-    }
-
     static void createNotification(String notifType,
                                    String poolName,
                                    MemoryUsage usage,
@@ -175,7 +162,7 @@
         long timestamp = System.currentTimeMillis();
         String msg = getNotifMsg(notifType);
         Notification notif = new Notification(notifType,
-                                              getObjectName(),
+                                              mbean.getObjectName(),
                                               getNextSeqNumber(),
                                               timestamp,
                                               msg);
@@ -189,4 +176,8 @@
         mbean.sendNotification(notif);
     }
 
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
+    }
+
 }
--- a/jdk/src/share/classes/sun/management/MemoryManagerImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MemoryManagerImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -25,9 +25,12 @@
 
 package sun.management;
 
+import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryManagerMXBean;
 import java.lang.management.MemoryPoolMXBean;
 
+import javax.management.ObjectName;
+
 /**
  * Implementation class for a memory manager.
  * Standard and committed hotspot-specific metrics if any.
@@ -73,4 +76,8 @@
     }
     private native MemoryPoolMXBean[] getMemoryPools0();
 
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE, getName());
+    }
+
 }
--- a/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -69,7 +69,7 @@
                                             memoryNotifInfoItemValues);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -80,7 +80,7 @@
                 MappedMXBeanType.toOpenType(MemoryNotificationInfo.class);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/MemoryPoolImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MemoryPoolImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -25,12 +25,13 @@
 
 package sun.management;
 
+import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryPoolMXBean;
-
 import java.lang.management.MemoryUsage;
 import java.lang.management.MemoryType;
 import java.lang.management.MemoryManagerMXBean;
 import javax.management.openmbean.CompositeData;
+import javax.management.ObjectName;
 
 import static java.lang.management.MemoryNotificationInfo.*;
 
@@ -114,7 +115,7 @@
                 "Usage threshold is not supported");
         }
 
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         MemoryUsage usage = getUsage0();
         if (newThreshold < 0) {
@@ -159,7 +160,7 @@
     }
 
     public void resetPeakUsage() {
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         synchronized (this) {
             // synchronized since getPeakUsage may be called concurrently
@@ -211,7 +212,7 @@
                 "CollectionUsage threshold is not supported");
         }
 
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         MemoryUsage usage = getUsage0();
         if (newThreshold < 0) {
@@ -304,7 +305,7 @@
         }
         void triggerAction() {
             // Should not reach here
-            throw new InternalError();
+            throw new AssertionError("Should not reach here");
         }
         void clearAction() {
             // do nothing
@@ -332,10 +333,15 @@
         }
         void triggerAction() {
             // Should not reach here
-            throw new InternalError();
+            throw new AssertionError("Should not reach here");
         }
         void clearAction() {
             // do nothing
         }
     }
+
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE, getName());
+    }
+
 }
--- a/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -68,7 +68,7 @@
                                             memoryUsageItemValues);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -79,7 +79,7 @@
                 MappedMXBeanType.toOpenType(MemoryUsage.class);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/MonitorInfoCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/MonitorInfoCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -81,7 +81,7 @@
                                             values);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -95,7 +95,7 @@
             monitorInfoItemNames = (String[]) s.toArray(new String[0]);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/NotificationEmitterSupport.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/NotificationEmitterSupport.java	Thu Apr 10 10:47:13 2008 -0700
@@ -156,7 +156,7 @@
                     li.listener.handleNotification(notification, li.handback);
                 } catch (Exception e) {
                     e.printStackTrace();
-                    throw new InternalError("Error in invoking listener");
+                    throw new AssertionError("Error in invoking listener");
                 }
             }
         }
--- a/jdk/src/share/classes/sun/management/OperatingSystemImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/OperatingSystemImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,8 @@
 package sun.management;
 
 import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ManagementFactory;
+import javax.management.ObjectName;
 import sun.misc.Unsafe;
 
 /**
@@ -71,4 +73,9 @@
              return -1.0;
         }
     }
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+    }
+
 }
+
--- a/jdk/src/share/classes/sun/management/RuntimeImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/RuntimeImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,7 @@
 package sun.management;
 
 import java.lang.management.RuntimeMXBean;
+import java.lang.management.ManagementFactory;
 
 import java.util.List;
 import java.util.HashMap;
@@ -38,6 +39,7 @@
 import javax.management.openmbean.OpenType;
 import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.OpenDataException;
+import javax.management.ObjectName;
 
 /**
  * Implementation class for the runtime subsystem.
@@ -104,12 +106,12 @@
             throw new UnsupportedOperationException(
                 "Boot class path mechanism is not supported");
         }
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
         return jvm.getBootClassPath();
     }
 
     public List<String> getInputArguments() {
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
         return jvm.getVmArguments();
     }
 
@@ -145,4 +147,9 @@
 
         return map;
     }
+
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
+    }
+
 }
--- a/jdk/src/share/classes/sun/management/StackTraceElementCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/StackTraceElementCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -76,7 +76,7 @@
                                             stackTraceElementItemValues);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -87,7 +87,7 @@
                 MappedMXBeanType.toOpenType(StackTraceElement.class);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/src/share/classes/sun/management/ThreadImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/ThreadImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,6 +26,7 @@
 package sun.management;
 
 import java.lang.management.ThreadMXBean;
+import java.lang.management.ManagementFactory;
 
 import java.lang.management.ThreadInfo;
 import java.lang.management.LockInfo;
@@ -33,6 +34,8 @@
 import java.util.Map;
 import java.util.HashMap;
 
+import javax.management.ObjectName;
+
 /**
  * Implementation class for the thread subsystem.
  * Standard and committed hotspot-specific metrics if any.
@@ -102,7 +105,7 @@
     }
 
     public long[] getAllThreadIds() {
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
 
         Thread[] threads = getThreads();
         int length = threads.length;
@@ -156,7 +159,7 @@
                 "Invalid maxDepth parameter: " + maxDepth);
         }
 
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
 
         ThreadInfo[] infos = new ThreadInfo[ids.length];
         if (maxDepth == Integer.MAX_VALUE) {
@@ -175,7 +178,7 @@
                 "Thread contention monitoring is not supported");
         }
 
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
 
         synchronized (this) {
             if (contentionMonitoringEnabled != enable) {
@@ -297,7 +300,7 @@
                 "Thread CPU time measurement is not supported");
         }
 
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
         synchronized (this) {
             if (cpuTimeEnabled != enable) {
                 // update VM of the state change
@@ -308,7 +311,7 @@
     }
 
     public long[] findMonitorDeadlockedThreads() {
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
 
         Thread[] threads = findMonitorDeadlockedThreads0();
         if (threads == null) {
@@ -329,7 +332,7 @@
                 "Monitoring of Synchronizer Usage is not supported.");
         }
 
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
 
         Thread[] threads = findDeadlockedThreads0();
         if (threads == null) {
@@ -345,7 +348,7 @@
     }
 
     public void resetPeakThreadCount() {
-        ManagementFactory.checkControlAccess();
+        Util.checkControlAccess();
         resetPeakThreadCount0();
     }
 
@@ -373,7 +376,7 @@
                 "Monitoring of Synchronizer Usage is not supported.");
         }
 
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
         return dumpThreads0(ids, lockedMonitors, lockedSynchronizers);
     }
 
@@ -388,7 +391,7 @@
                 "Monitoring of Synchronizer Usage is not supported.");
         }
 
-        ManagementFactory.checkMonitorAccess();
+        Util.checkMonitorAccess();
         return dumpThreads0(null, lockedMonitors, lockedSynchronizers);
     }
 
@@ -410,4 +413,10 @@
 
     // tid == 0 to reset contention times for all threads
     private static native void resetContentionTimes0(long tid);
+
+    public ObjectName getObjectName() {
+        return Util.newObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
+    }
+
 }
+
--- a/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -126,7 +126,7 @@
                                             threadInfoItemValues);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -209,7 +209,7 @@
                                   v5ItemTypes);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
 
         // Each CompositeData object has its CompositeType associated
--- a/jdk/src/share/classes/sun/management/Util.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/Util.java	Thu Apr 10 10:47:13 2008 -0700
@@ -26,48 +26,58 @@
 package sun.management;
 
 import java.lang.management.*;
+import java.util.List;
+import java.security.Permission;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
 import static java.lang.management.ManagementFactory.*;
-import java.util.List;
 
 class Util {
-    static String getMBeanObjectName(MemoryPoolMXBean pool) {
-        return MEMORY_POOL_MXBEAN_DOMAIN_TYPE +
-            ",name=" + pool.getName();
+    static RuntimeException newException(Exception e) {
+        throw new RuntimeException(e);
+    }
+
+    private static final String[] EMPTY_STRING_ARRAY = new String[0];
+    static String[] toStringArray(List<String> list) {
+        return (String[]) list.toArray(EMPTY_STRING_ARRAY);
+    }
+
+    static ObjectName newObjectName(String name) {
+        return com.sun.jmx.mbeanserver.Util.newObjectName(name);
+    }
+
+    public static ObjectName newObjectName(String domainAndType, String name) {
+        return newObjectName(domainAndType + ",name=" + name);
     }
 
-    static String getMBeanObjectName(MemoryManagerMXBean mgr) {
-        if (mgr instanceof GarbageCollectorMXBean) {
-            return getMBeanObjectName((GarbageCollectorMXBean) mgr);
-        } else {
-            return MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE +
-                ",name=" + mgr.getName();
+    private static ManagementPermission monitorPermission =
+        new ManagementPermission("monitor");
+    private static ManagementPermission controlPermission =
+        new ManagementPermission("control");
+
+    /**
+     * Check that the current context is trusted to perform monitoring
+     * or management.
+     * <p>
+     * If the check fails we throw a SecurityException, otherwise
+     * we return normally.
+     *
+     * @exception  SecurityException  if a security manager exists and if
+     *             the caller does not have ManagementPermission("control").
+     */
+    static void checkAccess(ManagementPermission p)
+         throws SecurityException {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(p);
         }
     }
 
-    static String getMBeanObjectName(GarbageCollectorMXBean gc) {
-        return GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE +
-            ",name=" + gc.getName();
-    }
-
-    static RuntimeException newException(Exception e) {
-        RuntimeException e1 = new RuntimeException(e.getMessage());
-        e1.initCause(e);
-        return e1;
+    static void checkMonitorAccess() throws SecurityException {
+        checkAccess(monitorPermission);
     }
-
-    static InternalError newInternalError(Exception e) {
-        InternalError e1 = new InternalError(e.getMessage());
-        e1.initCause(e);
-        return e1;
-    }
-    static AssertionError newAssertionError(Exception e) {
-        AssertionError e1 = new AssertionError(e.getMessage());
-        e1.initCause(e);
-        return e1;
-    }
-
-    private static String[] EMPTY_STRING_ARRAY = new String[0];
-    static String[] toStringArray(List<String> list) {
-        return (String[]) list.toArray(EMPTY_STRING_ARRAY);
+    static void checkControlAccess() throws SecurityException {
+        checkAccess(controlPermission);
     }
 }
--- a/jdk/src/share/classes/sun/management/VMManagementImpl.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/VMManagementImpl.java	Thu Apr 10 10:47:13 2008 -0700
@@ -59,7 +59,7 @@
     static {
         version = getVersion0();
         if (version == null) {
-            throw new InternalError("Invalid Management Version");
+            throw new AssertionError("Invalid Management Version");
         }
         initOptionalSupportFields();
     }
@@ -244,7 +244,7 @@
             // was set
             noPerfData = true;
         } catch (IOException e) {
-            throw new InternalError(e.getMessage());
+            throw new AssertionError(e);
         }
         return perfInstr;
     }
--- a/jdk/src/share/classes/sun/management/VMOptionCompositeData.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/src/share/classes/sun/management/VMOptionCompositeData.java	Thu Apr 10 10:47:13 2008 -0700
@@ -69,7 +69,7 @@
                                             vmOptionItemValues);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
@@ -80,7 +80,7 @@
                 MappedMXBeanType.toOpenType(VMOption.class);
         } catch (OpenDataException e) {
             // Should never reach here
-            throw Util.newInternalError(e);
+            throw new AssertionError(e);
         }
     }
 
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java	Thu Apr 10 10:47:13 2008 -0700
@@ -29,14 +29,14 @@
  */
 
 import java.lang.management.*;
+import java.util.List;
 import javax.management.MBeanServer;
 import com.sun.management.HotSpotDiagnosticMXBean;
 
 public class DumpHeap {
     public static void main(String[] argv) throws Exception {
-         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-         HotSpotDiagnosticMXBean dm = sun.management.ManagementFactory.getDiagnosticMXBean();
+         List<HotSpotDiagnosticMXBean> list = ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
          System.out.println("Dumping to file: " + argv[0] + " ....");
-         dm.dumpHeap(argv[0], true);
+         list.get(0).dumpHeap(argv[0], true);
     }
 }
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticOptions.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticOptions.java	Thu Apr 10 10:47:13 2008 -0700
@@ -41,8 +41,9 @@
         "com.sun.management:type=HotSpotDiagnostic";
 
     public static void main(String[] args) throws Exception {
-        HotSpotDiagnosticMXBean mbean =
-            sun.management.ManagementFactory.getDiagnosticMXBean();
+        List<HotSpotDiagnosticMXBean> list =
+            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
+        HotSpotDiagnosticMXBean mbean = list.get(0);
         checkDiagnosticOptions(mbean);
 
         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java	Thu Apr 10 10:47:13 2008 -0700
@@ -34,6 +34,7 @@
 import com.sun.management.VMOption;
 import com.sun.management.VMOption.Origin;
 import java.lang.management.ManagementFactory;
+import java.util.List;
 import javax.management.MBeanServer;
 
 public class GetVMOption {
@@ -44,8 +45,9 @@
         "com.sun.management:type=HotSpotDiagnostic";
 
     public static void main(String[] args) throws Exception {
-        HotSpotDiagnosticMXBean mbean =
-            sun.management.ManagementFactory.getDiagnosticMXBean();
+        List<HotSpotDiagnosticMXBean> list =
+            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
+        HotSpotDiagnosticMXBean mbean = list.get(0);
         checkVMOption(mbean);
 
         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java	Thu Apr 10 09:02:22 2008 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java	Thu Apr 10 10:47:13 2008 -0700
@@ -31,11 +31,11 @@
  * @run main/othervm -XX:+PrintGCDetails SetVMOption
  */
 
+import java.lang.management.ManagementFactory;
 import java.util.*;
 import com.sun.management.HotSpotDiagnosticMXBean;
 import com.sun.management.VMOption;
 import com.sun.management.VMOption.Origin;
-import sun.management.ManagementFactory;
 import sun.misc.Version;
 
 public class SetVMOption {
@@ -44,10 +44,11 @@
     private static String BAD_VALUE = "yes";
     private static String NEW_VALUE = "false";
     private static String MANAGEMENT_SERVER = "ManagementServer";
-    private static HotSpotDiagnosticMXBean mbean =
-        ManagementFactory.getDiagnosticMXBean();
+    private static HotSpotDiagnosticMXBean mbean;
 
     public static void main(String[] args) throws Exception {
+        List<HotSpotDiagnosticMXBean> list =
+            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
 
         // The following test is transitional only and should be removed
         // once build 52 is promoted.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/management/ManagementFactory/GetPlatformMXBeans.java	Thu Apr 10 10:47:13 2008 -0700
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6610094
+ * @summary Basic unit test of ManagementFactory.getPlatformMXBeans()
+ *          and also PlatformManagedObject.getObjectName()
+ * @author  Mandy Chung
+ *
+ * @run main GetPlatformMXBeans
+ */
+
+import java.lang.management.*;
+import static java.lang.management.ManagementFactory.*;
+import java.util.*;
+import javax.management.*;
+
+public class GetPlatformMXBeans {
+    private static MBeanServer platformMBeanServer =
+            getPlatformMBeanServer();
+    public static void main(String[] argv) throws Exception {
+        checkPlatformMXBean(getClassLoadingMXBean(),
+                            ClassLoadingMXBean.class,
+                            CLASS_LOADING_MXBEAN_NAME);
+        checkPlatformMXBean(getCompilationMXBean(),
+                            CompilationMXBean.class,
+                            COMPILATION_MXBEAN_NAME);
+        checkPlatformMXBean(getMemoryMXBean(),
+                            MemoryMXBean.class,
+                            MEMORY_MXBEAN_NAME);
+        checkPlatformMXBean(getOperatingSystemMXBean(),
+                            OperatingSystemMXBean.class,
+                            OPERATING_SYSTEM_MXBEAN_NAME);
+        checkPlatformMXBean(getRuntimeMXBean(),
+                            RuntimeMXBean.class,
+                            RUNTIME_MXBEAN_NAME);
+        checkPlatformMXBean(getThreadMXBean(),
+                            ThreadMXBean.class,
+                            THREAD_MXBEAN_NAME);
+        checkGarbageCollectorMXBeans(getGarbageCollectorMXBeans());
+        checkMemoryManagerMXBeans(getMemoryManagerMXBeans());
+        checkMemoryPoolMXBeans(getMemoryPoolMXBeans());
+    }
+
+    private static <T extends PlatformManagedObject>
+        void checkPlatformMXBean(T obj, Class<T> mxbeanInterface,
+                                 String mxbeanName) throws Exception
+    {
+        int numElements = (obj != null ? 1 : 0);
+        // verify local list of platform MXBeans
+        List<? extends PlatformManagedObject> mxbeans =
+            getPlatformMXBeans(mxbeanInterface);
+        if (mxbeans.size() != numElements) {
+            throw new RuntimeException("Unmatched number of platform MXBeans "
+                + mxbeans.size() + ". Expected = " + numElements);
+        }
+
+        if (obj != null) {
+            PlatformManagedObject pmo = mxbeans.get(0);
+            if (obj != pmo) {
+                throw new RuntimeException("The list returned by getPlatformMXBeans"
+                    + " not matched");
+            }
+            ObjectName on = new ObjectName(mxbeanName);
+            if (!on.equals(pmo.getObjectName())) {
+                throw new RuntimeException("Unmatched ObjectName " +
+                    pmo.getObjectName() + " Expected = " + on);
+            }
+        }
+
+        // verify platform MXBeans in the platform MBeanServer
+        mxbeans = getPlatformMXBeans(platformMBeanServer, mxbeanInterface);
+        if (mxbeans.size() != numElements) {
+            throw new RuntimeException("Unmatched number of platform MXBeans "
+                + mxbeans.size() + ". Expected = " + numElements);
+        }
+    }
+
+    private static void checkMemoryManagerMXBeans(List<MemoryManagerMXBean> objs)
+        throws Exception
+    {
+        checkPlatformMXBeans(objs, MemoryManagerMXBean.class);
+        for (MemoryManagerMXBean mxbean : objs) {
+            String domainAndType;
+            if (mxbean instanceof GarbageCollectorMXBean) {
+                domainAndType = GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE;
+            } else {
+                domainAndType = MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE;
+            }
+            ObjectName on = new ObjectName(domainAndType +
+                                           ",name=" + mxbean.getName());
+            if (!on.equals(mxbean.getObjectName())) {
+                throw new RuntimeException("Unmatched ObjectName " +
+                    mxbean.getObjectName() + " Expected = " + on);
+            }
+        }
+    }
+    private static void checkMemoryPoolMXBeans(List<MemoryPoolMXBean> objs)
+        throws Exception
+    {
+        checkPlatformMXBeans(objs, MemoryPoolMXBean.class);
+        for (MemoryPoolMXBean mxbean : objs) {
+            ObjectName on = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE +
+                                           ",name=" + mxbean.getName());
+            if (!on.equals(mxbean.getObjectName())) {
+                throw new RuntimeException("Unmatched ObjectName " +
+                    mxbean.getObjectName() + " Expected = " + on);
+            }
+        }
+    }
+
+    private static void checkGarbageCollectorMXBeans(List<GarbageCollectorMXBean> objs)
+        throws Exception
+    {
+        checkPlatformMXBeans(objs, GarbageCollectorMXBean.class);
+        for (GarbageCollectorMXBean mxbean : objs) {
+            ObjectName on = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE +
+                                           ",name=" + mxbean.getName());
+            if (!on.equals(mxbean.getObjectName())) {
+                throw new RuntimeException("Unmatched ObjectName " +
+                    mxbean.getObjectName() + " Expected = " + on);
+            }
+        }
+    }
+
+    private static <T extends PlatformManagedObject>
+        void checkPlatformMXBeans(List<T> objs, Class<T> mxbeanInterface)
+            throws Exception
+    {
+        // verify local list of platform MXBeans
+        List<? extends PlatformManagedObject> mxbeans =
+            getPlatformMXBeans(mxbeanInterface);
+        if (objs.size() != mxbeans.size()) {
+            throw new RuntimeException("Unmatched number of platform MXBeans "
+                + mxbeans.size() + ". Expected = " + objs.size());
+        }
+        List<T> list = new ArrayList<T>(objs);
+        for (PlatformManagedObject pmo : mxbeans) {
+            if (list.contains(pmo)) {
+                list.remove(pmo);
+            } else {
+                throw new RuntimeException(pmo +
+                    " not in the platform MXBean list");
+            }
+        }
+
+        if (!list.isEmpty()) {
+            throw new RuntimeException("The list returned by getPlatformMXBeans"
+                + " not matched");
+        }
+
+        // verify platform MXBeans in the platform MBeanServer
+        mxbeans = getPlatformMXBeans(platformMBeanServer, mxbeanInterface);
+        if (objs.size() != mxbeans.size()) {
+            throw new RuntimeException("Unmatched number of platform MXBeans "
+                + mxbeans.size() + ". Expected = " + objs.size());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/management/OperatingSystemMXBean/PlatformMXBeanTest.java	Thu Apr 10 10:47:13 2008 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6610094
+ * @summary Test the OperatingSystemMXBean instance returned by
+ *          ManagementFactory.getPlatformMXBeans()
+ * @author  Mandy Chung
+ *
+ * @run main PlatformMXBeanTest
+ */
+
+import java.lang.management.*;
+import java.util.List;
+
+public class PlatformMXBeanTest {
+    public static void main(String[] argv) throws Exception {
+        OperatingSystemMXBean osMBean = getOSPlatformMXBean(OperatingSystemMXBean.class);
+
+        // There should have only one single MXBean for the OS MXBean interfaces:
+        //   java.lang.management.OperatingSystemMXBean
+        //   com.sun.management.OperatingSystemMXBean
+        //   com.sun.management.UnixOperatingSystemMXBean
+        if (osMBean != getOSPlatformMXBean(com.sun.management.OperatingSystemMXBean.class)) {
+            throw new RuntimeException(
+                "Invalid com.sun.management.OperatingSystemMXBean instance");
+        }
+
+        if (!System.getProperty("os.name").startsWith("Windows") &&
+                osMBean != getOSPlatformMXBean(com.sun.management.UnixOperatingSystemMXBean.class)) {
+            throw new RuntimeException(
+                "Invalid com.sun.management.UnixOperatingSystemMXBean instance");
+        }
+    }
+
+    private static <T extends OperatingSystemMXBean>
+            T getOSPlatformMXBean(Class<T> c) {
+        List<T> result = ManagementFactory.getPlatformMXBeans(c);
+        if (result.isEmpty()) {
+            return null;
+        } else if (result.size() == 1) {
+            return result.get(0);
+        } else {
+            throw new RuntimeException(c.getName() + " has " +
+                result.size() + " number of instances");
+        }
+    }
+}