summaryrefslogtreecommitdiff
path: root/java/lang
diff options
context:
space:
mode:
Diffstat (limited to 'java/lang')
-rw-r--r--java/lang/management/GarbageCollectorMXBean.java79
-rw-r--r--java/lang/management/ManagementFactory.java36
-rw-r--r--java/lang/management/MemoryManagerMXBean.java77
3 files changed, 192 insertions, 0 deletions
diff --git a/java/lang/management/GarbageCollectorMXBean.java b/java/lang/management/GarbageCollectorMXBean.java
new file mode 100644
index 000000000..5bb0a18d3
--- /dev/null
+++ b/java/lang/management/GarbageCollectorMXBean.java
@@ -0,0 +1,79 @@
+/* GarbageCollectorMXBean.java - Interface for a garbage collector 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 garbage collectors
+ * of the virtual machine. Garbage collectors are responsible
+ * for removing unreferenced objects from memory. A garbage
+ * collector is a type of memory manager, so this interface
+ * is combined with that of generic memory managers. An instance
+ * of this bean for each garbage collector is obtained by calling
+ * {@link ManagementFactory#getGarbageCollectorMXBeans()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public interface GarbageCollectorMXBean
+ extends MemoryManagerMXBean
+{
+
+ /**
+ * Returns the number of collections the garbage collector
+ * represented by this bean has made. -1 is returned if the
+ * collection count is undefined.
+ *
+ * @return the number of collections made, or -1 if this is
+ * undefined.
+ */
+ long getCollectionCount();
+
+ /**
+ * Returns the accumulated number of milliseconds this garbage
+ * collector has spent freeing the memory used by unreferenced
+ * objects. -1 is returned if the collection time is undefined.
+ * Note that the accumulated time may not change, even when the
+ * collection count increases, if the time taken is sufficiently
+ * short; this depends on the resolution of the timer used.
+ *
+ * @return the accumulated number of milliseconds spent collecting,
+ * or -1 if this is undefined.
+ */
+ long getCollectionTime();
+
+}
diff --git a/java/lang/management/ManagementFactory.java b/java/lang/management/ManagementFactory.java
index 0f9516f25..2de6d3b05 100644
--- a/java/lang/management/ManagementFactory.java
+++ b/java/lang/management/ManagementFactory.java
@@ -41,8 +41,10 @@ import gnu.classpath.SystemProperties;
import gnu.java.lang.management.ClassLoadingMXBeanImpl;
import gnu.java.lang.management.CompilationMXBeanImpl;
+import gnu.java.lang.management.GarbageCollectorMXBeanImpl;
import gnu.java.lang.management.OperatingSystemMXBeanImpl;
import gnu.java.lang.management.MemoryMXBeanImpl;
+import gnu.java.lang.management.MemoryManagerMXBeanImpl;
import gnu.java.lang.management.MemoryPoolMXBeanImpl;
import gnu.java.lang.management.RuntimeMXBeanImpl;
import gnu.java.lang.management.ThreadMXBeanImpl;
@@ -208,4 +210,38 @@ public class ManagementFactory
poolBeans.add(new MemoryPoolMXBeanImpl(names[a]));
return poolBeans;
}
+
+ /**
+ * Returns the memory manager beans for the running
+ * virtual machine. These may change during the course
+ * of execution.
+ *
+ * @return a list of memory manager beans, one for each manager.
+ */
+ public static List getMemoryManagerMXBeans()
+ {
+ List managerBeans = new ArrayList();
+ String[] names = VMManagementFactory.getMemoryManagerNames();
+ for (int a = 0; a < names.length; ++a)
+ managerBeans.add(new MemoryManagerMXBeanImpl(names[a]));
+ managerBeans.add(getGarbageCollectorMXBeans());
+ return managerBeans;
+ }
+
+ /**
+ * Returns the garbage collector beans for the running
+ * virtual machine. These may change during the course
+ * of execution.
+ *
+ * @return a list of garbage collector beans, one for each pool.
+ */
+ public static List getGarbageCollectorMXBeans()
+ {
+ List gcBeans = new ArrayList();
+ String[] names = VMManagementFactory.getGarbageCollectorNames();
+ for (int a = 0; a < names.length; ++a)
+ gcBeans.add(new GarbageCollectorMXBeanImpl(names[a]));
+ return gcBeans;
+ }
+
}
diff --git a/java/lang/management/MemoryManagerMXBean.java b/java/lang/management/MemoryManagerMXBean.java
new file mode 100644
index 000000000..921070539
--- /dev/null
+++ b/java/lang/management/MemoryManagerMXBean.java
@@ -0,0 +1,77 @@
+/* MemoryManagerMXBean.java - Interface for a memory manager 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 memory managers
+ * of the virtual machine. An instance of this bean for each
+ * memory manager is obtained by calling
+ * {@link ManagementFactory#getMemoryManagerMXBeans()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public interface MemoryManagerMXBean
+{
+
+ /**
+ * Returns an array containing the names of the memory pools
+ * this memory manager manages.
+ *
+ * @return an array containing the name of each memory pool
+ * this manager is responsible for.
+ */
+ String[] getMemoryPoolNames();
+
+ /**
+ * Returns the name of the memory manager.
+ *
+ * @return the memory manager name.
+ */
+ String getName();
+
+ /**
+ * Returns true if this memory manager is still valid. A memory
+ * manager becomes invalid when it is removed by the virtual machine
+ * and no longer used.
+ *
+ * @return true if this memory manager is valid.
+ */
+ boolean isValid();
+
+}