This adds the optional compilation MX bean.  It relies on two
properties:

* gnu.java.compiler.name
* gnu.java.lang.management.CompilationTimeSupport

The former is the name of the JIT compiler.  If this is non-null,
a bean is created and supplied on calls to the appropriate
ManagementFactory method.  Its getName() method returns the value.

If the VM also wants to support timing compilations, it should
set the second of these properties and provide the
VMCompilationMXBeanImpl interface.

Changelog:

2006-07-02  Andrew John Hughes  <[EMAIL PROTECTED]>

        * NEWS:
        Updated to include VMCompilationMXBeanImpl.
        * doc/vmintegration.texinfo:
        Likewise, along with update to VMMemoryMXBeanImpl
        as below.
        * examples/gnu/classpath/examples/management/TestCompilation.java,
        * gnu/java/lang/management/CompilationMXBeanImpl.java,
        * java/lang/management/CompilationMXBeanImpl.java:
        New files.
        * java/lang/management/ManagementFactory.java:
        (getCompilationMXBean()): Implemented.
        * vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java:
        New file.
        * vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java:
        (getHeapMemoryUsage()): Added default implementation.   


-- 
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.155
diff -u -3 -p -u -r1.155 NEWS
--- NEWS        2 Jul 2006 18:21:49 -0000       1.155
+++ NEWS        2 Jul 2006 20:19:39 -0000
@@ -67,6 +67,8 @@ Runtime interface changes:
   of the memory management bean.  Providing this interface requires
   providing information about the levels of heap and non-heap memory,
   and the number of objects eligible for garbage collection.
+* VMCompilationMXBeanImpl is used to allow for optional compilation
+  time support for Just-In-Time compilers.
 
 New in release 0.91 (May 15, 2006)
 
Index: doc/vmintegration.texinfo
===================================================================
RCS file: /cvsroot/classpath/classpath/doc/vmintegration.texinfo,v
retrieving revision 1.32
diff -u -3 -p -u -r1.32 vmintegration.texinfo
--- doc/vmintegration.texinfo   2 Jul 2006 17:29:10 -0000       1.32
+++ doc/vmintegration.texinfo   2 Jul 2006 20:19:40 -0000
@@ -1273,6 +1273,7 @@ implementations of the management beans.
 * gnu.java.lang.management.VMClassLoadingMXBeanImpl::
 * gnu.java.lang.management.VMThreadMXBeanImpl::
 * gnu.java.lang.management.VMMemoryMXBeanImpl::
+* gnu.java.lang.management.VMCompilationMXBeanImpl::
 @end menu
 
 @node 
gnu.java.lang.management.VMRuntimeMXBeanImpl,gnu.java.lang.management.VMClassLoadingMXBeanImpl,,gnu.java.lang.management
@@ -1435,7 +1436,7 @@ that have died.  This is specified as a 
 implementation.
 @end itemize
 
[EMAIL PROTECTED] 
gnu.java.lang.management.VMMemoryMXBeanImpl,,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management
[EMAIL PROTECTED] 
gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management.VMCompilationMXBeanImpl,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management
 @subsection @code{gnu.java.lang.management.VMMemoryMXBeanImpl}
 
 The @code{gnu.java.lang.management.MemoryMXBeanImpl} provides an
@@ -1453,7 +1454,8 @@ The methods are as follows:
 @itemize @bullet
 @item @code{(getHeapMemoryUsage())} -- This should return
 an instance of @code{java.lang.management.MemoryUsage} with
-values pertaining to the heap.
+values pertaining to the heap.  A default implementation is
+provided, based on @code{java.lang.Runtime}'s methods.
 @item @code{(getNonHeapMemoryUsage())} -- This should return
 an instance of @code{java.lang.management.MemoryUsage} with
 values pertaining to non-heap memory.
@@ -1468,6 +1470,39 @@ output is turned or not, respectively.
 verbose memory management output to be turned on and off.
 @end itemize
 
[EMAIL PROTECTED] 
gnu.java.lang.management.VMCompilationMXBeanImpl,,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management
[EMAIL PROTECTED] @code{gnu.java.lang.management.VMCompilationMXBeanImpl}
+
+The @code{gnu.java.lang.management.CompilationMXBeanImpl} provides an
+implementation of the optional @code{java.lang.management.CompilationMXBean}
+interface, and is supported by VM functionality in the form of
[EMAIL PROTECTED]  This provides a
+single method for returning the number of milliseconds the virtual
+machine's Just-In-Time (JIT) compiler has spent compiling.  Even if
+a JIT compiler is available and an instance of the bean supplied, this
+method is still optional.
+
+Optional support is determined by the following properties:
+
[EMAIL PROTECTED] @bullet
[EMAIL PROTECTED] @code{gnu.java.lang.compiler.name} -- This property should
+specify the name of the JIT compiler.  Classpath also uses this,
+within @code{java.lang.management.ManagementFactory}, to determine
+whether a bean should be created.  If this property is set to a
+non-null value, a bean will be created and its @code{getName()}
+method will return this value.
[EMAIL PROTECTED] @code{gnu.java.lang.management.CompilationTimeSupport} --
+This property should be present if the VM supports monitoring the
+time spent compiling.
[EMAIL PROTECTED] itemize
+
+Time support is implemented by the following method:
+
[EMAIL PROTECTED] @bullet
[EMAIL PROTECTED] @code{(getTotalCompilationTime())} -- This should return the
+number of milliseconds the JIT compiler has spent compiling.
[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: examples/gnu/classpath/examples/management/TestCompilation.java
===================================================================
RCS file: examples/gnu/classpath/examples/management/TestCompilation.java
diff -N examples/gnu/classpath/examples/management/TestCompilation.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/management/TestCompilation.java     2 Jul 
2006 20:19:40 -0000
@@ -0,0 +1,48 @@
+/* TestCompilation.java -- Tests the compilation bean.
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+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. */
+
+package gnu.classpath.examples.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.CompilationMXBean;
+
+public class TestCompilation
+{
+
+  public static void main(String[] args)
+  {
+    CompilationMXBean bean = ManagementFactory.getCompilationMXBean();
+    if (bean == null)
+      {
+       System.out.println("The compilation bean is not supported by this VM.");
+       System.exit(-1);
+      }
+    System.out.println("Bean: " + bean);
+    System.out.println("JIT compiler name: " + bean.getName());
+    boolean timeMonitoring = bean.isCompilationTimeMonitoringSupported();
+    System.out.println("Compilation time monitoring supported: " + 
timeMonitoring);
+    if (timeMonitoring)
+      {
+       System.out.println("Compilation time: "
+                          + bean.getTotalCompilationTime() + "ms");
+      }
+  }
+
+}
Index: gnu/java/lang/management/CompilationMXBeanImpl.java
===================================================================
RCS file: gnu/java/lang/management/CompilationMXBeanImpl.java
diff -N gnu/java/lang/management/CompilationMXBeanImpl.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/java/lang/management/CompilationMXBeanImpl.java 2 Jul 2006 20:19:41 
-0000
@@ -0,0 +1,89 @@
+/* CompilationMXBeanImpl.java - Implementation of a compilation 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 gnu.classpath.SystemProperties;
+
+import java.lang.management.CompilationMXBean;
+
+/**
+ * Provides access to information about the JIT 
+ * compiler of the virtual machine, if one exists.
+ * Instances of this bean are obtained by calling
+ * [EMAIL PROTECTED] ManagementFactory#getCompilationMXBean()},
+ * if this is the case.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public final class CompilationMXBeanImpl
+  extends BeanImpl
+  implements CompilationMXBean
+{
+
+  /**
+   * Constant for compiler name.
+   */
+  private static final String COMPILER_NAME = "gnu.java.compiler.name";
+
+  /**
+   * Constant for compilation time support.
+   */
+  private static final String COMPILATION_TIME_SUPPORT = 
+    "gnu.java.lang.management.CompilationTimeSupport";
+
+  public String getName()
+  {
+    return SystemProperties.getProperty(COMPILER_NAME);
+  }
+  
+  public boolean isCompilationTimeMonitoringSupported()
+  {
+    return SystemProperties.getProperty(COMPILATION_TIME_SUPPORT) != null;
+  }
+
+  public long getTotalCompilationTime()
+  {
+    if (isCompilationTimeMonitoringSupported())
+      return VMCompilationMXBeanImpl.getTotalCompilationTime();
+    else
+      throw new UnsupportedOperationException("Compilation time monitoring "
+                                             + "is not supported");
+  }
+
+}
Index: java/lang/management/CompilationMXBean.java
===================================================================
RCS file: java/lang/management/CompilationMXBean.java
diff -N java/lang/management/CompilationMXBean.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ java/lang/management/CompilationMXBean.java 2 Jul 2006 20:19:42 -0000
@@ -0,0 +1,85 @@
+/* CompilationMXBean.java - Interface for a compilation 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 Just-In-Time
+ * (JIT) compiler provided by the virtual machine, if one
+ * exists.  An instance of this bean is obtainable by
+ * calling [EMAIL PROTECTED] ManagementFactory#getCompilationMXBean()}
+ * if a JIT is available.  Otherwise, the method returns
+ * <code>null</code>.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public interface CompilationMXBean
+{
+  
+  /**
+   * Returns the name of the Just-In-Time (JIT) compiler.
+   *
+   * @return the name of the JIT compiler.
+   */
+  String getName();
+
+  /**
+   * Returns true if the virtual machine's JIT compiler
+   * supports monitoring of the time spent compiling.
+   *
+   * @return true if the JIT compiler can be monitored
+   *         for time spent compiling.
+   */
+  boolean isCompilationTimeMonitoringSupported();
+
+  /**
+   * Returns the accumulated time, in milliseconds, that
+   * the JIT compiler has spent compiling Java bytecodes
+   * to native machine code.  This value represents a single
+   * time measurement for the whole virtual machine, including
+   * all multiple threads of operation.  The value is not
+   * intended as a performance measurement.
+   *
+   * @return the accumulated number of milliseconds the JIT
+   *         compiler has spent compiling.
+   * @throws UnsupportedOperationException if time monitoring
+   *                                       is not supported.
+   */
+  long getTotalCompilationTime();
+
+}
Index: java/lang/management/ManagementFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/lang/management/ManagementFactory.java,v
retrieving revision 1.7
diff -u -3 -p -u -r1.7 ManagementFactory.java
--- java/lang/management/ManagementFactory.java 2 Jul 2006 17:29:10 -0000       
1.7
+++ java/lang/management/ManagementFactory.java 2 Jul 2006 20:19:42 -0000
@@ -37,7 +37,10 @@ exception statement from your version. *
 
 package java.lang.management;
 
+import gnu.classpath.SystemProperties;
+
 import gnu.java.lang.management.ClassLoadingMXBeanImpl;
+import gnu.java.lang.management.CompilationMXBeanImpl;
 import gnu.java.lang.management.OperatingSystemMXBeanImpl;
 import gnu.java.lang.management.MemoryMXBeanImpl;
 import gnu.java.lang.management.RuntimeMXBeanImpl;
@@ -89,6 +92,11 @@ public class ManagementFactory
   private static MemoryMXBean memoryBean;
 
   /**
+   * The compilation bean (may remain null).
+   */
+  private static CompilationMXBean compilationBean;
+
+  /**
    * Private constructor to prevent instance creation.
    */
   private ManagementFactory() {}
@@ -163,4 +171,22 @@ public class ManagementFactory
     return memoryBean;
   }
 
+  /**
+   * Returns the compilation bean for the running
+   * virtual machine, if supported.  Otherwise,
+   * it returns <code>null</code>.
+   *
+   * @return an instance of [EMAIL PROTECTED] CompilationMXBean} for
+   *         this virtual machine, or <code>null</code>
+   *         if the virtual machine doesn't include
+   *         a Just-In-Time (JIT) compiler.
+   */
+  public static CompilationMXBean getCompilationMXBean()
+  {
+    if (compilationBean == null &&
+       SystemProperties.getProperty("gnu.java.compiler.name") != null)
+      compilationBean = new CompilationMXBeanImpl();
+    return compilationBean;
+  }
+
 }
Index: vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java
===================================================================
RCS file: vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java
diff -N vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java  2 Jul 
2006 20:19:44 -0000
@@ -0,0 +1,66 @@
+/* VMCompilationMXBeanImpl.java - VM implementation of a compilation 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 JIT 
+ * compiler of the virtual machine, if one exists.
+ * Instances of this bean are obtained by calling
+ * [EMAIL PROTECTED] ManagementFactory#getCompilationMXBean()},
+ * if this is the case.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+final class VMCompilationMXBeanImpl
+{
+
+  /**
+   * Returns the number of milliseconds the JIT
+   * compiler has spent compiling Java bytecode
+   * to native machine code.  This is only called
+   * if a JIT compiler exists and the
+   * gnu.java.lang.management.CompilationTimeSupport
+   * property has been set.
+   *
+   * @return the number of milliseconds spent
+   *         compiling.
+   */
+  static native long getTotalCompilationTime();
+
+}
Index: vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 VMMemoryMXBeanImpl.java
--- vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java       2 Jul 
2006 17:29:10 -0000       1.1
+++ vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java       2 Jul 
2006 20:19:44 -0000
@@ -54,12 +54,19 @@ final class VMMemoryMXBeanImpl
   /**
    * Returns an instance of [EMAIL PROTECTED] java.lang.management.MemoryUsage}
    * with appropriate initial, used, committed and maximum values
-   * for the heap.
+   * for the heap.  By default, this uses the methods of
+   * [EMAIL PROTECTED] java.lang.Runtime} to provide some of the values.
    *
    * @return an [EMAIL PROTECTED] java.lang.management.MemoryUsage} instance
    *         for the heap.
    */
-  static native MemoryUsage getHeapMemoryUsage();
+  static MemoryUsage getHeapMemoryUsage()
+  {
+    Runtime runtime = Runtime.getRuntime();
+    long totalMem = runtime.totalMemory();
+    return new MemoryUsage(-1, totalMem - runtime.freeMemory(),
+                          totalMem, runtime.maxMemory());
+  }
 
   /**
    * Returns an instance of [EMAIL PROTECTED] java.lang.management.MemoryUsage}

Attachment: signature.asc
Description: Digital signature

Reply via email to