summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-07-02 20:32:43 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-07-02 20:32:43 +0000
commit7db081cf4c4d514b73cb4567b841dbaacee7baa1 (patch)
treeec407bb3413d1d1f2a049b61098630faeb7e1d97
parent83c52f939a1ebcd235e0c7d12953005e4aeb060a (diff)
downloadclasspath-7db081cf4c4d514b73cb4567b841dbaacee7baa1.tar.gz
2006-07-02 Andrew John Hughes <gnu_andrew@member.fsf.org>generics-merge-20060702
* 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.
-rw-r--r--ChangeLog18
-rw-r--r--NEWS2
-rw-r--r--doc/vmintegration.texinfo39
-rw-r--r--examples/gnu/classpath/examples/management/TestCompilation.java48
-rw-r--r--gnu/java/lang/management/CompilationMXBeanImpl.java89
-rw-r--r--java/lang/management/CompilationMXBean.java85
-rw-r--r--java/lang/management/ManagementFactory.java26
-rw-r--r--vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java66
-rw-r--r--vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java11
9 files changed, 380 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index fdff5e3a3..b878750a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2006-07-02 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * 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.
+
2006-07-02 Anthony Green <green@redhat.com>
* NEWS: Mention MIDI file reader/writer providers.
diff --git a/NEWS b/NEWS
index 9844015c4..b0658e135 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/doc/vmintegration.texinfo b/doc/vmintegration.texinfo
index f4c87c5fe..d1e253696 100644
--- a/doc/vmintegration.texinfo
+++ b/doc/vmintegration.texinfo
@@ -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 native method in the reference
implementation.
@end itemize
-@node gnu.java.lang.management.VMMemoryMXBeanImpl,,gnu.java.lang.management.VMThreadMXBeanImpl,gnu.java.lang.management
+@node 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
+@node gnu.java.lang.management.VMCompilationMXBeanImpl,,gnu.java.lang.management.VMMemoryMXBeanImpl,gnu.java.lang.management
+@subsection @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
+@code{gnu.java.lang.management.VMCompilatinMXBeanImpl}. 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:
+
+@itemize @bullet
+@item @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.
+@item @code{gnu.java.lang.management.CompilationTimeSupport} --
+This property should be present if the VM supports monitoring the
+time spent compiling.
+@end itemize
+
+Time support is implemented by the following method:
+
+@itemize @bullet
+@item @code{(getTotalCompilationTime())} -- This should return the
+number of milliseconds the JIT compiler has spent compiling.
+@end 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:
diff --git a/examples/gnu/classpath/examples/management/TestCompilation.java b/examples/gnu/classpath/examples/management/TestCompilation.java
new file mode 100644
index 000000000..ea8f45f6d
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestCompilation.java
@@ -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");
+ }
+ }
+
+}
diff --git a/gnu/java/lang/management/CompilationMXBeanImpl.java b/gnu/java/lang/management/CompilationMXBeanImpl.java
new file mode 100644
index 000000000..044150fae
--- /dev/null
+++ b/gnu/java/lang/management/CompilationMXBeanImpl.java
@@ -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
+ * {@link ManagementFactory#getCompilationMXBean()},
+ * if this is the case.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @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");
+ }
+
+}
diff --git a/java/lang/management/CompilationMXBean.java b/java/lang/management/CompilationMXBean.java
new file mode 100644
index 000000000..7f666f2c6
--- /dev/null
+++ b/java/lang/management/CompilationMXBean.java
@@ -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 {@link ManagementFactory#getCompilationMXBean()}
+ * if a JIT is available. Otherwise, the method returns
+ * <code>null</code>.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @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();
+
+}
diff --git a/java/lang/management/ManagementFactory.java b/java/lang/management/ManagementFactory.java
index 915ca50c1..6e8010089 100644
--- a/java/lang/management/ManagementFactory.java
+++ b/java/lang/management/ManagementFactory.java
@@ -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 {@link 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;
+ }
+
}
diff --git a/vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java b/vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java
new file mode 100644
index 000000000..b9b5bbcef
--- /dev/null
+++ b/vm/reference/gnu/java/lang/management/VMCompilationMXBeanImpl.java
@@ -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
+ * {@link ManagementFactory#getCompilationMXBean()},
+ * if this is the case.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @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();
+
+}
diff --git a/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java b/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java
index 7e4f2fbcc..193e33535 100644
--- a/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java
+++ b/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java
@@ -54,12 +54,19 @@ final class VMMemoryMXBeanImpl
/**
* Returns an instance of {@link 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
+ * {@link java.lang.Runtime} to provide some of the values.
*
* @return an {@link 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 {@link java.lang.management.MemoryUsage}