summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/lang/management
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/gnu/java/lang/management
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/classpath/gnu/java/lang/management')
-rw-r--r--libjava/classpath/gnu/java/lang/management/BeanImpl.java447
-rw-r--r--libjava/classpath/gnu/java/lang/management/ClassLoadingMXBeanImpl.java98
-rw-r--r--libjava/classpath/gnu/java/lang/management/CompilationMXBeanImpl.java105
-rw-r--r--libjava/classpath/gnu/java/lang/management/GarbageCollectorMXBeanImpl.java84
-rw-r--r--libjava/classpath/gnu/java/lang/management/MemoryMXBeanImpl.java281
-rw-r--r--libjava/classpath/gnu/java/lang/management/MemoryManagerMXBeanImpl.java112
-rw-r--r--libjava/classpath/gnu/java/lang/management/MemoryPoolMXBeanImpl.java226
-rw-r--r--libjava/classpath/gnu/java/lang/management/OperatingSystemMXBeanImpl.java95
-rw-r--r--libjava/classpath/gnu/java/lang/management/RuntimeMXBeanImpl.java197
-rw-r--r--libjava/classpath/gnu/java/lang/management/ThreadMXBeanImpl.java350
-rw-r--r--libjava/classpath/gnu/java/lang/management/package.html46
11 files changed, 2041 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/java/lang/management/BeanImpl.java b/libjava/classpath/gnu/java/lang/management/BeanImpl.java
new file mode 100644
index 000000000..a7c2357b6
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/BeanImpl.java
@@ -0,0 +1,447 @@
+/* BeanImpl.java - A common superclass for bean implementations.
+ 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.javax.management.Translator;
+
+import java.lang.management.ManagementPermission;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ReflectionException;
+import javax.management.StandardMBean;
+
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
+import javax.management.openmbean.OpenMBeanConstructorInfo;
+import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
+import javax.management.openmbean.OpenMBeanInfo;
+import javax.management.openmbean.OpenMBeanInfoSupport;
+import javax.management.openmbean.OpenMBeanOperationInfo;
+import javax.management.openmbean.OpenMBeanOperationInfoSupport;
+import javax.management.openmbean.OpenMBeanParameterInfo;
+import javax.management.openmbean.OpenMBeanParameterInfoSupport;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+/**
+ * A common superclass for bean implementations.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public class BeanImpl
+ extends StandardMBean
+{
+
+ /**
+ * Cached open bean information.
+ */
+ private OpenMBeanInfo openInfo;
+
+ /**
+ * Constructs a new <code>BeanImpl</code>.
+ *
+ * @param iface the bean interface being implemented.
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ protected BeanImpl(Class iface)
+ throws NotCompliantMBeanException
+ {
+ super(iface);
+ }
+
+ protected void cacheMBeanInfo(MBeanInfo info)
+ {
+ if (info == null)
+ return;
+ try
+ {
+ MBeanAttributeInfo[] oldA = info.getAttributes();
+ OpenMBeanAttributeInfo[] attribs =
+ new OpenMBeanAttributeInfoSupport[oldA.length];
+ for (int a = 0; a < oldA.length; ++a)
+ {
+ OpenMBeanParameterInfo param = Translator.translate(oldA[a].getType());
+ if (param.getMinValue() == null)
+ {
+ Object[] lv;
+ if (param.getLegalValues() == null)
+ lv = null;
+ else
+ lv = param.getLegalValues().toArray();
+ attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
+ oldA[a].getDescription(),
+ ((OpenType<Object>)
+ param.getOpenType()),
+ oldA[a].isReadable(),
+ oldA[a].isWritable(),
+ oldA[a].isIs(),
+ param.getDefaultValue(),
+ lv);
+ }
+ else
+ attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
+ oldA[a].getDescription(),
+ ((OpenType<Object>)
+ param.getOpenType()),
+ oldA[a].isReadable(),
+ oldA[a].isWritable(),
+ oldA[a].isIs(),
+ param.getDefaultValue(),
+ ((Comparable<Object>)
+ param.getMinValue()),
+ ((Comparable<Object>)
+ param.getMaxValue()));
+ }
+ MBeanConstructorInfo[] oldC = info.getConstructors();
+ OpenMBeanConstructorInfo[] cons = new OpenMBeanConstructorInfoSupport[oldC.length];
+ for (int a = 0; a < oldC.length; ++a)
+ cons[a] =
+ new OpenMBeanConstructorInfoSupport(oldC[a].getName(),
+ oldC[a].getDescription(),
+ translateSignature(oldC[a].getSignature()));
+ MBeanOperationInfo[] oldO = info.getOperations();
+ OpenMBeanOperationInfo[] ops = new OpenMBeanOperationInfoSupport[oldO.length];
+ for (int a = 0; a < oldO.length; ++a)
+ ops[a] =
+ new OpenMBeanOperationInfoSupport(oldO[a].getName(),
+ oldO[a].getDescription(),
+ translateSignature(oldO[a].getSignature()),
+ Translator.translate(oldO[a].getReturnType()).getOpenType(),
+ oldO[a].getImpact());
+ openInfo = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(),
+ attribs, cons, ops, info.getNotifications());
+ }
+ catch (OpenDataException e)
+ {
+ throw (InternalError) (new InternalError("A problem occurred creating the open type " +
+ "descriptors.").initCause(e));
+ }
+ }
+
+ protected void checkMonitorPermissions()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new ManagementPermission("monitor"));
+ }
+
+ protected void checkControlPermissions()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new ManagementPermission("control"));
+ }
+
+ public Object getAttribute(String attribute)
+ throws AttributeNotFoundException, MBeanException,
+ ReflectionException
+ {
+ Object value = super.getAttribute(attribute);
+ if (value instanceof Enum)
+ return ((Enum) value).name();
+ Class vClass = value.getClass();
+ if (vClass.isArray())
+ vClass = vClass.getComponentType();
+ String cName = vClass.getName();
+ String[] allowedTypes = OpenType.ALLOWED_CLASSNAMES;
+ for (int a = 0; a < allowedTypes.length; ++a)
+ if (cName.equals(allowedTypes[a]))
+ return value;
+ OpenMBeanInfo info = (OpenMBeanInfo) getMBeanInfo();
+ MBeanAttributeInfo[] attribs =
+ (MBeanAttributeInfo[]) info.getAttributes();
+ OpenType type = null;
+ for (int a = 0; a < attribs.length; ++a)
+ if (attribs[a].getName().equals(attribute))
+ type = ((OpenMBeanAttributeInfo) attribs[a]).getOpenType();
+ if (value instanceof List)
+ {
+ try
+ {
+ Class e =
+ Class.forName(((ArrayType) type).getElementOpenType().getClassName());
+ List l = (List) value;
+ Object[] array = (Object[]) Array.newInstance(e, l.size());
+ return l.toArray(array);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw (InternalError) (new InternalError("The class of the list " +
+ "element type could not " +
+ "be created").initCause(e));
+ }
+ }
+ if (value instanceof Map)
+ {
+ TabularType ttype = (TabularType) type;
+ TabularData data = new TabularDataSupport(ttype);
+ Iterator it = ((Map) value).entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ try
+ {
+ data.put(new CompositeDataSupport(ttype.getRowType(),
+ new String[] {
+ "key",
+ "value"
+ },
+ new Object[] {
+ entry.getKey(),
+ entry.getValue()
+ }));
+ }
+ catch (OpenDataException e)
+ {
+ throw (InternalError) (new InternalError("A problem occurred " +
+ "converting the map " +
+ "to a composite data " +
+ "structure.").initCause(e));
+ }
+ }
+ return data;
+ }
+ CompositeType cType = (CompositeType) type;
+ Set names = cType.keySet();
+ Iterator it = names.iterator();
+ List values = new ArrayList(names.size());
+ while (it.hasNext())
+ {
+ String field = (String) it.next();
+ Method getter = null;
+ try
+ {
+ getter = vClass.getMethod("get" + field);
+ }
+ catch (NoSuchMethodException e)
+ {
+ /* Ignored; the type tells us it's there. */
+ }
+ try
+ {
+ values.add(getter.invoke(value));
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ReflectionException(e, "Failed to retrieve " + field);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ReflectionException(e, "Failed to retrieve " + field);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new MBeanException((Exception) e.getCause(),
+ "The getter of " + field +
+ " threw an exception");
+ }
+ }
+ try
+ {
+ return new CompositeDataSupport(cType,
+ (String[])
+ names.toArray(new String[names.size()]),
+ values.toArray());
+ }
+ catch (OpenDataException e)
+ {
+ throw (InternalError) (new InternalError("A problem occurred " +
+ "converting the value " +
+ "to a composite data " +
+ "structure.").initCause(e));
+ }
+ }
+
+ protected MBeanInfo getCachedMBeanInfo()
+ {
+ return (MBeanInfo) openInfo;
+ }
+
+ /**
+ * Override this method so as to prevent the description of a constructor's
+ * parameter being @code{null}. Open MBeans can not have @code{null} descriptions,
+ * but one will occur as the names of parameters aren't stored for reflection.
+ *
+ * @param constructor the constructor whose parameter needs describing.
+ * @param parameter the parameter to be described.
+ * @param sequenceNo the number of the parameter to describe.
+ * @return a description of the constructor's parameter.
+ */
+ protected String getDescription(MBeanConstructorInfo constructor,
+ MBeanParameterInfo parameter,
+ int sequenceNo)
+ {
+ String desc = parameter.getDescription();
+ if (desc == null)
+ return "param" + sequenceNo;
+ else
+ return desc;
+ }
+
+ /**
+ * Override this method so as to prevent the description of an operation's
+ * parameter being @code{null}. Open MBeans can not have @code{null} descriptions,
+ * but one will occur as the names of parameters aren't stored for reflection.
+ *
+ * @param operation the operation whose parameter needs describing.
+ * @param parameter the parameter to be described.
+ * @param sequenceNo the number of the parameter to describe.
+ * @return a description of the operation's parameter.
+ */
+ protected String getDescription(MBeanOperationInfo operation,
+ MBeanParameterInfo parameter,
+ int sequenceNo)
+ {
+ String desc = parameter.getDescription();
+ if (desc == null)
+ return "param" + sequenceNo;
+ else
+ return desc;
+ }
+
+ /**
+ * Override this method so as to prevent the name of a constructor's
+ * parameter being @code{null}. Open MBeans can not have @code{null} names,
+ * but one will occur as the names of parameters aren't stored for reflection.
+ *
+ * @param constructor the constructor whose parameter needs a name.
+ * @param parameter the parameter to be named.
+ * @param sequenceNo the number of the parameter to name.
+ * @return a description of the constructor's parameter.
+ */
+ protected String getParameterName(MBeanConstructorInfo constructor,
+ MBeanParameterInfo parameter,
+ int sequenceNo)
+ {
+ String name = parameter.getName();
+ if (name == null)
+ return "param" + sequenceNo;
+ else
+ return name;
+ }
+
+ /**
+ * Override this method so as to prevent the name of an operation's
+ * parameter being @code{null}. Open MBeans can not have @code{null} names,
+ * but one will occur as the names of parameters aren't stored for reflection.
+ *
+ * @param operation the operation whose parameter needs a name.
+ * @param parameter the parameter to be named.
+ * @param sequenceNo the number of the parameter to name.
+ * @return a description of the operation's parameter.
+ */
+ protected String getParameterName(MBeanOperationInfo operation,
+ MBeanParameterInfo parameter,
+ int sequenceNo)
+ {
+ String name = parameter.getName();
+ if (name == null)
+ return "param" + sequenceNo;
+ else
+ return name;
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ super.getMBeanInfo();
+ return getCachedMBeanInfo();
+ }
+
+ private OpenMBeanParameterInfo[] translateSignature(MBeanParameterInfo[] oldS)
+ throws OpenDataException
+ {
+ OpenMBeanParameterInfo[] sig = new OpenMBeanParameterInfoSupport[oldS.length];
+ for (int a = 0; a < oldS.length; ++a)
+ {
+ OpenMBeanParameterInfo param = Translator.translate(oldS[a].getType());
+ if (param.getMinValue() == null)
+ {
+ Object[] lv;
+ if (param.getLegalValues() == null)
+ lv = null;
+ else
+ lv = param.getLegalValues().toArray();
+ sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
+ oldS[a].getDescription(),
+ ((OpenType<Object>)
+ param.getOpenType()),
+ param.getDefaultValue(),
+ lv);
+ }
+ else
+ sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
+ oldS[a].getDescription(),
+ ((OpenType<Object>)
+ param.getOpenType()),
+ param.getDefaultValue(),
+ ((Comparable<Object>)
+ param.getMinValue()),
+ ((Comparable<Object>)
+ param.getMaxValue()));
+ }
+ return sig;
+ }
+
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/ClassLoadingMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/ClassLoadingMXBeanImpl.java
new file mode 100644
index 000000000..d98a39633
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/ClassLoadingMXBeanImpl.java
@@ -0,0 +1,98 @@
+/* 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 javax.management.NotCompliantMBeanException;
+
+/**
+ * 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
+ * {@link ManagementFactory#getClassLoadingMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class ClassLoadingMXBeanImpl
+ extends BeanImpl
+ implements ClassLoadingMXBean
+{
+
+ /**
+ * Constructs a new <code>ClassLoadingMXBeanImpl</code>.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public ClassLoadingMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(ClassLoadingMXBean.class);
+ }
+
+ public int getLoadedClassCount()
+ {
+ return VMClassLoadingMXBeanImpl.getLoadedClassCount();
+ }
+
+ public long getTotalLoadedClassCount()
+ {
+ return getLoadedClassCount() + getUnloadedClassCount();
+ }
+
+ public long getUnloadedClassCount()
+ {
+ return VMClassLoadingMXBeanImpl.getUnloadedClassCount();
+ }
+
+ public boolean isVerbose()
+ {
+ return VMClassLoadingMXBeanImpl.isVerbose();
+ }
+
+ public void setVerbose(boolean verbose)
+ {
+ checkControlPermissions();
+ VMClassLoadingMXBeanImpl.setVerbose(verbose);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/CompilationMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/CompilationMXBeanImpl.java
new file mode 100644
index 000000000..1b77edf5a
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/CompilationMXBeanImpl.java
@@ -0,0 +1,105 @@
+/* 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;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * 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";
+
+ /**
+ * Constructs a new <code>CompilationMXBeanImpl</code>.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public CompilationMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(CompilationMXBean.class);
+ }
+
+ 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/libjava/classpath/gnu/java/lang/management/GarbageCollectorMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/GarbageCollectorMXBeanImpl.java
new file mode 100644
index 000000000..7a2d762fa
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/GarbageCollectorMXBeanImpl.java
@@ -0,0 +1,84 @@
+/* GarbageCollectorMXBeanImpl.java - Implementation of a GC 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.GarbageCollectorMXBean;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about one of the garbage
+ * collectors used by the current invocation of the
+ * virtual machine. 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 final class GarbageCollectorMXBeanImpl
+ extends MemoryManagerMXBeanImpl
+ implements GarbageCollectorMXBean
+{
+
+ /**
+ * Constructs a new <code>GarbageCollectorMXBeanImpl</code>.
+ *
+ * @param name the name of the garbage collector this bean represents.
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public GarbageCollectorMXBeanImpl(String name)
+ throws NotCompliantMBeanException
+ {
+ super(name, GarbageCollectorMXBean.class);
+ }
+
+ public long getCollectionCount()
+ {
+ return VMGarbageCollectorMXBeanImpl.getCollectionCount(name);
+ }
+
+ public long getCollectionTime()
+ {
+ return VMGarbageCollectorMXBeanImpl.getCollectionTime(name);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/MemoryMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/MemoryMXBeanImpl.java
new file mode 100644
index 000000000..10e6522f1
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/MemoryMXBeanImpl.java
@@ -0,0 +1,281 @@
+/* MemoryMXBeanImpl.java - Implementation of a memory 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.javax.management.ListenerData;
+
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryNotificationInfo;
+import java.lang.management.MemoryUsage;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanNotificationInfo;
+import javax.management.NotCompliantMBeanException;
+import javax.management.Notification;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+/**
+ * Provides access to information about the memory
+ * management of the current invocation of the virtual
+ * machine. Instances of this bean are obtained by calling
+ * {@link ManagementFactory#getMemoryMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class MemoryMXBeanImpl
+ extends BeanImpl
+ implements MemoryMXBean, NotificationEmitter
+{
+
+ private List listeners;
+
+ private long notificationCount;
+
+ public static CompositeType notifType;
+
+ public static CompositeType usageType;
+
+ static
+ {
+ try
+ {
+ CompositeType usageType =
+ new CompositeType(MemoryUsage.class.getName(),
+ "Describes the usage levels of a pool",
+ new String[] { "init", "used",
+ "committed", "max"
+ },
+ new String[] { "Initial level",
+ "Used level",
+ "Committed level",
+ "Maximum level"
+ },
+ new OpenType[] {
+ SimpleType.LONG, SimpleType.LONG,
+ SimpleType.LONG, SimpleType.LONG
+ });
+ CompositeType notifType =
+ new CompositeType(MemoryNotificationInfo.class.getName(),
+ "Provides the notification info on memory usage",
+ new String[] { "poolName", "usage", "count" },
+ new String[] { "Name of the memory pool",
+ "Usage level of the memory pool",
+ "Number of times the threshold " +
+ "has been crossed"
+ },
+ new OpenType[] {
+ SimpleType.STRING, usageType, SimpleType.LONG
+ });
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the composite data types.", e);
+ }
+ }
+
+ /**
+ * Constructs a new <code>MemoryMXBeanImpl</code>.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public MemoryMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(MemoryMXBean.class);
+ listeners = new ArrayList();
+ notificationCount = 0;
+ }
+
+ public void gc()
+ {
+ System.gc();
+ }
+
+ public MemoryUsage getHeapMemoryUsage()
+ {
+ return VMMemoryMXBeanImpl.getHeapMemoryUsage();
+ }
+
+ public MemoryUsage getNonHeapMemoryUsage()
+ {
+ return VMMemoryMXBeanImpl.getNonHeapMemoryUsage();
+ }
+
+ public int getObjectPendingFinalizationCount()
+ {
+ return VMMemoryMXBeanImpl.getObjectPendingFinalizationCount();
+ }
+
+ public boolean isVerbose()
+ {
+ return VMMemoryMXBeanImpl.isVerbose();
+ }
+
+ public void setVerbose(boolean verbose)
+ {
+ checkControlPermissions();
+ VMMemoryMXBeanImpl.setVerbose(verbose);
+ }
+
+ public void addNotificationListener(NotificationListener listener,
+ NotificationFilter filter,
+ Object passback)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener added to bean.");
+ listeners.add(new ListenerData(listener, filter, passback));
+ }
+
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ return new MBeanNotificationInfo[]
+ {
+ new MBeanNotificationInfo(new String[]
+ {
+ MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED,
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED
+ },
+ Notification.class.getName(),
+ "Memory Usage Notifications")
+ };
+ }
+
+ public void removeNotificationListener(NotificationListener listener)
+ throws ListenerNotFoundException
+ {
+ Iterator it = listeners.iterator();
+ boolean foundOne = false;
+ while (it.hasNext())
+ {
+ ListenerData data = (ListenerData) it.next();
+ if (data.getListener() == listener)
+ {
+ it.remove();
+ foundOne = true;
+ }
+ }
+ if (!foundOne)
+ throw new ListenerNotFoundException("The specified listener, " + listener +
+ "is not registered with this bean.");
+ }
+
+ public void removeNotificationListener(NotificationListener listener,
+ NotificationFilter filter,
+ Object passback)
+ throws ListenerNotFoundException
+ {
+ if (!(listeners.remove(new ListenerData(listener, filter, passback))))
+ {
+ throw new ListenerNotFoundException("The specified listener, " + listener +
+ " with filter " + filter +
+ "and passback " + passback +
+ ", is not registered with this bean.");
+ }
+ }
+
+ void fireNotification(String type, String poolName, long init, long used,
+ long committed, long max, long count)
+ {
+ Notification notif = new Notification(type, this, notificationCount);
+ MemoryUsage usage = new MemoryUsage(init, used, committed, max);
+ CompositeData data;
+ try
+ {
+ data = new CompositeDataSupport(notifType,
+ new String[] {
+ "poolName", "usage", "count"
+ },
+ new Object[] {
+ poolName, usage, Long.valueOf(count)
+ });
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the composite data instance.", e);
+ }
+ notif.setUserData(data);
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ ListenerData ldata = (ListenerData) it.next();
+ NotificationFilter filter = ldata.getFilter();
+ if (filter == null || filter.isNotificationEnabled(notif))
+ ldata.getListener().handleNotification(notif, ldata.getPassback());
+ }
+ ++notificationCount;
+ }
+
+ void fireThresholdExceededNotification(String poolName, long init,
+ long used, long committed,
+ long max, long count)
+ {
+ fireNotification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ poolName, init, used, committed, max, count);
+ }
+
+ void fireCollectionThresholdExceededNotification(String poolName,
+ long init,
+ long used,
+ long committed,
+ long max,
+ long count)
+ {
+ fireNotification(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED,
+ poolName, init, used, committed, max, count);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/MemoryManagerMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/MemoryManagerMXBeanImpl.java
new file mode 100644
index 000000000..51d0ed972
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/MemoryManagerMXBeanImpl.java
@@ -0,0 +1,112 @@
+/* MemoryManagerMXBeanImpl.java - Implementation of 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 gnu.java.lang.management;
+
+import java.lang.management.MemoryManagerMXBean;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about one of the memory
+ * managers used by the current invocation of the
+ * virtual machine. An instance of this bean for each memory
+ * manager is obtained by calling
+ * {@link ManagementFactory#getMemoryPoolMXBeans()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public class MemoryManagerMXBeanImpl
+ extends BeanImpl
+ implements MemoryManagerMXBean
+{
+
+ /**
+ * The name of the memory manager.
+ */
+ protected String name;
+
+ /**
+ * Constructs a new <code>MemoryManagerMXBeanImpl</code>.
+ *
+ * @param name the name of the manager this bean represents.
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public MemoryManagerMXBeanImpl(String name)
+ throws NotCompliantMBeanException
+ {
+ this(name, MemoryManagerMXBean.class);
+ }
+
+ /**
+ * Constructs a new <code>MemoryManagerMXBeanImpl</code>
+ * implementing the specified bean interface.
+ *
+ * @param name the name of the manager this bean represents.
+ * @param iface the bean interface being implemented.
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ protected MemoryManagerMXBeanImpl(String name, Class iface)
+ throws NotCompliantMBeanException
+ {
+ super(iface);
+ this.name = name;
+ }
+
+ public String[] getMemoryPoolNames()
+ {
+ return VMMemoryManagerMXBeanImpl.getMemoryPoolNames(name);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean isValid()
+ {
+ return VMMemoryManagerMXBeanImpl.isValid(name);
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/MemoryPoolMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/MemoryPoolMXBeanImpl.java
new file mode 100644
index 000000000..d92e6703f
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/MemoryPoolMXBeanImpl.java
@@ -0,0 +1,226 @@
+/* MemoryPoolMXBeanImpl.java - Implementation of a memory pool 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.MemoryPoolMXBean;
+import java.lang.management.MemoryType;
+import java.lang.management.MemoryUsage;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about one of the memory
+ * resources or pools used by the current invocation of the
+ * virtual machine. An instance of this bean for each memory
+ * pool is obtained by calling
+ * {@link ManagementFactory#getMemoryPoolMXBeans()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class MemoryPoolMXBeanImpl
+ extends BeanImpl
+ implements MemoryPoolMXBean
+{
+
+ /**
+ * The name of the pool.
+ */
+ private String name;
+
+ /**
+ * Constant for collection usage threshold.
+ */
+ private static final String COLLECTION_USAGE_THRESHOLD =
+ "gnu.java.lang.management.CollectionUsageThresholdSupport";
+
+ /**
+ * Constant for thread time support.
+ */
+ private static final String USAGE_THRESHOLD =
+ "gnu.java.lang.management.UsageThresholdSupport";
+
+ /**
+ * Constructs a new <code>MemoryPoolMXBeanImpl</code>.
+ *
+ * @param name the name of the pool this bean represents.
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public MemoryPoolMXBeanImpl(String name)
+ throws NotCompliantMBeanException
+ {
+ super(MemoryPoolMXBean.class);
+ this.name = name;
+ }
+
+ public MemoryUsage getCollectionUsage()
+ {
+ return VMMemoryPoolMXBeanImpl.getCollectionUsage(name);
+ }
+
+ public long getCollectionUsageThreshold()
+ {
+ if (isCollectionUsageThresholdSupported())
+ return VMMemoryPoolMXBeanImpl.getCollectionUsageThreshold(name);
+ else
+ throw new UnsupportedOperationException("A collection usage "+
+ "threshold is not supported.");
+ }
+
+ public long getCollectionUsageThresholdCount()
+ {
+ if (isCollectionUsageThresholdSupported())
+ return VMMemoryPoolMXBeanImpl.getCollectionUsageThresholdCount(name);
+ else
+ throw new UnsupportedOperationException("A collection usage "+
+ "threshold is not supported.");
+ }
+
+ public String[] getMemoryManagerNames()
+ {
+ return VMMemoryPoolMXBeanImpl.getMemoryManagerNames(name);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public MemoryUsage getPeakUsage()
+ {
+ if (isValid())
+ return VMMemoryPoolMXBeanImpl.getPeakUsage(name);
+ else
+ return null;
+ }
+
+ public MemoryType getType()
+ {
+ return
+ MemoryType.valueOf(VMMemoryPoolMXBeanImpl.getType(name));
+ }
+
+ public MemoryUsage getUsage()
+ {
+ if (isValid())
+ return VMMemoryPoolMXBeanImpl.getUsage(name);
+ else
+ return null;
+ }
+
+ public long getUsageThreshold()
+ {
+ if (isUsageThresholdSupported())
+ return VMMemoryPoolMXBeanImpl.getUsageThreshold(name);
+ else
+ throw new UnsupportedOperationException("A usage threshold " +
+ "is not supported.");
+ }
+
+ public long getUsageThresholdCount()
+ {
+ if (isUsageThresholdSupported())
+ return VMMemoryPoolMXBeanImpl.getUsageThresholdCount(name);
+ else
+ throw new UnsupportedOperationException("A usage threshold " +
+ "is not supported.");
+ }
+
+ public boolean isCollectionUsageThresholdExceeded()
+ {
+ return getCollectionUsage().getUsed() >= getCollectionUsageThreshold();
+ }
+
+ public boolean isCollectionUsageThresholdSupported()
+ {
+ return SystemProperties.getProperty(COLLECTION_USAGE_THRESHOLD) != null;
+ }
+
+ public boolean isUsageThresholdExceeded()
+ {
+ return getUsage().getUsed() >= getUsageThreshold();
+ }
+
+ public boolean isUsageThresholdSupported()
+ {
+ return SystemProperties.getProperty(USAGE_THRESHOLD) != null;
+ }
+
+ public boolean isValid()
+ {
+ return VMMemoryPoolMXBeanImpl.isValid(name);
+ }
+
+ public void resetPeakUsage()
+ {
+ checkControlPermissions();
+ VMMemoryPoolMXBeanImpl.resetPeakUsage(name);
+ }
+
+ public void setCollectionUsageThreshold(long threshold)
+ {
+ checkControlPermissions();
+ if (threshold < 0)
+ throw new IllegalArgumentException("Threshold of " + threshold +
+ "is less than zero.");
+ if (isCollectionUsageThresholdSupported())
+ VMMemoryPoolMXBeanImpl.setCollectionUsageThreshold(name, threshold);
+ else
+ throw new UnsupportedOperationException("A collection usage "+
+ "threshold is not supported.");
+ }
+
+ public void setUsageThreshold(long threshold)
+ {
+ checkControlPermissions();
+ if (threshold < 0)
+ throw new IllegalArgumentException("Threshold of " + threshold +
+ "is less than zero.");
+ if (isUsageThresholdSupported())
+ VMMemoryPoolMXBeanImpl.setUsageThreshold(name, threshold);
+ else
+ throw new UnsupportedOperationException("A usage threshold " +
+ "is not supported.");
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/OperatingSystemMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/OperatingSystemMXBeanImpl.java
new file mode 100644
index 000000000..7f5a9586c
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/OperatingSystemMXBeanImpl.java
@@ -0,0 +1,95 @@
+/* OperatingSystemMXBeanImpl.java - Implementation of an operating system 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.OperatingSystemMXBean;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about the underlying operating
+ * system.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class OperatingSystemMXBeanImpl
+ extends BeanImpl
+ implements OperatingSystemMXBean
+{
+
+ /**
+ * Constructs a new <code>OperatingSystemMXBeanImpl</code>.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public OperatingSystemMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(OperatingSystemMXBean.class);
+ }
+
+ public String getArch()
+ {
+ return System.getProperty("os.arch");
+ }
+
+ public int getAvailableProcessors()
+ {
+ return Runtime.getRuntime().availableProcessors();
+ }
+
+ public String getName()
+ {
+ return System.getProperty("os.name");
+ }
+
+ public double getSystemLoadAverage()
+ {
+ return VMOperatingSystemMXBeanImpl.getSystemLoadAverage();
+ }
+
+ public String getVersion()
+ {
+ return System.getProperty("os.version");
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/RuntimeMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/RuntimeMXBeanImpl.java
new file mode 100644
index 000000000..8db943bb6
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/RuntimeMXBeanImpl.java
@@ -0,0 +1,197 @@
+/* RuntimeMXBeanImpl.java - Implementation of an runtime 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.RuntimeMXBean;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about the virtual machine.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class RuntimeMXBeanImpl
+ extends BeanImpl
+ implements RuntimeMXBean
+{
+
+ private static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path";
+ private static final String JAVA_BOOT_CLASS_PATH = "java.boot.class.path";
+
+ private long startTime = -1;
+
+ private String bootClassPath = null;
+
+ private boolean bootClassPathSupported = true;
+
+ /**
+ * Constructs a new <code>RuntimeMXBeanImpl</code>.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public RuntimeMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(RuntimeMXBean.class);
+ }
+
+ public String getBootClassPath()
+ {
+ checkMonitorPermissions();
+ if (isBootClassPathSupported())
+ return bootClassPath;
+ else
+ throw
+ new UnsupportedOperationException("Retrieving the boot " +
+ "classpath is not supported.");
+ }
+
+ public String getClassPath()
+ {
+ return System.getProperty("java.class.path");
+ }
+
+ public List getInputArguments()
+ {
+ checkMonitorPermissions();
+ return Arrays.asList(VMRuntimeMXBeanImpl.getInputArguments());
+ }
+
+ public String getLibraryPath()
+ {
+ return System.getProperty("java.library.path");
+ }
+
+ public String getManagementSpecVersion()
+ {
+ return "1.0";
+ }
+
+ public String getName()
+ {
+ return VMRuntimeMXBeanImpl.getName();
+ }
+
+ public String getSpecName()
+ {
+ return System.getProperty("java.vm.specification.name");
+ }
+
+ public String getSpecVendor()
+ {
+ return System.getProperty("java.vm.specification.vendor");
+ }
+
+ public String getSpecVersion()
+ {
+ return System.getProperty("java.vm.specification.version");
+ }
+
+ public long getStartTime()
+ {
+ if (startTime == -1)
+ startTime = VMRuntimeMXBeanImpl.getStartTime();
+ return startTime;
+ }
+
+ public Map getSystemProperties()
+ {
+ Map map = new HashMap();
+ Properties props = System.getProperties();
+ Iterator entries = props.entrySet().iterator();
+ while (entries.hasNext())
+ {
+ Map.Entry next = (Map.Entry) entries.next();
+ Object key = next.getKey();
+ Object value = next.getValue();
+ if (key instanceof String &&
+ value instanceof String)
+ map.put(key, value);
+ }
+ return map;
+ }
+
+ public long getUptime()
+ {
+ return new Date().getTime() - getStartTime();
+ }
+
+ public String getVmName()
+ {
+ return System.getProperty("java.vm.name");
+ }
+
+ public String getVmVendor()
+ {
+ return System.getProperty("java.vm.vendor");
+ }
+
+ public String getVmVersion()
+ {
+ return System.getProperty("java.vm.version");
+ }
+
+ public boolean isBootClassPathSupported()
+ {
+ if (bootClassPath == null)
+ {
+ bootClassPath = SystemProperties.getProperty(JAVA_BOOT_CLASS_PATH);
+ if (bootClassPath == null)
+ bootClassPath = SystemProperties.getProperty(SUN_BOOT_CLASS_PATH);
+ if (bootClassPath == null)
+ bootClassPathSupported = false;
+ }
+ return bootClassPathSupported;
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/ThreadMXBeanImpl.java b/libjava/classpath/gnu/java/lang/management/ThreadMXBeanImpl.java
new file mode 100644
index 000000000..97040997b
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/ThreadMXBeanImpl.java
@@ -0,0 +1,350 @@
+/* ThreadMXBeanImpl.java - Implementation of a thread 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.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import javax.management.NotCompliantMBeanException;
+
+/**
+ * Provides access to information about the threads
+ * of the virtual machine. An instance of this bean is
+ * obtained by calling
+ * {@link ManagementFactory#getThreadMXBean()}.
+ * See {@link java.lang.management.ThreadMXBean} for
+ * full documentation.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+public final class ThreadMXBeanImpl
+ extends BeanImpl
+ implements ThreadMXBean
+{
+
+ /**
+ * Constant for current thread time support.
+ */
+ private static final String CURRENT_THREAD_TIME_SUPPORT =
+ "gnu.java.lang.management.CurrentThreadTimeSupport";
+
+ /**
+ * Constant for thread time support.
+ */
+ private static final String THREAD_TIME_SUPPORT =
+ "gnu.java.lang.management.ThreadTimeSupport";
+
+ /**
+ * Constant for thread contention support.
+ */
+ private static final String CONTENTION_SUPPORT =
+ "gnu.java.lang.management.ThreadContentionSupport";
+
+ /**
+ * Constant for initial value of thread time support.
+ */
+ private static final String TIME_ENABLED =
+ "gnu.java.lang.management.ThreadTimeInitallyEnabled";
+
+ /**
+ * Constant for monitor usage monitoring support.
+ */
+ private static final String MONITOR_SUPPORT =
+ "gnu.java.lang.management.MonitorUsageMonitoringSupport";
+
+ /**
+ * Constant for ownable synchronizer usage monitoring support.
+ */
+ private static final String SYNCHRONIZER_SUPPORT =
+ "gnu.java.lang.management.OwnableSynchronizerUsageMonitoringSupport";
+
+ /**
+ * Flag to indicate whether time monitoring is enabled or not.
+ */
+ private boolean timeEnabled;
+
+ /**
+ * Flag to indicate whether contention monitoring is enabled or not.
+ */
+ private boolean contentionEnabled;
+
+ /**
+ * Default constructor to set up flag states. The
+ * VM has to specify whether time monitoring is initially
+ * enabled or not.
+ *
+ * @throws NotCompliantMBeanException if this class doesn't implement
+ * the interface or a method appears
+ * in the interface that doesn't comply
+ * with the naming conventions.
+ */
+ public ThreadMXBeanImpl()
+ throws NotCompliantMBeanException
+ {
+ super(ThreadMXBean.class);
+ timeEnabled = Boolean.parseBoolean(SystemProperties.getProperty(TIME_ENABLED));
+ contentionEnabled = false;
+ }
+
+ public ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
+ boolean lockedSynchronizers)
+ {
+ return getThreadInfo(getAllThreadIds(), lockedMonitors,
+ lockedSynchronizers);
+ }
+
+ public long[] findDeadlockedThreads()
+ {
+ checkMonitorPermissions();
+ if (!isSynchronizerUsageSupported())
+ throw new UnsupportedOperationException("Ownable synchronizer usage " +
+ "monitoring is not provided " +
+ "by this VM.");
+ return VMThreadMXBeanImpl.findDeadlockedThreads();
+ }
+
+ public long[] findMonitorDeadlockedThreads()
+ {
+ checkMonitorPermissions();
+ return VMThreadMXBeanImpl.findMonitorDeadlockedThreads();
+ }
+
+ public long[] getAllThreadIds()
+ {
+ checkMonitorPermissions();
+ return VMThreadMXBeanImpl.getAllThreadIds();
+ }
+
+ public long getCurrentThreadCpuTime()
+ {
+ if (!isCurrentThreadCpuTimeSupported())
+ throw new UnsupportedOperationException("Current thread CPU " +
+ "time not supported.");
+ if (!timeEnabled)
+ return -1;
+ return VMThreadMXBeanImpl.getCurrentThreadCpuTime();
+ }
+
+ public long getCurrentThreadUserTime()
+ {
+ if (!isCurrentThreadCpuTimeSupported())
+ throw new UnsupportedOperationException("Current thread user " +
+ "time not supported.");
+ if (!timeEnabled)
+ return -1;
+ return VMThreadMXBeanImpl.getCurrentThreadUserTime();
+ }
+
+ public int getDaemonThreadCount()
+ {
+ return VMThreadMXBeanImpl.getDaemonThreadCount();
+ }
+
+ public int getPeakThreadCount()
+ {
+ return VMThreadMXBeanImpl.getPeakThreadCount();
+ }
+
+ public int getThreadCount()
+ {
+ return VMThreadMXBeanImpl.getThreadCount();
+ }
+
+ public long getThreadCpuTime(long id)
+ {
+ if (!isThreadCpuTimeSupported())
+ throw new UnsupportedOperationException("Thread CPU time not " +
+ "supported.");
+ if (id <= 0)
+ throw new IllegalArgumentException("Invalid thread id: " + id);
+ if (!timeEnabled)
+ return -1;
+ return VMThreadMXBeanImpl.getThreadCpuTime(id);
+ }
+
+ public ThreadInfo getThreadInfo(long id)
+ {
+ return getThreadInfo(id, 0);
+ }
+
+ public ThreadInfo[] getThreadInfo(long[] ids)
+ {
+ return getThreadInfo(ids, 0);
+ }
+
+ public ThreadInfo getThreadInfo(long id, int maxDepth)
+ {
+ checkMonitorPermissions();
+ if (id <= 0)
+ throw new IllegalArgumentException("Invalid thread id: " + id);
+ if (maxDepth < 0)
+ throw new IllegalArgumentException("Invalid depth: " + maxDepth);
+ return VMThreadMXBeanImpl.getThreadInfoForId(id, maxDepth);
+ }
+
+ public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth)
+ {
+ checkMonitorPermissions();
+ if (maxDepth < 0)
+ throw new IllegalArgumentException("Invalid depth: " + maxDepth);
+ ThreadInfo[] infos = new ThreadInfo[ids.length];
+ for (int a = 0; a < ids.length; ++a)
+ {
+ if (ids[a] <= 0)
+ throw new IllegalArgumentException("Invalid thread id " + a +
+ ": " + ids[a]);
+ infos[a] = VMThreadMXBeanImpl.getThreadInfoForId(ids[a], maxDepth);
+ }
+ return infos;
+ }
+
+ public ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
+ boolean lockedSynchronizers)
+ {
+ checkMonitorPermissions();
+ if (lockedMonitors && !isObjectMonitorUsageSupported())
+ throw new UnsupportedOperationException("Monitor usage monitoring is " +
+ "not provided by this VM.");
+ if (lockedSynchronizers && !isSynchronizerUsageSupported())
+ throw new UnsupportedOperationException("Ownable synchronizer usage " +
+ "monitoring is not provided " +
+ "by this VM.");
+ ThreadInfo[] infos = getThreadInfo(ids, Integer.MAX_VALUE);
+ if (lockedMonitors)
+ for (ThreadInfo info : infos)
+ VMThreadMXBeanImpl.getMonitorInfo(info);
+ if (lockedSynchronizers)
+ for (ThreadInfo info : infos)
+ VMThreadMXBeanImpl.getLockInfo(info);
+ return infos;
+ }
+
+ public long getThreadUserTime(long id)
+ {
+ if (!isThreadCpuTimeSupported())
+ throw new UnsupportedOperationException("Thread user time not " +
+ "supported.");
+ if (id <= 0)
+ throw new IllegalArgumentException("Invalid thread id: " + id);
+ if (!timeEnabled)
+ return -1;
+ return VMThreadMXBeanImpl.getThreadUserTime(id);
+ }
+
+ public long getTotalStartedThreadCount()
+ {
+ return VMThreadMXBeanImpl.getTotalStartedThreadCount();
+ }
+
+ public boolean isCurrentThreadCpuTimeSupported()
+ {
+ if (isThreadCpuTimeSupported())
+ return true;
+ return SystemProperties.getProperty(CURRENT_THREAD_TIME_SUPPORT) != null;
+ }
+
+ public boolean isObjectMonitorUsageSupported()
+ {
+ return SystemProperties.getProperty(MONITOR_SUPPORT) != null;
+ }
+
+ public boolean isSynchronizerUsageSupported()
+ {
+ return SystemProperties.getProperty(SYNCHRONIZER_SUPPORT) != null;
+ }
+
+ public boolean isThreadContentionMonitoringEnabled()
+ {
+ if (isThreadContentionMonitoringSupported())
+ return contentionEnabled;
+ else
+ throw new UnsupportedOperationException("Contention monitoring " +
+ "not supported.");
+ }
+
+ public boolean isThreadContentionMonitoringSupported()
+ {
+ return SystemProperties.getProperty(CONTENTION_SUPPORT) != null;
+ }
+
+ public boolean isThreadCpuTimeEnabled()
+ {
+ if (isThreadCpuTimeSupported() ||
+ isCurrentThreadCpuTimeSupported())
+ return timeEnabled;
+ else
+ throw new UnsupportedOperationException("Thread time not " +
+ "supported.");
+ }
+
+ public boolean isThreadCpuTimeSupported()
+ {
+ return SystemProperties.getProperty(THREAD_TIME_SUPPORT) != null;
+ }
+
+ public void resetPeakThreadCount()
+ {
+ checkControlPermissions();
+ VMThreadMXBeanImpl.resetPeakThreadCount();
+ }
+
+ public void setThreadContentionMonitoringEnabled(boolean enable)
+ {
+ checkControlPermissions();
+ if (isThreadContentionMonitoringSupported())
+ contentionEnabled = enable;
+ else
+ throw new UnsupportedOperationException("Contention monitoring " +
+ "not supported.");
+ }
+
+ public void setThreadCpuTimeEnabled(boolean enable)
+ {
+ checkControlPermissions();
+ if (isThreadCpuTimeSupported() ||
+ isCurrentThreadCpuTimeSupported())
+ timeEnabled = enable;
+ else
+ throw new UnsupportedOperationException("Thread time not " +
+ "supported.");
+ }
+
+}
diff --git a/libjava/classpath/gnu/java/lang/management/package.html b/libjava/classpath/gnu/java/lang/management/package.html
new file mode 100644
index 000000000..fc1bafc0c
--- /dev/null
+++ b/libjava/classpath/gnu/java/lang/management/package.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in gnu.java.lang.management package.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+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. -->
+
+<html>
+<head><title>GNU Classpath - gnu.java.lang.management</title></head>
+
+<body>
+<p>GNU implementations of the Java system management beans.</p>
+
+</body>
+</html>