The attached patch adds the class loading management bean
interface and an appropriate GNU implementation.  This adds
four new VM methods to provide the necessary information.
Any comments on these are welcomed, especially if there is
a way some can be avoided.

Changelog:

2006-06-24  Andrew John Hughes  <[EMAIL PROTECTED]>

        * NEWS,
        * doc/vmintegration.texinfo:
        Updated with information on new VM interface.
        * gnu/java/lang/management/ClassLoadingMXBeanImpl.java,
        * java/lang/management/ClassLoadingMXBean.java:
        New files implementing the class loading bean.
        * java/lang/management/ManagementFactory.java:
        (getClassLoadingMXBean()): Implemented.
        * vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java:
        New VM interface file.

-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: NEWS
===================================================================
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.151
diff -u -3 -p -u -r1.151 NEWS
--- NEWS        19 Jun 2006 12:22:42 -0000      1.151
+++ NEWS        25 Jun 2006 00:47:42 -0000
@@ -38,7 +38,7 @@ Runtime interface changes:
 * The method gnu.java.io.PlatformHelper.toCanonicalForm() has been
   replaced with a JNI implementation of VMFile.toCanonicalForm() for
   GNU/Posix systems.
-* An new class, VMRuntimeMXBeanImpl, is used to implement
+* A new class, VMRuntimeMXBeanImpl, is used to implement
   the low-level support of the runtime management bean.
   VMs should use it to supply the input arguments and start
   time of the VM.  In addition, one of sun.boot.class.path
@@ -48,6 +48,12 @@ Runtime interface changes:
   reference implementation.  We've also added a couple other new VM
   classes to support the JSR 166 code -- sun.reflect.Reflection and
   sun.reflect.misc.ReflectUtil.
+* Another new class, VMClassLoadingMXBeanImpl, is used to implement
+  the low-level support of the class loading management bean.
+  VMs need to supply it with information about how many classes
+  are currently loaded, how many have been unloaded and whether
+  verbose class loading output is on or off.  Provision should also
+  be made for the latter to be toggled at runtime.
 
 New in release 0.91 (May 15, 2006)
 
Index: doc/vmintegration.texinfo
===================================================================
RCS file: /cvsroot/classpath/classpath/doc/vmintegration.texinfo,v
retrieving revision 1.29
diff -u -3 -p -u -r1.29 vmintegration.texinfo
--- doc/vmintegration.texinfo   11 Jun 2006 21:57:15 -0000      1.29
+++ doc/vmintegration.texinfo   25 Jun 2006 00:47:43 -0000
@@ -1267,9 +1267,10 @@ implementations of the management beans.
 
 @menu
 * gnu.java.lang.management.VMRuntimeMXBeanImpl::
+* gnu.java.lang.management.VMClassLoadingMXBeanImpl::
 @end menu
 
[EMAIL PROTECTED] 
gnu.java.lang.management.VMRuntimeMXBeanImpl,,,gnu.java.lang.management
[EMAIL PROTECTED] 
gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management
 @subsection @code{gnu.java.lang.management.VMRuntimeMXBeanImpl}
 
 The @code{gnu.java.lang.management.RuntimeMXBeanImpl} provides an
@@ -1311,6 +1312,33 @@ The virtual machine also needs to provid
 property in order to support the optional boot class path
 retrieval functionality.
 
[EMAIL PROTECTED] 
gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management
[EMAIL PROTECTED] @code{gnu.java.lang.management.VMClassLoadingMXBeanImpl}
+
+The @code{gnu.java.lang.management.ClassLoadingMXBeanImpl} provides an
+implementation of the @code{java.lang.management.ClassLoadingMXBean} interface,
+and is supported by VM functionality in the form of
[EMAIL PROTECTED]  This provides a
+series of methods, which should be implemented by the virtual machine
+in order to provide the required information for the bean.  Implementing
+this bean requires the VM to monitor when classes are loaded and unloaded,
+and provide the option of verbose class loading output.
+
+The methods are as follows:
+
[EMAIL PROTECTED] @bullet
[EMAIL PROTECTED] @code{(getLoadedClassCount())} -- This should return
+the number of classes that are currently loaded by the VM.
[EMAIL PROTECTED] @code{(getUnloadedClassCount())} -- This should return
+the number of classes that have been loaded by the VM, but
+have since been unloaded.
[EMAIL PROTECTED] @code{(isVerbose())} -- This should return @code{true}
+or @code{false}, depending on whether verbose class loading
+output is turned or not, respectively.
[EMAIL PROTECTED] @code{(setVerbose(boolean))} -- This should allow the
+verbose class loading output to be turned on and off.
[EMAIL PROTECTED] itemize
+
 @node Classpath Callbacks, , gnu.java.lang.management, Classpath Hooks
 Some of the classes you implement for the VM will need to call back to
 package-private methods in Classpath:
Index: gnu/java/lang/management/ClassLoadingMXBeanImpl.java
===================================================================
RCS file: gnu/java/lang/management/ClassLoadingMXBeanImpl.java
diff -N gnu/java/lang/management/ClassLoadingMXBeanImpl.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/java/lang/management/ClassLoadingMXBeanImpl.java        25 Jun 2006 
00:47:43 -0000
@@ -0,0 +1,85 @@
+/* ClassLoadingMXBeanImpl.java - Implementation of a class loading bean
+   Copyright (C) 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.lang.management;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementPermission;
+
+/**
+ * Provides access to information about the class loading 
+ * behaviour of the current invocation of the virtual
+ * machine.  Instances of this bean are obtained by calling
+ * [EMAIL PROTECTED] ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public final class ClassLoadingMXBeanImpl
+  implements ClassLoadingMXBean
+{
+
+  public int getLoadedClassCount()
+  {
+    return VMClassLoadingMXBeanImpl.getLoadedClassCount();
+  }
+
+  public int getTotalLoadedClassCount()
+  {
+    return getLoadedClassCount() + getUnloadedClassCount();
+  }
+
+  public int getUnloadedClassCount()
+  {
+    return VMClassLoadingMXBeanImpl.getUnloadedClassCount();
+  }
+
+  public boolean isVerbose()
+  {
+    return VMClassLoadingMXBeanImpl.isVerbose();
+  }
+
+  public void setVerbose(boolean verbose)
+  {
+    SecurityManager sm = System.getSecurityManager();
+    if (sm != null)
+      sm.checkPermission(new ManagementPermission("control"));
+    VMClassLoadingMXBeanImpl.setVerbose(verbose);
+  }
+
+}
+
Index: java/lang/management/ClassLoadingMXBean.java
===================================================================
RCS file: java/lang/management/ClassLoadingMXBean.java
diff -N java/lang/management/ClassLoadingMXBean.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ java/lang/management/ClassLoadingMXBean.java        25 Jun 2006 00:47:43 
-0000
@@ -0,0 +1,103 @@
+/* ClassLoadingMXBean.java - Interface for a class loading bean
+   Copyright (C) 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.lang.management;
+
+/**
+ * Provides access to information about the class loading 
+ * behaviour of the current invocation of the virtual
+ * machine.  Instances of this bean are obtained by calling
+ * [EMAIL PROTECTED] ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public interface ClassLoadingMXBean
+{
+
+  /**
+   * Returns the number of classes currently loaded by
+   * the virtual machine.
+   *
+   * @return the number of loaded classes.
+   */
+  int getLoadedClassCount();
+
+  /**
+   * Returns the total number of classes loaded by the
+   * virtual machine since it was started.  This is the
+   * sum of the currently loaded classes and those that
+   * have been unloaded.
+   *
+   * @return the total number of classes that have been
+   *         loaded by the virtual machine since it started.
+   */
+  int getTotalLoadedClassCount();
+
+  /**
+   * Returns the number of classes that have been unloaded
+   * by the virtual machine since it was started.
+   *
+   * @return the number of unloaded classes.
+   */
+  int getUnloadedClassCount();
+
+  /**
+   * Returns true if the virtual machine will emit additional
+   * information when classes are loaded and unloaded.  The
+   * format of the output is left up to the virtual machine.
+   *
+   * @return true if verbose class loading output is on.
+   */
+  boolean isVerbose();
+
+  /**
+   * Turns on or off the emission of additional information
+   * when classes are loaded and unloaded.  The format of the
+   * output is left up to the virtual machine.  This method
+   * may be called by multiple threads concurrently, but there
+   * is only one global setting of verbosity that is affected.
+   *
+   * @param verbose the new setting for verbose class loading
+   *                output.
+   * @throws SecurityException if a security manager exists and
+   *                           denies ManagementPermission("control").
+   */
+  void setVerbose(boolean verbose);
+
+}
+
Index: java/lang/management/ManagementFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/lang/management/ManagementFactory.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 ManagementFactory.java
--- java/lang/management/ManagementFactory.java 15 Jun 2006 17:12:51 -0000      
1.3
+++ java/lang/management/ManagementFactory.java 25 Jun 2006 00:47:43 -0000
@@ -37,6 +37,7 @@ exception statement from your version. *
 
 package java.lang.management;
 
+import gnu.java.lang.management.ClassLoadingMXBeanImpl;
 import gnu.java.lang.management.OperatingSystemMXBeanImpl;
 import gnu.java.lang.management.RuntimeMXBeanImpl;
 
@@ -71,6 +72,11 @@ public class ManagementFactory
   private static RuntimeMXBean runtimeBean;
 
   /**
+   * The class loading management bean.
+   */
+  private static ClassLoadingMXBean classLoadingBean;
+
+  /**
    * Private constructor to prevent instance creation.
    */
   private ManagementFactory() {}
@@ -103,4 +109,18 @@ public class ManagementFactory
     return runtimeBean;
   }
 
+  /**
+   * Returns the class loading management bean for the
+   * running virtual machine.
+   *
+   * @return an instance of [EMAIL PROTECTED] ClassLoadingMXBean} for
+   *         this virtual machine.
+   */
+  public static ClassLoadingMXBean getClassLoadingMXBean()
+  {
+    if (classLoadingBean == null)
+      classLoadingBean = new ClassLoadingMXBeanImpl();
+    return classLoadingBean;
+  }
+  
 }
Index: vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java
===================================================================
RCS file: vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java
diff -N vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ vm/reference/gnu/java/lang/management/VMClassLoadingMXBeanImpl.java 25 Jun 
2006 00:47:44 -0000
@@ -0,0 +1,89 @@
+/* VMClassLoadingMXBeanImpl.java - VM impl. of a class loading bean
+   Copyright (C) 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.lang.management;
+
+/**
+ * Provides access to information about the class loading 
+ * behaviour of the current invocation of the virtual
+ * machine.  Instances of this bean are obtained by calling
+ * [EMAIL PROTECTED] ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+final class VMClassLoadingMXBeanImpl
+{
+
+  /**
+   * Returns the number of classes currently loaded by
+   * the virtual machine.
+   *
+   * @return the number of loaded classes.
+   */
+  static native int getLoadedClassCount();
+
+  /**
+   * Returns the number of classes that have been unloaded
+   * by the virtual machine since it was started.
+   *
+   * @return the number of unloaded classes.
+   */
+  static native int getUnloadedClassCount();
+
+  /**
+   * Returns true if the virtual machine will emit additional
+   * information when classes are loaded and unloaded.  The
+   * format of the output is left up to the virtual machine.
+   *
+   * @return true if verbose class loading output is on.
+   */
+  static native boolean isVerbose();
+
+  /**
+   * Turns on or off the emission of additional information
+   * when classes are loaded and unloaded.  The format of the
+   * output is left up to the virtual machine.  This method
+   * may be called by multiple threads concurrently, but there
+   * is only one global setting of verbosity that is affected.
+   *
+   * @param verbose the new setting for verbose class loading
+   *                output.
+   */
+  static native void setVerbose(boolean verbose);
+
+}

Attachment: signature.asc
Description: Digital signature

Reply via email to