History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/lang/management (63 of 18352 files). Show all

Unified · Split

63 files
  1. java/pkg/java/lang/management/BufferPoolMXBean.class +0 −0
  2. java/pkg/java/lang/management/BufferPoolMXBean.java +93 −0
  3. java/pkg/java/lang/management/ClassLoadingMXBean.class +0 −0
  4. java/pkg/java/lang/management/ClassLoadingMXBean.java +114 −0
  5. java/pkg/java/lang/management/CompilationMXBean.class +0 −0
  6. java/pkg/java/lang/management/CompilationMXBean.java +101 −0
  7. java/pkg/java/lang/management/GarbageCollectorMXBean.class +0 −0
  8. java/pkg/java/lang/management/GarbageCollectorMXBean.java +94 −0
  9. java/pkg/java/lang/management/LockInfo.class +0 −0
  10. java/pkg/java/lang/management/LockInfo.java +122 −0
  11. java/pkg/java/lang/management/ManagementFactory$1.class +0 −0
  12. java/pkg/java/lang/management/ManagementFactory$2.class +0 −0
  13. java/pkg/java/lang/management/ManagementFactory.class +0 −0
  14. java/pkg/java/lang/management/ManagementFactory.java +828 −0
  15. java/pkg/java/lang/management/ManagementPermission.class +0 −0
  16. java/pkg/java/lang/management/ManagementPermission.java +123 −0
  17. java/pkg/java/lang/management/MemoryMXBean.class +0 −0
  18. java/pkg/java/lang/management/MemoryMXBean.java +304 −0
  19. java/pkg/java/lang/management/MemoryManagerMXBean.class +0 −0
  20. java/pkg/java/lang/management/MemoryManagerMXBean.java +88 −0
  21. java/pkg/java/lang/management/MemoryNotificationInfo.class +0 −0
  22. java/pkg/java/lang/management/MemoryNotificationInfo.java +256 −0
  23. java/pkg/java/lang/management/MemoryPoolMXBean.class +0 −0
  24. java/pkg/java/lang/management/MemoryPoolMXBean.java +643 −0
  25. java/pkg/java/lang/management/MemoryType.class +0 −0
  26. java/pkg/java/lang/management/MemoryType.java +73 −0
  27. java/pkg/java/lang/management/MemoryUsage.class +0 −0
  28. java/pkg/java/lang/management/MemoryUsage.java +303 −0
  29. java/pkg/java/lang/management/MonitorInfo.class +0 −0
  30. java/pkg/java/lang/management/MonitorInfo.java +159 −0
  31. java/pkg/java/lang/management/OperatingSystemMXBean.class +0 −0
  32. java/pkg/java/lang/management/OperatingSystemMXBean.java +142 −0
  33. java/pkg/java/lang/management/PlatformComponent$1.class +0 −0
  34. java/pkg/java/lang/management/PlatformComponent$10.class +0 −0
  35. java/pkg/java/lang/management/PlatformComponent$11.class +0 −0
  36. java/pkg/java/lang/management/PlatformComponent$12.class +0 −0
  37. java/pkg/java/lang/management/PlatformComponent$13.class +0 −0
  38. java/pkg/java/lang/management/PlatformComponent$14.class +0 −0
  39. java/pkg/java/lang/management/PlatformComponent$15.class +0 −0
  40. java/pkg/java/lang/management/PlatformComponent$2.class +0 −0
  41. java/pkg/java/lang/management/PlatformComponent$3.class +0 −0
  42. java/pkg/java/lang/management/PlatformComponent$4.class +0 −0
  43. java/pkg/java/lang/management/PlatformComponent$5.class +0 −0
  44. java/pkg/java/lang/management/PlatformComponent$6.class +0 −0
  45. java/pkg/java/lang/management/PlatformComponent$7.class +0 −0
  46. java/pkg/java/lang/management/PlatformComponent$8.class +0 −0
  47. java/pkg/java/lang/management/PlatformComponent$9.class +0 −0
  48. java/pkg/java/lang/management/PlatformComponent$MXBeanFetcher.class +0 −0
  49. java/pkg/java/lang/management/PlatformComponent.class +0 −0
  50. java/pkg/java/lang/management/PlatformComponent.java +467 −0
  51. java/pkg/java/lang/management/PlatformLoggingMXBean.class +0 −0
  52. java/pkg/java/lang/management/PlatformLoggingMXBean.java +138 −0
  53. java/pkg/java/lang/management/PlatformManagedObject.class +0 −0
  54. java/pkg/java/lang/management/PlatformManagedObject.java +61 −0
  55. java/pkg/java/lang/management/RuntimeMXBean.class +0 −0
  56. java/pkg/java/lang/management/RuntimeMXBean.java +339 −0
  57. java/pkg/java/lang/management/ThreadInfo$1.class +0 −0
  58. java/pkg/java/lang/management/ThreadInfo.class +0 −0
  59. java/pkg/java/lang/management/ThreadInfo.java +839 −0
  60. java/pkg/java/lang/management/ThreadMXBean.class +0 −0
  61. java/pkg/java/lang/management/ThreadMXBean.java +806 −0
  62. java/pkg/java/lang/management/mkfile +28 −0
  63. java/pkg/java/lang/management/package.html +248 −0
java/pkg/java/lang/management/BufferPoolMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/BufferPoolMXBean.java+93−0
@@ -0,0 +1,93 @@
1+/*
2+ * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for a buffer pool, for example a pool of
30+ * {@link java.nio.ByteBuffer#allocateDirect direct} or {@link
31+ * java.nio.MappedByteBuffer mapped} buffers.
32+ *
33+ * <p> A class implementing this interface is an
34+ * {@link javax.management.MXBean}. A Java
35+ * virtual machine has one or more implementations of this interface. The {@link
36+ * java.lang.management.ManagementFactory#getPlatformMXBeans getPlatformMXBeans}
37+ * method can be used to obtain the list of {@code BufferPoolMXBean} objects
38+ * representing the management interfaces for pools of buffers as follows:
39+ * <pre>
40+ * List&lt;BufferPoolMXBean&gt; pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
41+ * </pre>
42+ *
43+ * <p> The management interfaces are also registered with the platform {@link
44+ * javax.management.MBeanServer MBeanServer}. The {@link
45+ * javax.management.ObjectName ObjectName} that uniquely identifies the
46+ * management interface within the {@code MBeanServer} takes the form:
47+ * <pre>
48+ * java.nio:type=BufferPool,name=<i>pool name</i>
49+ * </pre>
50+ * where <em>pool name</em> is the {@link #getName name} of the buffer pool.
51+ *
52+ * @since 1.7
53+ */
54+public interface BufferPoolMXBean extends PlatformManagedObject {
55+
56+ /**
57+ * Returns the name representing this buffer pool.
58+ *
59+ * @return The name of this buffer pool.
60+ */
61+ String getName();
62+
63+ /**
64+ * Returns an estimate of the number of buffers in the pool.
65+ *
66+ * @return An estimate of the number of buffers in this pool
67+ */
68+ long getCount();
69+
70+ /**
71+ * Returns an estimate of the total capacity of the buffers in this pool.
72+ * A buffer's capacity is the number of elements it contains and the value
73+ * returned by this method is an estimate of the total capacity of buffers
74+ * in the pool in bytes.
75+ *
76+ * @return An estimate of the total capacity of the buffers in this pool
77+ * in bytes
78+ */
79+ long getTotalCapacity();
80+
81+ /**
82+ * Returns an estimate of the memory that the Java virtual machine is using
83+ * for this buffer pool. The value returned by this method may differ
84+ * from the estimate of the total {@link #getTotalCapacity capacity} of
85+ * the buffers in this pool. This difference is explained by alignment,
86+ * memory allocator, and other implementation specific reasons.
87+ *
88+ * @return An estimate of the memory that the Java virtual machine is using
89+ * for this buffer pool in bytes, or {@code -1L} if an estimate of
90+ * the memory usage is not available
91+ */
92+ long getMemoryUsed();
93+}
java/pkg/java/lang/management/ClassLoadingMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ClassLoadingMXBean.java+114−0
@@ -0,0 +1,114 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the class loading system of
30+ * the Java virtual machine.
31+ *
32+ * <p> A Java virtual machine has a single instance of the implementation
33+ * class of this interface. This instance implementing this interface is
34+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
35+ * that can be obtained by calling
36+ * the {@link ManagementFactory#getClassLoadingMXBean} method or
37+ * from the {@link ManagementFactory#getPlatformMBeanServer
38+ * platform <tt>MBeanServer</tt>}.
39+ *
40+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
41+ * the class loading system within an <tt>MBeanServer</tt> is:
42+ * <blockquote>
43+ * {@link ManagementFactory#CLASS_LOADING_MXBEAN_NAME
44+ * <tt>java.lang:type=ClassLoading</tt>}
45+ * </blockquote>
46+ *
47+ * It can be obtained by calling the
48+ * {@link PlatformManagedObject#getObjectName} method.
49+ *
50+ * @see ManagementFactory#getPlatformMXBeans(Class)
51+ * @see <a href="../../../javax/management/package-summary.html">
52+ * JMX Specification.</a>
53+ * @see <a href="package-summary.html#examples">
54+ * Ways to Access MXBeans</a>
55+ *
56+ * @author Mandy Chung
57+ * @since 1.5
58+ */
59+public interface ClassLoadingMXBean extends PlatformManagedObject {
60+
61+ /**
62+ * Returns the total number of classes that have been loaded since
63+ * the Java virtual machine has started execution.
64+ *
65+ * @return the total number of classes loaded.
66+ *
67+ */
68+ public long getTotalLoadedClassCount();
69+
70+ /**
71+ * Returns the number of classes that are currently loaded in the
72+ * Java virtual machine.
73+ *
74+ * @return the number of currently loaded classes.
75+ */
76+ public int getLoadedClassCount();
77+
78+ /**
79+ * Returns the total number of classes unloaded since the Java virtual machine
80+ * has started execution.
81+ *
82+ * @return the total number of unloaded classes.
83+ */
84+ public long getUnloadedClassCount();
85+
86+ /**
87+ * Tests if the verbose output for the class loading system is enabled.
88+ *
89+ * @return <tt>true</tt> if the verbose output for the class loading
90+ * system is enabled; <tt>false</tt> otherwise.
91+ */
92+ public boolean isVerbose();
93+
94+ /**
95+ * Enables or disables the verbose output for the class loading
96+ * system. The verbose output information and the output stream
97+ * to which the verbose information is emitted are implementation
98+ * dependent. Typically, a Java virtual machine implementation
99+ * prints a message each time a class file is loaded.
100+ *
101+ * <p>This method can be called by multiple threads concurrently.
102+ * Each invocation of this method enables or disables the verbose
103+ * output globally.
104+ *
105+ * @param value <tt>true</tt> to enable the verbose output;
106+ * <tt>false</tt> to disable.
107+ *
108+ * @exception java.lang.SecurityException if a security manager
109+ * exists and the caller does not have
110+ * ManagementPermission("control").
111+ */
112+ public void setVerbose(boolean value);
113+
114+}
java/pkg/java/lang/management/CompilationMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/CompilationMXBean.java+101−0
@@ -0,0 +1,101 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the compilation system of
30+ * the Java virtual machine.
31+ *
32+ * <p> A Java virtual machine has a single instance of the implementation
33+ * class of this interface. This instance implementing this interface is
34+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
35+ * that can be obtained by calling
36+ * the {@link ManagementFactory#getCompilationMXBean} method or
37+ * from the {@link ManagementFactory#getPlatformMBeanServer
38+ * platform <tt>MBeanServer</tt>} method.
39+ *
40+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
41+ * the compilation system within an MBeanServer is:
42+ * <blockquote>
43+ * {@link ManagementFactory#COMPILATION_MXBEAN_NAME
44+ * <tt>java.lang:type=Compilation</tt>}
45+ * </blockquote>
46+ *
47+ * It can be obtained by calling the
48+ * {@link PlatformManagedObject#getObjectName} method.
49+ *
50+ * @see ManagementFactory#getPlatformMXBeans(Class)
51+ * @see <a href="../../../javax/management/package-summary.html">
52+ * JMX Specification.</a>
53+ * @see <a href="package-summary.html#examples">
54+ * Ways to Access MXBeans</a>
55+ *
56+ * @author Mandy Chung
57+ * @since 1.5
58+ */
59+public interface CompilationMXBean extends PlatformManagedObject {
60+ /**
61+ * Returns the name of the Just-in-time (JIT) compiler.
62+ *
63+ * @return the name of the JIT compiler.
64+ */
65+ public java.lang.String getName();
66+
67+ /**
68+ * Tests if the Java virtual machine supports the monitoring of
69+ * compilation time.
70+ *
71+ * @return <tt>true</tt> if the monitoring of compilation time is
72+ * supported ; <tt>false</tt> otherwise.
73+ */
74+ public boolean isCompilationTimeMonitoringSupported();
75+
76+ /**
77+ * Returns the approximate accumlated elapsed time (in milliseconds)
78+ * spent in compilation.
79+ * If multiple threads are used for compilation, this value is
80+ * summation of the approximate time that each thread spent in compilation.
81+ *
82+ * <p>This method is optionally supported by the platform.
83+ * A Java virtual machine implementation may not support the compilation
84+ * time monitoring. The {@link #isCompilationTimeMonitoringSupported}
85+ * method can be used to determine if the Java virtual machine
86+ * supports this operation.
87+ *
88+ * <p> This value does not indicate the level of performance of
89+ * the Java virtual machine and is not intended for performance comparisons
90+ * of different virtual machine implementations.
91+ * The implementations may have different definitions and different
92+ * measurements of the compilation time.
93+ *
94+ * @return Compilation time in milliseconds
95+ * @throws java.lang.UnsupportedOperationException if the Java
96+ * virtual machine does not support
97+ * this operation.
98+ *
99+ */
100+ public long getTotalCompilationTime();
101+}
java/pkg/java/lang/management/GarbageCollectorMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/GarbageCollectorMXBean.java+94−0
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the garbage collection of
30+ * the Java virtual machine. Garbage collection is the process
31+ * that the Java virtual machine uses to find and reclaim unreachable
32+ * objects to free up memory space. A garbage collector is one type of
33+ * {@link MemoryManagerMXBean memory manager}.
34+ *
35+ * <p> A Java virtual machine may have one or more instances of
36+ * the implementation class of this interface.
37+ * An instance implementing this interface is
38+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
39+ * that can be obtained by calling
40+ * the {@link ManagementFactory#getGarbageCollectorMXBeans} method or
41+ * from the {@link ManagementFactory#getPlatformMBeanServer
42+ * platform <tt>MBeanServer</tt>} method.
43+ *
44+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
45+ * a garbage collector within an MBeanServer is:
46+ * <blockquote>
47+ * {@link ManagementFactory#GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
48+ * <tt>java.lang:type=GarbageCollector</tt>}<tt>,name=</tt><i>collector's name</i>
49+ * </blockquote>
50+ *
51+ * It can be obtained by calling the
52+ * {@link PlatformManagedObject#getObjectName} method.
53+ *
54+ * A platform usually includes additional platform-dependent information
55+ * specific to a garbage collection algorithm for monitoring.
56+ *
57+ * @see ManagementFactory#getPlatformMXBeans(Class)
58+ * @see MemoryMXBean
59+ *
60+ * @see <a href="../../../javax/management/package-summary.html">
61+ * JMX Specification.</a>
62+ * @see <a href="package-summary.html#examples">
63+ * Ways to Access MXBeans</a>
64+ *
65+ * @author Mandy Chung
66+ * @since 1.5
67+ */
68+public interface GarbageCollectorMXBean extends MemoryManagerMXBean {
69+ /**
70+ * Returns the total number of collections that have occurred.
71+ * This method returns <tt>-1</tt> if the collection count is undefined for
72+ * this collector.
73+ *
74+ * @return the total number of collections that have occurred.
75+ */
76+ public long getCollectionCount();
77+
78+ /**
79+ * Returns the approximate accumulated collection elapsed time
80+ * in milliseconds. This method returns <tt>-1</tt> if the collection
81+ * elapsed time is undefined for this collector.
82+ * <p>
83+ * The Java virtual machine implementation may use a high resolution
84+ * timer to measure the elapsed time. This method may return the
85+ * same value even if the collection count has been incremented
86+ * if the collection elapsed time is very short.
87+ *
88+ * @return the approximate accumulated collection elapsed time
89+ * in milliseconds.
90+ */
91+ public long getCollectionTime();
92+
93+
94+}
java/pkg/java/lang/management/LockInfo.class+0−0

Binary file not shown.

java/pkg/java/lang/management/LockInfo.java+122−0
@@ -0,0 +1,122 @@
1+/*
2+ * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.openmbean.CompositeData;
29+import java.util.concurrent.locks.*;
30+import java.beans.ConstructorProperties;
31+
32+/**
33+ * Information about a <em>lock</em>. A lock can be a built-in object monitor,
34+ * an <em>ownable synchronizer</em>, or the {@link Condition Condition}
35+ * object associated with synchronizers.
36+ * <p>
37+ * <a name="OwnableSynchronizer">An ownable synchronizer</a> is
38+ * a synchronizer that may be exclusively owned by a thread and uses
39+ * {@link AbstractOwnableSynchronizer AbstractOwnableSynchronizer}
40+ * (or its subclass) to implement its synchronization property.
41+ * {@link ReentrantLock ReentrantLock} and
42+ * {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
43+ * two examples of ownable synchronizers provided by the platform.
44+ *
45+ * <h4><a name="MappedType">MXBean Mapping</a></h4>
46+ * <tt>LockInfo</tt> is mapped to a {@link CompositeData CompositeData}
47+ * as specified in the <a href="../../../javax/management/MXBean.html#mapping-rules">
48+ * type mapping rules</a> of {@linkplain javax.management.MXBean MXBeans}.
49+ *
50+ * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
51+ * @see java.util.concurrent.locks.Condition
52+ *
53+ * @author Mandy Chung
54+ * @since 1.6
55+ */
56+
57+public class LockInfo {
58+
59+ private String className;
60+ private int identityHashCode;
61+
62+ /**
63+ * Constructs a <tt>LockInfo</tt> object.
64+ *
65+ * @param className the fully qualified name of the class of the lock object.
66+ * @param identityHashCode the {@link System#identityHashCode
67+ * identity hash code} of the lock object.
68+ */
69+ @ConstructorProperties({"className", "identityHashCode"})
70+ public LockInfo(String className, int identityHashCode) {
71+ if (className == null) {
72+ throw new NullPointerException("Parameter className cannot be null");
73+ }
74+ this.className = className;
75+ this.identityHashCode = identityHashCode;
76+ }
77+
78+ /**
79+ * package-private constructors
80+ */
81+ LockInfo(Object lock) {
82+ this.className = lock.getClass().getName();
83+ this.identityHashCode = System.identityHashCode(lock);
84+ }
85+
86+ /**
87+ * Returns the fully qualified name of the class of the lock object.
88+ *
89+ * @return the fully qualified name of the class of the lock object.
90+ */
91+ public String getClassName() {
92+ return className;
93+ }
94+
95+ /**
96+ * Returns the identity hash code of the lock object
97+ * returned from the {@link System#identityHashCode} method.
98+ *
99+ * @return the identity hash code of the lock object.
100+ */
101+ public int getIdentityHashCode() {
102+ return identityHashCode;
103+ }
104+
105+ /**
106+ * Returns a string representation of a lock. The returned
107+ * string representation consists of the name of the class of the
108+ * lock object, the at-sign character `@', and the unsigned
109+ * hexadecimal representation of the <em>identity</em> hash code
110+ * of the object. This method returns a string equals to the value of:
111+ * <blockquote>
112+ * <pre>
113+ * lock.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(lock))
114+ * </pre></blockquote>
115+ * where <tt>lock</tt> is the lock object.
116+ *
117+ * @return the string representation of a lock.
118+ */
119+ public String toString() {
120+ return className + '@' + Integer.toHexString(identityHashCode);
121+ }
122+}
java/pkg/java/lang/management/ManagementFactory$1.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ManagementFactory$2.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ManagementFactory.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ManagementFactory.java+828−0
@@ -0,0 +1,828 @@
1+/*
2+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+import javax.management.DynamicMBean;
28+import javax.management.MBeanServer;
29+import javax.management.MBeanServerConnection;
30+import javax.management.MBeanServerFactory;
31+import javax.management.MBeanServerPermission;
32+import javax.management.NotificationEmitter;
33+import javax.management.ObjectInstance;
34+import javax.management.ObjectName;
35+import javax.management.InstanceAlreadyExistsException;
36+import javax.management.InstanceNotFoundException;
37+import javax.management.MalformedObjectNameException;
38+import javax.management.MBeanRegistrationException;
39+import javax.management.NotCompliantMBeanException;
40+import javax.management.StandardEmitterMBean;
41+import javax.management.StandardMBean;
42+import java.util.Collections;
43+import java.util.List;
44+import java.util.Set;
45+import java.util.TreeSet;
46+import java.security.AccessController;
47+import java.security.Permission;
48+import java.security.PrivilegedAction;
49+import java.security.PrivilegedActionException;
50+import java.security.PrivilegedExceptionAction;
51+import javax.management.JMX;
52+import sun.management.ManagementFactoryHelper;
53+
54+/**
55+ * The {@code ManagementFactory} class is a factory class for getting
56+ * managed beans for the Java platform.
57+ * This class consists of static methods each of which returns
58+ * one or more <i>platform MXBeans</i> representing
59+ * the management interface of a component of the Java virtual
60+ * machine.
61+ * <p>
62+ * <h4><a name="MXBean">Platform MXBeans</a></h4>
63+ * <p>
64+ * A platform MXBean is a <i>managed bean</i> that
65+ * conforms to the <a href="../../../javax/management/package-summary.html">JMX</a>
66+ * Instrumentation Specification and only uses a set of basic data types.
67+ * A JMX management application and the {@linkplain
68+ * #getPlatformMBeanServer platform MBeanServer}
69+ * can interoperate without requiring classes for MXBean specific
70+ * data types.
71+ * The data types being transmitted between the JMX connector
72+ * server and the connector client are
73+ * {@linkplain javax.management.openmbean.OpenType open types}
74+ * and this allows interoperation across versions.
75+ * See <a href="../../../javax/management/MXBean.html#MXBean-spec">
76+ * the specification of MXBeans</a> for details.
77+ *
78+ * <a name="MXBeanNames"></a>
79+ * <p>Each platform MXBean is a {@link PlatformManagedObject}
80+ * and it has a unique
81+ * {@link javax.management.ObjectName ObjectName} for
82+ * registration in the platform {@code MBeanServer} as returned by
83+ * by the {@link PlatformManagedObject#getObjectName getObjectName}
84+ * method.
85+ *
86+ * <p>
87+ * An application can access a platform MXBean in the following ways:
88+ * <h5>1. Direct access to an MXBean interface</h5>
89+ * <blockquote>
90+ * <ul>
91+ * <li>Get an MXBean instance by calling the
92+ * {@link #getPlatformMXBean(Class) getPlatformMXBean} or
93+ * {@link #getPlatformMXBeans(Class) getPlatformMXBeans} method
94+ * and access the MXBean locally in the running
95+ * virtual machine.
96+ * </li>
97+ * <li>Construct an MXBean proxy instance that forwards the
98+ * method calls to a given {@link MBeanServer MBeanServer} by calling
99+ * the {@link #getPlatformMXBean(MBeanServerConnection, Class)} or
100+ * {@link #getPlatformMXBeans(MBeanServerConnection, Class)} method.
101+ * The {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method
102+ * can also be used to construct an MXBean proxy instance of
103+ * a given {@code ObjectName}.
104+ * A proxy is typically constructed to remotely access
105+ * an MXBean of another running virtual machine.
106+ * </li>
107+ * </ul>
108+ * <h5>2. Indirect access to an MXBean interface via MBeanServer</h5>
109+ * <ul>
110+ * <li>Go through the platform {@code MBeanServer} to access MXBeans
111+ * locally or a specific <tt>MBeanServerConnection</tt> to access
112+ * MXBeans remotely.
113+ * The attributes and operations of an MXBean use only
114+ * <em>JMX open types</em> which include basic data types,
115+ * {@link javax.management.openmbean.CompositeData CompositeData},
116+ * and {@link javax.management.openmbean.TabularData TabularData}
117+ * defined in
118+ * {@link javax.management.openmbean.OpenType OpenType}.
119+ * The mapping is specified in
120+ * the {@linkplain javax.management.MXBean MXBean} specification
121+ * for details.
122+ * </li>
123+ * </ul>
124+ * </blockquote>
125+ *
126+ * <p>
127+ * The {@link #getPlatformManagementInterfaces getPlatformManagementInterfaces}
128+ * method returns all management interfaces supported in the Java virtual machine
129+ * including the standard management interfaces listed in the tables
130+ * below as well as the management interfaces extended by the JDK implementation.
131+ * <p>
132+ * A Java virtual machine has a single instance of the following management
133+ * interfaces:
134+ *
135+ * <blockquote>
136+ * <table border>
137+ * <tr>
138+ * <th>Management Interface</th>
139+ * <th>ObjectName</th>
140+ * </tr>
141+ * <tr>
142+ * <td> {@link ClassLoadingMXBean} </td>
143+ * <td> {@link #CLASS_LOADING_MXBEAN_NAME
144+ * java.lang:type=ClassLoading}</td>
145+ * </tr>
146+ * <tr>
147+ * <td> {@link MemoryMXBean} </td>
148+ * <td> {@link #MEMORY_MXBEAN_NAME
149+ * java.lang:type=Memory}</td>
150+ * </tr>
151+ * <tr>
152+ * <td> {@link ThreadMXBean} </td>
153+ * <td> {@link #THREAD_MXBEAN_NAME
154+ * java.lang:type=Threading}</td>
155+ * </tr>
156+ * <tr>
157+ * <td> {@link RuntimeMXBean} </td>
158+ * <td> {@link #RUNTIME_MXBEAN_NAME
159+ * java.lang:type=Runtime}</td>
160+ * </tr>
161+ * <tr>
162+ * <td> {@link OperatingSystemMXBean} </td>
163+ * <td> {@link #OPERATING_SYSTEM_MXBEAN_NAME
164+ * java.lang:type=OperatingSystem}</td>
165+ * </tr>
166+ * <tr>
167+ * <td> {@link PlatformLoggingMXBean} </td>
168+ * <td> {@link java.util.logging.LogManager#LOGGING_MXBEAN_NAME
169+ * java.util.logging:type=Logging}</td>
170+ * </tr>
171+ * </table>
172+ * </blockquote>
173+ *
174+ * <p>
175+ * A Java virtual machine has zero or a single instance of
176+ * the following management interfaces.
177+ *
178+ * <blockquote>
179+ * <table border>
180+ * <tr>
181+ * <th>Management Interface</th>
182+ * <th>ObjectName</th>
183+ * </tr>
184+ * <tr>
185+ * <td> {@link CompilationMXBean} </td>
186+ * <td> {@link #COMPILATION_MXBEAN_NAME
187+ * java.lang:type=Compilation}</td>
188+ * </tr>
189+ * </table>
190+ * </blockquote>
191+ *
192+ * <p>
193+ * A Java virtual machine may have one or more instances of the following
194+ * management interfaces.
195+ * <blockquote>
196+ * <table border>
197+ * <tr>
198+ * <th>Management Interface</th>
199+ * <th>ObjectName</th>
200+ * </tr>
201+ * <tr>
202+ * <td> {@link GarbageCollectorMXBean} </td>
203+ * <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
204+ * java.lang:type=GarbageCollector}<tt>,name=</tt><i>collector's name</i></td>
205+ * </tr>
206+ * <tr>
207+ * <td> {@link MemoryManagerMXBean} </td>
208+ * <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
209+ * java.lang:type=MemoryManager}<tt>,name=</tt><i>manager's name</i></td>
210+ * </tr>
211+ * <tr>
212+ * <td> {@link MemoryPoolMXBean} </td>
213+ * <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE
214+ * java.lang:type=MemoryPool}<tt>,name=</tt><i>pool's name</i></td>
215+ * </tr>
216+ * <tr>
217+ * <td> {@link BufferPoolMXBean} </td>
218+ * <td> {@code java.nio:type=BufferPool,name=}<i>pool name</i></td>
219+ * </tr>
220+ * </table>
221+ * </blockquote>
222+ *
223+ * @see <a href="../../../javax/management/package-summary.html">
224+ * JMX Specification</a>
225+ * @see <a href="package-summary.html#examples">
226+ * Ways to Access Management Metrics</a>
227+ * @see javax.management.MXBean
228+ *
229+ * @author Mandy Chung
230+ * @since 1.5
231+ */
232+public class ManagementFactory {
233+ // A class with only static fields and methods.
234+ private ManagementFactory() {};
235+
236+ /**
237+ * String representation of the
238+ * <tt>ObjectName</tt> for the {@link ClassLoadingMXBean}.
239+ */
240+ public final static String CLASS_LOADING_MXBEAN_NAME =
241+ "java.lang:type=ClassLoading";
242+
243+ /**
244+ * String representation of the
245+ * <tt>ObjectName</tt> for the {@link CompilationMXBean}.
246+ */
247+ public final static String COMPILATION_MXBEAN_NAME =
248+ "java.lang:type=Compilation";
249+
250+ /**
251+ * String representation of the
252+ * <tt>ObjectName</tt> for the {@link MemoryMXBean}.
253+ */
254+ public final static String MEMORY_MXBEAN_NAME =
255+ "java.lang:type=Memory";
256+
257+ /**
258+ * String representation of the
259+ * <tt>ObjectName</tt> for the {@link OperatingSystemMXBean}.
260+ */
261+ public final static String OPERATING_SYSTEM_MXBEAN_NAME =
262+ "java.lang:type=OperatingSystem";
263+
264+ /**
265+ * String representation of the
266+ * <tt>ObjectName</tt> for the {@link RuntimeMXBean}.
267+ */
268+ public final static String RUNTIME_MXBEAN_NAME =
269+ "java.lang:type=Runtime";
270+
271+ /**
272+ * String representation of the
273+ * <tt>ObjectName</tt> for the {@link ThreadMXBean}.
274+ */
275+ public final static String THREAD_MXBEAN_NAME =
276+ "java.lang:type=Threading";
277+
278+ /**
279+ * The domain name and the type key property in
280+ * the <tt>ObjectName</tt> for a {@link GarbageCollectorMXBean}.
281+ * The unique <tt>ObjectName</tt> for a <tt>GarbageCollectorMXBean</tt>
282+ * can be formed by appending this string with
283+ * "<tt>,name=</tt><i>collector's name</i>".
284+ */
285+ public final static String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE =
286+ "java.lang:type=GarbageCollector";
287+
288+ /**
289+ * The domain name and the type key property in
290+ * the <tt>ObjectName</tt> for a {@link MemoryManagerMXBean}.
291+ * The unique <tt>ObjectName</tt> for a <tt>MemoryManagerMXBean</tt>
292+ * can be formed by appending this string with
293+ * "<tt>,name=</tt><i>manager's name</i>".
294+ */
295+ public final static String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE=
296+ "java.lang:type=MemoryManager";
297+
298+ /**
299+ * The domain name and the type key property in
300+ * the <tt>ObjectName</tt> for a {@link MemoryPoolMXBean}.
301+ * The unique <tt>ObjectName</tt> for a <tt>MemoryPoolMXBean</tt>
302+ * can be formed by appending this string with
303+ * <tt>,name=</tt><i>pool's name</i>.
304+ */
305+ public final static String MEMORY_POOL_MXBEAN_DOMAIN_TYPE=
306+ "java.lang:type=MemoryPool";
307+
308+ /**
309+ * Returns the managed bean for the class loading system of
310+ * the Java virtual machine.
311+ *
312+ * @return a {@link ClassLoadingMXBean} object for
313+ * the Java virtual machine.
314+ */
315+ public static ClassLoadingMXBean getClassLoadingMXBean() {
316+ return ManagementFactoryHelper.getClassLoadingMXBean();
317+ }
318+
319+ /**
320+ * Returns the managed bean for the memory system of
321+ * the Java virtual machine.
322+ *
323+ * @return a {@link MemoryMXBean} object for the Java virtual machine.
324+ */
325+ public static MemoryMXBean getMemoryMXBean() {
326+ return ManagementFactoryHelper.getMemoryMXBean();
327+ }
328+
329+ /**
330+ * Returns the managed bean for the thread system of
331+ * the Java virtual machine.
332+ *
333+ * @return a {@link ThreadMXBean} object for the Java virtual machine.
334+ */
335+ public static ThreadMXBean getThreadMXBean() {
336+ return ManagementFactoryHelper.getThreadMXBean();
337+ }
338+
339+ /**
340+ * Returns the managed bean for the runtime system of
341+ * the Java virtual machine.
342+ *
343+ * @return a {@link RuntimeMXBean} object for the Java virtual machine.
344+
345+ */
346+ public static RuntimeMXBean getRuntimeMXBean() {
347+ return ManagementFactoryHelper.getRuntimeMXBean();
348+ }
349+
350+ /**
351+ * Returns the managed bean for the compilation system of
352+ * the Java virtual machine. This method returns <tt>null</tt>
353+ * if the Java virtual machine has no compilation system.
354+ *
355+ * @return a {@link CompilationMXBean} object for the Java virtual
356+ * machine or <tt>null</tt> if the Java virtual machine has
357+ * no compilation system.
358+ */
359+ public static CompilationMXBean getCompilationMXBean() {
360+ return ManagementFactoryHelper.getCompilationMXBean();
361+ }
362+
363+ /**
364+ * Returns the managed bean for the operating system on which
365+ * the Java virtual machine is running.
366+ *
367+ * @return an {@link OperatingSystemMXBean} object for
368+ * the Java virtual machine.
369+ */
370+ public static OperatingSystemMXBean getOperatingSystemMXBean() {
371+ return ManagementFactoryHelper.getOperatingSystemMXBean();
372+ }
373+
374+ /**
375+ * Returns a list of {@link MemoryPoolMXBean} objects in the
376+ * Java virtual machine.
377+ * The Java virtual machine can have one or more memory pools.
378+ * It may add or remove memory pools during execution.
379+ *
380+ * @return a list of <tt>MemoryPoolMXBean</tt> objects.
381+ *
382+ */
383+ public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
384+ return ManagementFactoryHelper.getMemoryPoolMXBeans();
385+ }
386+
387+ /**
388+ * Returns a list of {@link MemoryManagerMXBean} objects
389+ * in the Java virtual machine.
390+ * The Java virtual machine can have one or more memory managers.
391+ * It may add or remove memory managers during execution.
392+ *
393+ * @return a list of <tt>MemoryManagerMXBean</tt> objects.
394+ *
395+ */
396+ public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
397+ return ManagementFactoryHelper.getMemoryManagerMXBeans();
398+ }
399+
400+
401+ /**
402+ * Returns a list of {@link GarbageCollectorMXBean} objects
403+ * in the Java virtual machine.
404+ * The Java virtual machine may have one or more
405+ * <tt>GarbageCollectorMXBean</tt> objects.
406+ * It may add or remove <tt>GarbageCollectorMXBean</tt>
407+ * during execution.
408+ *
409+ * @return a list of <tt>GarbageCollectorMXBean</tt> objects.
410+ *
411+ */
412+ public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
413+ return ManagementFactoryHelper.getGarbageCollectorMXBeans();
414+ }
415+
416+ private static MBeanServer platformMBeanServer;
417+ /**
418+ * Returns the platform {@link javax.management.MBeanServer MBeanServer}.
419+ * On the first call to this method, it first creates the platform
420+ * {@code MBeanServer} by calling the
421+ * {@link javax.management.MBeanServerFactory#createMBeanServer
422+ * MBeanServerFactory.createMBeanServer}
423+ * method and registers each platform MXBean in this platform
424+ * {@code MBeanServer} with its
425+ * {@link PlatformManagedObject#getObjectName ObjectName}.
426+ * This method, in subsequent calls, will simply return the
427+ * initially created platform {@code MBeanServer}.
428+ * <p>
429+ * MXBeans that get created and destroyed dynamically, for example,
430+ * memory {@link MemoryPoolMXBean pools} and
431+ * {@link MemoryManagerMXBean managers},
432+ * will automatically be registered and deregistered into the platform
433+ * {@code MBeanServer}.
434+ * <p>
435+ * If the system property {@code javax.management.builder.initial}
436+ * is set, the platform {@code MBeanServer} creation will be done
437+ * by the specified {@link javax.management.MBeanServerBuilder}.
438+ * <p>
439+ * It is recommended that this platform MBeanServer also be used
440+ * to register other application managed beans
441+ * besides the platform MXBeans.
442+ * This will allow all MBeans to be published through the same
443+ * {@code MBeanServer} and hence allow for easier network publishing
444+ * and discovery.
445+ * Name conflicts with the platform MXBeans should be avoided.
446+ *
447+ * @return the platform {@code MBeanServer}; the platform
448+ * MXBeans are registered into the platform {@code MBeanServer}
449+ * at the first time this method is called.
450+ *
451+ * @exception SecurityException if there is a security manager
452+ * and the caller does not have the permission required by
453+ * {@link javax.management.MBeanServerFactory#createMBeanServer}.
454+ *
455+ * @see javax.management.MBeanServerFactory
456+ * @see javax.management.MBeanServerFactory#createMBeanServer
457+ */
458+ public static synchronized MBeanServer getPlatformMBeanServer() {
459+ SecurityManager sm = System.getSecurityManager();
460+ if (sm != null) {
461+ Permission perm = new MBeanServerPermission("createMBeanServer");
462+ sm.checkPermission(perm);
463+ }
464+
465+ if (platformMBeanServer == null) {
466+ platformMBeanServer = MBeanServerFactory.createMBeanServer();
467+ for (PlatformComponent pc : PlatformComponent.values()) {
468+ List<? extends PlatformManagedObject> list =
469+ pc.getMXBeans(pc.getMXBeanInterface());
470+ for (PlatformManagedObject o : list) {
471+ // Each PlatformComponent represents one management
472+ // interface. Some MXBean may extend another one.
473+ // The MXBean instances for one platform component
474+ // (returned by pc.getMXBeans()) might be also
475+ // the MXBean instances for another platform component.
476+ // e.g. com.sun.management.GarbageCollectorMXBean
477+ //
478+ // So need to check if an MXBean instance is registered
479+ // before registering into the platform MBeanServer
480+ if (!platformMBeanServer.isRegistered(o.getObjectName())) {
481+ addMXBean(platformMBeanServer, o);
482+ }
483+ }
484+ }
485+ }
486+ return platformMBeanServer;
487+ }
488+
489+ /**
490+ * Returns a proxy for a platform MXBean interface of a
491+ * given <a href="#MXBeanNames">MXBean name</a>
492+ * that forwards its method calls through the given
493+ * <tt>MBeanServerConnection</tt>.
494+ *
495+ * <p>This method is equivalent to:
496+ * <blockquote>
497+ * {@link java.lang.reflect.Proxy#newProxyInstance
498+ * Proxy.newProxyInstance}<tt>(mxbeanInterface.getClassLoader(),
499+ * new Class[] { mxbeanInterface }, handler)</tt>
500+ * </blockquote>
501+ *
502+ * where <tt>handler</tt> is an {@link java.lang.reflect.InvocationHandler
503+ * InvocationHandler} to which method invocations to the MXBean interface
504+ * are dispatched. This <tt>handler</tt> converts an input parameter
505+ * from an MXBean data type to its mapped open type before forwarding
506+ * to the <tt>MBeanServer</tt> and converts a return value from
507+ * an MXBean method call through the <tt>MBeanServer</tt>
508+ * from an open type to the corresponding return type declared in
509+ * the MXBean interface.
510+ *
511+ * <p>
512+ * If the MXBean is a notification emitter (i.e.,
513+ * it implements
514+ * {@link javax.management.NotificationEmitter NotificationEmitter}),
515+ * both the <tt>mxbeanInterface</tt> and <tt>NotificationEmitter</tt>
516+ * will be implemented by this proxy.
517+ *
518+ * <p>
519+ * <b>Notes:</b>
520+ * <ol>
521+ * <li>Using an MXBean proxy is a convenience remote access to
522+ * a platform MXBean of a running virtual machine. All method
523+ * calls to the MXBean proxy are forwarded to an
524+ * <tt>MBeanServerConnection</tt> where
525+ * {@link java.io.IOException IOException} may be thrown
526+ * when the communication problem occurs with the connector server.
527+ * An application remotely accesses the platform MXBeans using
528+ * proxy should prepare to catch <tt>IOException</tt> as if
529+ * accessing with the <tt>MBeanServerConnector</tt> interface.</li>
530+ *
531+ * <li>When a client application is designed to remotely access MXBeans
532+ * for a running virtual machine whose version is different than
533+ * the version on which the application is running,
534+ * it should prepare to catch
535+ * {@link java.io.InvalidObjectException InvalidObjectException}
536+ * which is thrown when an MXBean proxy receives a name of an
537+ * enum constant which is missing in the enum class loaded in
538+ * the client application. </li>
539+ *
540+ * <li>{@link javax.management.MBeanServerInvocationHandler
541+ * MBeanServerInvocationHandler} or its
542+ * {@link javax.management.MBeanServerInvocationHandler#newProxyInstance
543+ * newProxyInstance} method cannot be used to create
544+ * a proxy for a platform MXBean. The proxy object created
545+ * by <tt>MBeanServerInvocationHandler</tt> does not handle
546+ * the properties of the platform MXBeans described in
547+ * the <a href="#MXBean">class specification</a>.
548+ *</li>
549+ * </ol>
550+ *
551+ * @param connection the <tt>MBeanServerConnection</tt> to forward to.
552+ * @param mxbeanName the name of a platform MXBean within
553+ * <tt>connection</tt> to forward to. <tt>mxbeanName</tt> must be
554+ * in the format of {@link ObjectName ObjectName}.
555+ * @param mxbeanInterface the MXBean interface to be implemented
556+ * by the proxy.
557+ *
558+ * @throws IllegalArgumentException if
559+ * <ul>
560+ * <li><tt>mxbeanName</tt> is not with a valid
561+ * {@link ObjectName ObjectName} format, or</li>
562+ * <li>the named MXBean in the <tt>connection</tt> is
563+ * not a MXBean provided by the platform, or</li>
564+ * <li>the named MXBean is not registered in the
565+ * <tt>MBeanServerConnection</tt>, or</li>
566+ * <li>the named MXBean is not an instance of the given
567+ * <tt>mxbeanInterface</tt></li>
568+ * </ul>
569+ *
570+ * @throws java.io.IOException if a communication problem
571+ * occurred when accessing the <tt>MBeanServerConnection</tt>.
572+ */
573+ public static <T> T
574+ newPlatformMXBeanProxy(MBeanServerConnection connection,
575+ String mxbeanName,
576+ Class<T> mxbeanInterface)
577+ throws java.io.IOException {
578+
579+ final Class interfaceClass = mxbeanInterface;
580+ // Only allow MXBean interfaces from rt.jar loaded by the
581+ // bootstrap class loader
582+ final ClassLoader loader =
583+ AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
584+ public ClassLoader run() {
585+ return interfaceClass.getClassLoader();
586+ }
587+ });
588+ if (loader != null) {
589+ throw new IllegalArgumentException(mxbeanName +
590+ " is not a platform MXBean");
591+ }
592+
593+ try {
594+ final ObjectName objName = new ObjectName(mxbeanName);
595+ // skip the isInstanceOf check for LoggingMXBean
596+ String intfName = interfaceClass.getName();
597+ if (!connection.isInstanceOf(objName, intfName)) {
598+ throw new IllegalArgumentException(mxbeanName +
599+ " is not an instance of " + interfaceClass);
600+ }
601+
602+ final Class[] interfaces;
603+ // check if the registered MBean is a notification emitter
604+ boolean emitter = connection.isInstanceOf(objName, NOTIF_EMITTER);
605+
606+ // create an MXBean proxy
607+ return JMX.newMXBeanProxy(connection, objName, mxbeanInterface,
608+ emitter);
609+ } catch (InstanceNotFoundException|MalformedObjectNameException e) {
610+ throw new IllegalArgumentException(e);
611+ }
612+ }
613+
614+ /**
615+ * Returns the platform MXBean implementing
616+ * the given {@code mxbeanInterface} which is specified
617+ * to have one single instance in the Java virtual machine.
618+ * This method may return {@code null} if the management interface
619+ * is not implemented in the Java virtual machine (for example,
620+ * a Java virtual machine with no compilation system does not
621+ * implement {@link CompilationMXBean});
622+ * otherwise, this method is equivalent to calling:
623+ * <pre>
624+ * {@link #getPlatformMXBeans(Class)
625+ * getPlatformMXBeans(mxbeanInterface)}.get(0);
626+ * </pre>
627+ *
628+ * @param mxbeanInterface a management interface for a platform
629+ * MXBean with one single instance in the Java virtual machine
630+ * if implemented.
631+ *
632+ * @return the platform MXBean that implements
633+ * {@code mxbeanInterface}, or {@code null} if not exist.
634+ *
635+ * @throws IllegalArgumentException if {@code mxbeanInterface}
636+ * is not a platform management interface or
637+ * not a singleton platform MXBean.
638+ *
639+ * @since 1.7
640+ */
641+ public static <T extends PlatformManagedObject>
642+ T getPlatformMXBean(Class<T> mxbeanInterface) {
643+ PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface);
644+ if (pc == null)
645+ throw new IllegalArgumentException(mxbeanInterface.getName() +
646+ " is not a platform management interface");
647+ if (!pc.isSingleton())
648+ throw new IllegalArgumentException(mxbeanInterface.getName() +
649+ " can have zero or more than one instances");
650+
651+ return pc.getSingletonMXBean(mxbeanInterface);
652+ }
653+
654+ /**
655+ * Returns the list of platform MXBeans implementing
656+ * the given {@code mxbeanInterface} in the Java
657+ * virtual machine.
658+ * The returned list may contain zero, one, or more instances.
659+ * The number of instances in the returned list is defined
660+ * in the specification of the given management interface.
661+ * The order is undefined and there is no guarantee that
662+ * the list returned is in the same order as previous invocations.
663+ *
664+ * @param mxbeanInterface a management interface for a platform
665+ * MXBean
666+ *
667+ * @return the list of platform MXBeans that implement
668+ * {@code mxbeanInterface}.
669+ *
670+ * @throws IllegalArgumentException if {@code mxbeanInterface}
671+ * is not a platform management interface.
672+ *
673+ * @since 1.7
674+ */
675+ public static <T extends PlatformManagedObject> List<T>
676+ getPlatformMXBeans(Class<T> mxbeanInterface) {
677+ PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface);
678+ if (pc == null)
679+ throw new IllegalArgumentException(mxbeanInterface.getName() +
680+ " is not a platform management interface");
681+ return Collections.unmodifiableList(pc.getMXBeans(mxbeanInterface));
682+ }
683+
684+ /**
685+ * Returns the platform MXBean proxy for
686+ * {@code mxbeanInterface} which is specified to have one single
687+ * instance in a Java virtual machine and the proxy will
688+ * forward the method calls through the given {@code MBeanServerConnection}.
689+ * This method may return {@code null} if the management interface
690+ * is not implemented in the Java virtual machine being monitored
691+ * (for example, a Java virtual machine with no compilation system
692+ * does not implement {@link CompilationMXBean});
693+ * otherwise, this method is equivalent to calling:
694+ * <pre>
695+ * {@link #getPlatformMXBeans(MBeanServerConnection, Class)
696+ * getPlatformMXBeans(connection, mxbeanInterface)}.get(0);
697+ * </pre>
698+ *
699+ * @param connection the {@code MBeanServerConnection} to forward to.
700+ * @param mxbeanInterface a management interface for a platform
701+ * MXBean with one single instance in the Java virtual machine
702+ * being monitored, if implemented.
703+ *
704+ * @return the platform MXBean proxy for
705+ * forwarding the method calls of the {@code mxbeanInterface}
706+ * through the given {@code MBeanServerConnection},
707+ * or {@code null} if not exist.
708+ *
709+ * @throws IllegalArgumentException if {@code mxbeanInterface}
710+ * is not a platform management interface or
711+ * not a singleton platform MXBean.
712+ * @throws java.io.IOException if a communication problem
713+ * occurred when accessing the {@code MBeanServerConnection}.
714+ *
715+ * @see #newPlatformMXBeanProxy
716+ * @since 1.7
717+ */
718+ public static <T extends PlatformManagedObject>
719+ T getPlatformMXBean(MBeanServerConnection connection,
720+ Class<T> mxbeanInterface)
721+ throws java.io.IOException
722+ {
723+ PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface);
724+ if (pc == null)
725+ throw new IllegalArgumentException(mxbeanInterface.getName() +
726+ " is not a platform management interface");
727+ if (!pc.isSingleton())
728+ throw new IllegalArgumentException(mxbeanInterface.getName() +
729+ " can have zero or more than one instances");
730+ return pc.getSingletonMXBean(connection, mxbeanInterface);
731+ }
732+
733+ /**
734+ * Returns the list of the platform MXBean proxies for
735+ * forwarding the method calls of the {@code mxbeanInterface}
736+ * through the given {@code MBeanServerConnection}.
737+ * The returned list may contain zero, one, or more instances.
738+ * The number of instances in the returned list is defined
739+ * in the specification of the given management interface.
740+ * The order is undefined and there is no guarantee that
741+ * the list returned is in the same order as previous invocations.
742+ *
743+ * @param connection the {@code MBeanServerConnection} to forward to.
744+ * @param mxbeanInterface a management interface for a platform
745+ * MXBean
746+ *
747+ * @return the list of platform MXBean proxies for
748+ * forwarding the method calls of the {@code mxbeanInterface}
749+ * through the given {@code MBeanServerConnection}.
750+ *
751+ * @throws IllegalArgumentException if {@code mxbeanInterface}
752+ * is not a platform management interface.
753+ *
754+ * @throws java.io.IOException if a communication problem
755+ * occurred when accessing the {@code MBeanServerConnection}.
756+ *
757+ * @see #newPlatformMXBeanProxy
758+ * @since 1.7
759+ */
760+ public static <T extends PlatformManagedObject>
761+ List<T> getPlatformMXBeans(MBeanServerConnection connection,
762+ Class<T> mxbeanInterface)
763+ throws java.io.IOException
764+ {
765+ PlatformComponent pc = PlatformComponent.getPlatformComponent(mxbeanInterface);
766+ if (pc == null) {
767+ throw new IllegalArgumentException(mxbeanInterface.getName() +
768+ " is not a platform management interface");
769+ }
770+ return Collections.unmodifiableList(pc.getMXBeans(connection, mxbeanInterface));
771+ }
772+
773+ /**
774+ * Returns the set of {@code Class} objects, subinterface of
775+ * {@link PlatformManagedObject}, representing
776+ * all management interfaces for
777+ * monitoring and managing the Java platform.
778+ *
779+ * @return the set of {@code Class} objects, subinterface of
780+ * {@link PlatformManagedObject} representing
781+ * the management interfaces for
782+ * monitoring and managing the Java platform.
783+ *
784+ * @since 1.7
785+ */
786+ public static Set<Class<? extends PlatformManagedObject>>
787+ getPlatformManagementInterfaces()
788+ {
789+ Set<Class<? extends PlatformManagedObject>> result =
790+ new TreeSet<>();
791+ for (PlatformComponent component: PlatformComponent.values()) {
792+ result.add(component.getMXBeanInterface());
793+ }
794+ return Collections.unmodifiableSet(result);
795+ }
796+
797+ private static final String NOTIF_EMITTER =
798+ "javax.management.NotificationEmitter";
799+
800+ /**
801+ * Registers an MXBean.
802+ */
803+ private static void addMXBean(final MBeanServer mbs, final PlatformManagedObject pmo) {
804+ // Make DynamicMBean out of MXBean by wrapping it with a StandardMBean
805+ final DynamicMBean dmbean;
806+ if (pmo instanceof DynamicMBean) {
807+ dmbean = DynamicMBean.class.cast(pmo);
808+ } else if (pmo instanceof NotificationEmitter) {
809+ dmbean = new StandardEmitterMBean(pmo, null, true, (NotificationEmitter) pmo);
810+ } else {
811+ dmbean = new StandardMBean(pmo, null, true);
812+ }
813+
814+ try {
815+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
816+ public Void run() throws InstanceAlreadyExistsException,
817+ MBeanRegistrationException,
818+ NotCompliantMBeanException {
819+ mbs.registerMBean(dmbean, pmo.getObjectName());
820+ return null;
821+ }
822+ });
823+ } catch (PrivilegedActionException e) {
824+ throw new RuntimeException(e.getException());
825+ }
826+ }
827+
828+}
java/pkg/java/lang/management/ManagementPermission.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ManagementPermission.java+123−0
@@ -0,0 +1,123 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The permission which the SecurityManager will check when code
30+ * that is running with a SecurityManager calls methods defined
31+ * in the management interface for the Java platform.
32+ * <P>
33+ * The following table
34+ * provides a summary description of what the permission allows,
35+ * and discusses the risks of granting code the permission.
36+ * <P>
37+ *
38+ * <table border=1 cellpadding=5 summary="Table shows permission target name, wh
39+at the permission allows, and associated risks">
40+ * <tr>
41+ * <th>Permission Target Name</th>
42+ * <th>What the Permission Allows</th>
43+ * <th>Risks of Allowing this Permission</th>
44+ * </tr>
45+ *
46+ * <tr>
47+ * <td>control</td>
48+ * <td>Ability to control the runtime characteristics of the Java virtual
49+ * machine, for example, setting the -verbose:gc and -verbose:class flag,
50+ * setting the threshold of a memory pool, and enabling and disabling
51+ * the thread contention monitoring support.
52+ * </td>
53+ * <td>This allows an attacker to control the runtime characteristics
54+ * of the Java virtual machine and cause the system to misbehave.
55+ * </td>
56+ * </tr>
57+ * <tr>
58+ * <td>monitor</td>
59+ * <td>Ability to retrieve runtime information about
60+ * the Java virtual machine such as thread
61+ * stack trace, a list of all loaded class names, and input arguments
62+ * to the Java virtual machine.</td>
63+ * <td>This allows malicious code to monitor runtime information and
64+ * uncover vulnerabilities.</td>
65+ * </tr>
66+ *
67+ * </table>
68+ *
69+ * <p>
70+ * Programmers do not normally create ManagementPermission objects directly.
71+ * Instead they are created by the security policy code based on reading
72+ * the security policy file.
73+ *
74+ * @author Mandy Chung
75+ * @since 1.5
76+ *
77+ * @see java.security.BasicPermission
78+ * @see java.security.Permission
79+ * @see java.security.Permissions
80+ * @see java.security.PermissionCollection
81+ * @see java.lang.SecurityManager
82+ *
83+ */
84+
85+public final class ManagementPermission extends java.security.BasicPermission {
86+ private static final long serialVersionUID = 1897496590799378737L;
87+
88+ /**
89+ * Constructs a ManagementPermission with the specified name.
90+ *
91+ * @param name Permission name. Must be either "monitor" or "control".
92+ *
93+ * @throws NullPointerException if <code>name</code> is <code>null</code>.
94+ * @throws IllegalArgumentException if <code>name</code> is empty or invalid.
95+ */
96+ public ManagementPermission(String name) {
97+ super(name);
98+ if (!name.equals("control") && !name.equals("monitor")) {
99+ throw new IllegalArgumentException("name: " + name);
100+ }
101+ }
102+
103+ /**
104+ * Constructs a new ManagementPermission object.
105+ *
106+ * @param name Permission name. Must be either "monitor" or "control".
107+ * @param actions Must be either null or the empty string.
108+ *
109+ * @throws NullPointerException if <code>name</code> is <code>null</code>.
110+ * @throws IllegalArgumentException if <code>name</code> is empty or
111+ * if arguments are invalid.
112+ */
113+ public ManagementPermission(String name, String actions)
114+ throws IllegalArgumentException {
115+ super(name);
116+ if (!name.equals("control") && !name.equals("monitor")) {
117+ throw new IllegalArgumentException("name: " + name);
118+ }
119+ if (actions != null && actions.length() > 0) {
120+ throw new IllegalArgumentException("actions: " + actions);
121+ }
122+ }
123+}
java/pkg/java/lang/management/MemoryMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryMXBean.java+304−0
@@ -0,0 +1,304 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.openmbean.CompositeData;
29+
30+/**
31+ * The management interface for the memory system of
32+ * the Java virtual machine.
33+ *
34+ * <p> A Java virtual machine has a single instance of the implementation
35+ * class of this interface. This instance implementing this interface is
36+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
37+ * that can be obtained by calling
38+ * the {@link ManagementFactory#getMemoryMXBean} method or
39+ * from the {@link ManagementFactory#getPlatformMBeanServer
40+ * platform <tt>MBeanServer</tt>} method.
41+ *
42+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
43+ * the memory system within an MBeanServer is:
44+ * <blockquote>
45+ * {@link ManagementFactory#MEMORY_MXBEAN_NAME
46+ * <tt>java.lang:type=Memory</tt>}
47+ * </blockquote>
48+ *
49+ * It can be obtained by calling the
50+ * {@link PlatformManagedObject#getObjectName} method.
51+ *
52+ * <h4> Memory </h4>
53+ * The memory system of the Java virtual machine manages
54+ * the following kinds of memory:
55+ *
56+ * <h4> 1. Heap </h4>
57+ * The Java virtual machine has a <i>heap</i> that is the runtime
58+ * data area from which memory for all class instances and arrays
59+ * are allocated. It is created at the Java virtual machine start-up.
60+ * Heap memory for objects is reclaimed by an automatic memory management
61+ * system which is known as a <i>garbage collector</i>.
62+ *
63+ * <p>The heap may be of a fixed size or may be expanded and shrunk.
64+ * The memory for the heap does not need to be contiguous.
65+ *
66+ * <h4> 2. Non-Heap Memory</h4>
67+ * The Java virtual machine manages memory other than the heap
68+ * (referred as <i>non-heap memory</i>).
69+ *
70+ * <p> The Java virtual machine has a <i>method area</i> that is shared
71+ * among all threads.
72+ * The method area belongs to non-heap memory. It stores per-class structures
73+ * such as a runtime constant pool, field and method data, and the code for
74+ * methods and constructors. It is created at the Java virtual machine
75+ * start-up.
76+ *
77+ * <p> The method area is logically part of the heap but a Java virtual
78+ * machine implementation may choose not to either garbage collect
79+ * or compact it. Similar to the heap, the method area may be of a
80+ * fixed size or may be expanded and shrunk. The memory for the
81+ * method area does not need to be contiguous.
82+ *
83+ * <p>In addition to the method area, a Java virtual machine
84+ * implementation may require memory for internal processing or
85+ * optimization which also belongs to non-heap memory.
86+ * For example, the JIT compiler requires memory for storing the native
87+ * machine code translated from the Java virtual machine code for
88+ * high performance.
89+ *
90+ * <h4>Memory Pools and Memory Managers</h4>
91+ * {@link MemoryPoolMXBean Memory pools} and
92+ * {@link MemoryManagerMXBean memory managers} are the abstract entities
93+ * that monitor and manage the memory system
94+ * of the Java virtual machine.
95+ *
96+ * <p>A memory pool represents a memory area that the Java virtual machine
97+ * manages. The Java virtual machine has at least one memory pool
98+ * and it may create or remove memory pools during execution.
99+ * A memory pool can belong to either the heap or the non-heap memory.
100+ *
101+ * <p>A memory manager is responsible for managing one or more memory pools.
102+ * The garbage collector is one type of memory manager responsible
103+ * for reclaiming memory occupied by unreachable objects. A Java virtual
104+ * machine may have one or more memory managers. It may
105+ * add or remove memory managers during execution.
106+ * A memory pool can be managed by more than one memory manager.
107+ *
108+ * <h4>Memory Usage Monitoring</h4>
109+ *
110+ * Memory usage is a very important monitoring attribute for the memory system.
111+ * The memory usage, for example, could indicate:
112+ * <ul>
113+ * <li>the memory usage of an application,</li>
114+ * <li>the workload being imposed on the automatic memory management system,</li>
115+ * <li>potential memory leakage.</li>
116+ * </ul>
117+ *
118+ * <p>
119+ * The memory usage can be monitored in three ways:
120+ * <ul>
121+ * <li>Polling</li>
122+ * <li>Usage Threshold Notification</li>
123+ * <li>Collection Usage Threshold Notification</li>
124+ * </ul>
125+ *
126+ * Details are specified in the {@link MemoryPoolMXBean} interface.
127+ *
128+ * <p>The memory usage monitoring mechanism is intended for load-balancing
129+ * or workload distribution use. For example, an application would stop
130+ * receiving any new workload when its memory usage exceeds a
131+ * certain threshold. It is not intended for an application to detect
132+ * and recover from a low memory condition.
133+ *
134+ * <h4>Notifications</h4>
135+ *
136+ * <p>This <tt>MemoryMXBean</tt> is a
137+ * {@link javax.management.NotificationEmitter NotificationEmitter}
138+ * that emits two types of memory {@link javax.management.Notification
139+ * notifications} if any one of the memory pools
140+ * supports a <a href="MemoryPoolMXBean.html#UsageThreshold">usage threshold</a>
141+ * or a <a href="MemoryPoolMXBean.html#CollectionThreshold">collection usage
142+ * threshold</a> which can be determined by calling the
143+ * {@link MemoryPoolMXBean#isUsageThresholdSupported} and
144+ * {@link MemoryPoolMXBean#isCollectionUsageThresholdSupported} methods.
145+ * <ul>
146+ * <li>{@link MemoryNotificationInfo#MEMORY_THRESHOLD_EXCEEDED
147+ * usage threshold exceeded notification} - for notifying that
148+ * the memory usage of a memory pool is increased and has reached
149+ * or exceeded its
150+ * <a href="MemoryPoolMXBean.html#UsageThreshold"> usage threshold</a> value.
151+ * </li>
152+ * <li>{@link MemoryNotificationInfo#MEMORY_COLLECTION_THRESHOLD_EXCEEDED
153+ * collection usage threshold exceeded notification} - for notifying that
154+ * the memory usage of a memory pool is greater than or equal to its
155+ * <a href="MemoryPoolMXBean.html#CollectionThreshold">
156+ * collection usage threshold</a> after the Java virtual machine
157+ * has expended effort in recycling unused objects in that
158+ * memory pool.</li>
159+ * </ul>
160+ *
161+ * <p>
162+ * The notification emitted is a {@link javax.management.Notification}
163+ * instance whose {@link javax.management.Notification#setUserData
164+ * user data} is set to a {@link CompositeData CompositeData}
165+ * that represents a {@link MemoryNotificationInfo} object
166+ * containing information about the memory pool when the notification
167+ * was constructed. The <tt>CompositeData</tt> contains the attributes
168+ * as described in {@link MemoryNotificationInfo#from
169+ * MemoryNotificationInfo}.
170+ *
171+ * <hr>
172+ * <h4>NotificationEmitter</h4>
173+ * The <tt>MemoryMXBean</tt> object returned by
174+ * {@link ManagementFactory#getMemoryMXBean} implements
175+ * the {@link javax.management.NotificationEmitter NotificationEmitter}
176+ * interface that allows a listener to be registered within the
177+ * <tt>MemoryMXBean</tt> as a notification listener.
178+ *
179+ * Below is an example code that registers a <tt>MyListener</tt> to handle
180+ * notification emitted by the <tt>MemoryMXBean</tt>.
181+ *
182+ * <blockquote><pre>
183+ * class MyListener implements javax.management.NotificationListener {
184+ * public void handleNotification(Notification notif, Object handback) {
185+ * // handle notification
186+ * ....
187+ * }
188+ * }
189+ *
190+ * MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
191+ * NotificationEmitter emitter = (NotificationEmitter) mbean;
192+ * MyListener listener = new MyListener();
193+ * emitter.addNotificationListener(listener, null, null);
194+ * </pre></blockquote>
195+ *
196+ * @see ManagementFactory#getPlatformMXBeans(Class)
197+ * @see <a href="../../../javax/management/package-summary.html">
198+ * JMX Specification.</a>
199+ * @see <a href="package-summary.html#examples">
200+ * Ways to Access MXBeans</a>
201+ *
202+ * @author Mandy Chung
203+ * @since 1.5
204+ */
205+public interface MemoryMXBean extends PlatformManagedObject {
206+ /**
207+ * Returns the approximate number of objects for which
208+ * finalization is pending.
209+ *
210+ * @return the approximate number objects for which finalization
211+ * is pending.
212+ */
213+ public int getObjectPendingFinalizationCount();
214+
215+ /**
216+ * Returns the current memory usage of the heap that
217+ * is used for object allocation. The heap consists
218+ * of one or more memory pools. The <tt>used</tt>
219+ * and <tt>committed</tt> size of the returned memory
220+ * usage is the sum of those values of all heap memory pools
221+ * whereas the <tt>init</tt> and <tt>max</tt> size of the
222+ * returned memory usage represents the setting of the heap
223+ * memory which may not be the sum of those of all heap
224+ * memory pools.
225+ * <p>
226+ * The amount of used memory in the returned memory usage
227+ * is the amount of memory occupied by both live objects
228+ * and garbage objects that have not been collected, if any.
229+ *
230+ * <p>
231+ * <b>MBeanServer access</b>:<br>
232+ * The mapped type of <tt>MemoryUsage</tt> is
233+ * <tt>CompositeData</tt> with attributes as specified in
234+ * {@link MemoryUsage#from MemoryUsage}.
235+ *
236+ * @return a {@link MemoryUsage} object representing
237+ * the heap memory usage.
238+ */
239+ public MemoryUsage getHeapMemoryUsage();
240+
241+ /**
242+ * Returns the current memory usage of non-heap memory that
243+ * is used by the Java virtual machine.
244+ * The non-heap memory consists of one or more memory pools.
245+ * The <tt>used</tt> and <tt>committed</tt> size of the
246+ * returned memory usage is the sum of those values of
247+ * all non-heap memory pools whereas the <tt>init</tt>
248+ * and <tt>max</tt> size of the returned memory usage
249+ * represents the setting of the non-heap
250+ * memory which may not be the sum of those of all non-heap
251+ * memory pools.
252+ *
253+ * <p>
254+ * <b>MBeanServer access</b>:<br>
255+ * The mapped type of <tt>MemoryUsage</tt> is
256+ * <tt>CompositeData</tt> with attributes as specified in
257+ * {@link MemoryUsage#from MemoryUsage}.
258+ *
259+ * @return a {@link MemoryUsage} object representing
260+ * the non-heap memory usage.
261+ */
262+ public MemoryUsage getNonHeapMemoryUsage();
263+
264+ /**
265+ * Tests if verbose output for the memory system is enabled.
266+ *
267+ * @return <tt>true</tt> if verbose output for the memory
268+ * system is enabled; <tt>false</tt> otherwise.
269+ */
270+ public boolean isVerbose();
271+
272+ /**
273+ * Enables or disables verbose output for the memory
274+ * system. The verbose output information and the output stream
275+ * to which the verbose information is emitted are implementation
276+ * dependent. Typically, a Java virtual machine implementation
277+ * prints a message whenever it frees memory at garbage collection.
278+ *
279+ * <p>
280+ * Each invocation of this method enables or disables verbose
281+ * output globally.
282+ *
283+ * @param value <tt>true</tt> to enable verbose output;
284+ * <tt>false</tt> to disable.
285+ *
286+ * @exception java.lang.SecurityException if a security manager
287+ * exists and the caller does not have
288+ * ManagementPermission("control").
289+ */
290+ public void setVerbose(boolean value);
291+
292+ /**
293+ * Runs the garbage collector.
294+ * The call <code>gc()</code> is effectively equivalent to the
295+ * call:
296+ * <blockquote><pre>
297+ * System.gc()
298+ * </pre></blockquote>
299+ *
300+ * @see java.lang.System#gc()
301+ */
302+ public void gc();
303+
304+}
java/pkg/java/lang/management/MemoryManagerMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryManagerMXBean.java+88−0
@@ -0,0 +1,88 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for a memory manager.
30+ * A memory manager manages one or more memory pools of the
31+ * Java virtual machine.
32+ *
33+ * <p> A Java virtual machine has one or more memory managers.
34+ * An instance implementing this interface is
35+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
36+ * that can be obtained by calling
37+ * the {@link ManagementFactory#getMemoryManagerMXBeans} method or
38+ * from the {@link ManagementFactory#getPlatformMBeanServer
39+ * platform <tt>MBeanServer</tt>} method.
40+ *
41+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
42+ * a memory manager within an MBeanServer is:
43+ * <blockquote>
44+ * {@link ManagementFactory#MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
45+ * <tt>java.lang:type=MemoryManager</tt>}<tt>,name=</tt><i>manager's name</i>
46+ * </blockquote>
47+ *
48+ * It can be obtained by calling the
49+ * {@link PlatformManagedObject#getObjectName} method.
50+ *
51+ * @see ManagementFactory#getPlatformMXBeans(Class)
52+ * @see MemoryMXBean
53+ *
54+ * @see <a href="../../../javax/management/package-summary.html">
55+ * JMX Specification.</a>
56+ * @see <a href="package-summary.html#examples">
57+ * Ways to Access MXBeans</a>
58+ *
59+ * @author Mandy Chung
60+ * @since 1.5
61+ */
62+public interface MemoryManagerMXBean extends PlatformManagedObject {
63+ /**
64+ * Returns the name representing this memory manager.
65+ *
66+ * @return the name of this memory manager.
67+ */
68+ public String getName();
69+
70+ /**
71+ * Tests if this memory manager is valid in the Java virtual
72+ * machine. A memory manager becomes invalid once the Java virtual
73+ * machine removes it from the memory system.
74+ *
75+ * @return <tt>true</tt> if the memory manager is valid in the
76+ * Java virtual machine;
77+ * <tt>false</tt> otherwise.
78+ */
79+ public boolean isValid();
80+
81+ /**
82+ * Returns the name of memory pools that this memory manager manages.
83+ *
84+ * @return an array of <tt>String</tt> objects, each is
85+ * the name of a memory pool that this memory manager manages.
86+ */
87+ public String[] getMemoryPoolNames();
88+}
java/pkg/java/lang/management/MemoryNotificationInfo.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryNotificationInfo.java+256−0
@@ -0,0 +1,256 @@
1+/*
2+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+import javax.management.openmbean.CompositeData;
28+import sun.management.MemoryNotifInfoCompositeData;
29+
30+/**
31+ * The information about a memory notification.
32+ *
33+ * <p>
34+ * A memory notification is emitted by {@link MemoryMXBean}
35+ * when the Java virtual machine detects that the memory usage
36+ * of a memory pool is exceeding a threshold value.
37+ * The notification emitted will contain the memory notification
38+ * information about the detected condition:
39+ * <ul>
40+ * <li>The name of the memory pool.</li>
41+ * <li>The memory usage of the memory pool when the notification
42+ * was constructed.</li>
43+ * <li>The number of times that the memory usage has crossed
44+ * a threshold when the notification was constructed.
45+ * For usage threshold notifications, this count will be the
46+ * {@link MemoryPoolMXBean#getUsageThresholdCount usage threshold
47+ * count}. For collection threshold notifications,
48+ * this count will be the
49+ * {@link MemoryPoolMXBean#getCollectionUsageThresholdCount
50+ * collection usage threshold count}.
51+ * </li>
52+ * </ul>
53+ *
54+ * <p>
55+ * A {@link CompositeData CompositeData} representing
56+ * the <tt>MemoryNotificationInfo</tt> object
57+ * is stored in the
58+ * {@link javax.management.Notification#setUserData user data}
59+ * of a {@link javax.management.Notification notification}.
60+ * The {@link #from from} method is provided to convert from
61+ * a <tt>CompositeData</tt> to a <tt>MemoryNotificationInfo</tt>
62+ * object. For example:
63+ *
64+ * <blockquote><pre>
65+ * Notification notif;
66+ *
67+ * // receive the notification emitted by MemoryMXBean and set to notif
68+ * ...
69+ *
70+ * String notifType = notif.getType();
71+ * if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
72+ * notifType.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
73+ * // retrieve the memory notification information
74+ * CompositeData cd = (CompositeData) notif.getUserData();
75+ * MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
76+ * ....
77+ * }
78+ * </pre></blockquote>
79+ *
80+ * <p>
81+ * The types of notifications emitted by <tt>MemoryMXBean</tt> are:
82+ * <ul>
83+ * <li>A {@link #MEMORY_THRESHOLD_EXCEEDED
84+ * usage threshold exceeded notification}.
85+ * <br>This notification will be emitted when
86+ * the memory usage of a memory pool is increased and has reached
87+ * or exceeded its
88+ * <a href="MemoryPoolMXBean.html#UsageThreshold"> usage threshold</a> value.
89+ * Subsequent crossing of the usage threshold value does not cause
90+ * further notification until the memory usage has returned
91+ * to become less than the usage threshold value.
92+ * <p></li>
93+ * <li>A {@link #MEMORY_COLLECTION_THRESHOLD_EXCEEDED
94+ * collection usage threshold exceeded notification}.
95+ * <br>This notification will be emitted when
96+ * the memory usage of a memory pool is greater than or equal to its
97+ * <a href="MemoryPoolMXBean.html#CollectionThreshold">
98+ * collection usage threshold</a> after the Java virtual machine
99+ * has expended effort in recycling unused objects in that
100+ * memory pool.</li>
101+ * </ul>
102+ *
103+ * @author Mandy Chung
104+ * @since 1.5
105+ *
106+ */
107+public class MemoryNotificationInfo {
108+ private final String poolName;
109+ private final MemoryUsage usage;
110+ private final long count;
111+
112+ /**
113+ * Notification type denoting that
114+ * the memory usage of a memory pool has
115+ * reached or exceeded its
116+ * <a href="MemoryPoolMXBean.html#UsageThreshold"> usage threshold</a> value.
117+ * This notification is emitted by {@link MemoryMXBean}.
118+ * Subsequent crossing of the usage threshold value does not cause
119+ * further notification until the memory usage has returned
120+ * to become less than the usage threshold value.
121+ * The value of this notification type is
122+ * <tt>java.management.memory.threshold.exceeded</tt>.
123+ */
124+ public static final String MEMORY_THRESHOLD_EXCEEDED =
125+ "java.management.memory.threshold.exceeded";
126+
127+ /**
128+ * Notification type denoting that
129+ * the memory usage of a memory pool is greater than or equal to its
130+ * <a href="MemoryPoolMXBean.html#CollectionThreshold">
131+ * collection usage threshold</a> after the Java virtual machine
132+ * has expended effort in recycling unused objects in that
133+ * memory pool.
134+ * This notification is emitted by {@link MemoryMXBean}.
135+ * The value of this notification type is
136+ * <tt>java.management.memory.collection.threshold.exceeded</tt>.
137+ */
138+ public static final String MEMORY_COLLECTION_THRESHOLD_EXCEEDED =
139+ "java.management.memory.collection.threshold.exceeded";
140+
141+ /**
142+ * Constructs a <tt>MemoryNotificationInfo</tt> object.
143+ *
144+ * @param poolName The name of the memory pool which triggers this notification.
145+ * @param usage Memory usage of the memory pool.
146+ * @param count The threshold crossing count.
147+ */
148+ public MemoryNotificationInfo(String poolName,
149+ MemoryUsage usage,
150+ long count) {
151+ if (poolName == null) {
152+ throw new NullPointerException("Null poolName");
153+ }
154+ if (usage == null) {
155+ throw new NullPointerException("Null usage");
156+ }
157+
158+ this.poolName = poolName;
159+ this.usage = usage;
160+ this.count = count;
161+ }
162+
163+ MemoryNotificationInfo(CompositeData cd) {
164+ MemoryNotifInfoCompositeData.validateCompositeData(cd);
165+
166+ this.poolName = MemoryNotifInfoCompositeData.getPoolName(cd);
167+ this.usage = MemoryNotifInfoCompositeData.getUsage(cd);
168+ this.count = MemoryNotifInfoCompositeData.getCount(cd);
169+ }
170+
171+ /**
172+ * Returns the name of the memory pool that triggers this notification.
173+ * The memory pool usage has crossed a threshold.
174+ *
175+ * @return the name of the memory pool that triggers this notification.
176+ */
177+ public String getPoolName() {
178+ return poolName;
179+ }
180+
181+ /**
182+ * Returns the memory usage of the memory pool
183+ * when this notification was constructed.
184+ *
185+ * @return the memory usage of the memory pool
186+ * when this notification was constructed.
187+ */
188+ public MemoryUsage getUsage() {
189+ return usage;
190+ }
191+
192+ /**
193+ * Returns the number of times that the memory usage has crossed
194+ * a threshold when the notification was constructed.
195+ * For usage threshold notifications, this count will be the
196+ * {@link MemoryPoolMXBean#getUsageThresholdCount threshold
197+ * count}. For collection threshold notifications,
198+ * this count will be the
199+ * {@link MemoryPoolMXBean#getCollectionUsageThresholdCount
200+ * collection usage threshold count}.
201+ *
202+ * @return the number of times that the memory usage has crossed
203+ * a threshold when the notification was constructed.
204+ */
205+ public long getCount() {
206+ return count;
207+ }
208+
209+ /**
210+ * Returns a <tt>MemoryNotificationInfo</tt> object represented by the
211+ * given <tt>CompositeData</tt>.
212+ * The given <tt>CompositeData</tt> must contain
213+ * the following attributes:
214+ * <blockquote>
215+ * <table border>
216+ * <tr>
217+ * <th align=left>Attribute Name</th>
218+ * <th align=left>Type</th>
219+ * </tr>
220+ * <tr>
221+ * <td>poolName</td>
222+ * <td><tt>java.lang.String</tt></td>
223+ * </tr>
224+ * <tr>
225+ * <td>usage</td>
226+ * <td><tt>javax.management.openmbean.CompositeData</tt></td>
227+ * </tr>
228+ * <tr>
229+ * <td>count</td>
230+ * <td><tt>java.lang.Long</tt></td>
231+ * </tr>
232+ * </table>
233+ * </blockquote>
234+ *
235+ * @param cd <tt>CompositeData</tt> representing a
236+ * <tt>MemoryNotificationInfo</tt>
237+ *
238+ * @throws IllegalArgumentException if <tt>cd</tt> does not
239+ * represent a <tt>MemoryNotificationInfo</tt> object.
240+ *
241+ * @return a <tt>MemoryNotificationInfo</tt> object represented
242+ * by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
243+ * <tt>null</tt> otherwise.
244+ */
245+ public static MemoryNotificationInfo from(CompositeData cd) {
246+ if (cd == null) {
247+ return null;
248+ }
249+
250+ if (cd instanceof MemoryNotifInfoCompositeData) {
251+ return ((MemoryNotifInfoCompositeData) cd).getMemoryNotifInfo();
252+ } else {
253+ return new MemoryNotificationInfo(cd);
254+ }
255+ }
256+}
java/pkg/java/lang/management/MemoryPoolMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryPoolMXBean.java+643−0
@@ -0,0 +1,643 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for a memory pool. A memory pool
30+ * represents the memory resource managed by the Java virtual machine
31+ * and is managed by one or more {@link MemoryManagerMXBean memory managers}.
32+ *
33+ * <p> A Java virtual machine has one or more instances of the
34+ * implementation class of this interface. An instance
35+ * implementing this interface is
36+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
37+ * that can be obtained by calling
38+ * the {@link ManagementFactory#getMemoryPoolMXBeans} method or
39+ * from the {@link ManagementFactory#getPlatformMBeanServer
40+ * platform <tt>MBeanServer</tt>} method.
41+ *
42+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
43+ * a memory pool within an <tt>MBeanServer</tt> is:
44+ * <blockquote>
45+ * {@link ManagementFactory#MEMORY_POOL_MXBEAN_DOMAIN_TYPE
46+ * <tt>java.lang:type=MemoryPool</tt>}<tt>,name=</tt><i>pool's name</i>
47+ * </blockquote>
48+ *
49+ * It can be obtained by calling the
50+ * {@link PlatformManagedObject#getObjectName} method.
51+ *
52+ * <h4>Memory Type</h4>
53+ * <p>The Java virtual machine has a heap for object allocation and also
54+ * maintains non-heap memory for the method area and the Java virtual
55+ * machine execution. The Java virtual machine can have one or more
56+ * memory pools. Each memory pool represents a memory area
57+ * of one of the following types:
58+ * <ul>
59+ * <li>{@link MemoryType#HEAP heap}</li>
60+ * <li>{@link MemoryType#NON_HEAP non-heap}</li>
61+ * </ul>
62+ *
63+ * <h4>Memory Usage Monitoring</h4>
64+ *
65+ * A memory pool has the following attributes:
66+ * <ul>
67+ * <li><a href="#Usage">Memory usage</a></li>
68+ * <li><a href="#PeakUsage">Peak memory usage</a></li>
69+ * <li><a href="#UsageThreshold">Usage Threshold</a></li>
70+ * <li><a href="#CollectionThreshold">Collection Usage Threshold</a>
71+ * (only supported by some <em>garbage-collected</em> memory pools)</li>
72+ * </ul>
73+ *
74+ * <h4><a name="Usage">1. Memory Usage</a></h4>
75+ *
76+ * The {@link #getUsage} method provides an estimate
77+ * of the current usage of a memory pool.
78+ * For a garbage-collected memory pool, the amount of used memory
79+ * includes the memory occupied by all objects in the pool
80+ * including both <em>reachable</em> and <em>unreachable</em> objects.
81+ *
82+ * <p>In general, this method is a lightweight operation for getting
83+ * an approximate memory usage. For some memory pools, for example,
84+ * when objects are not packed contiguously, this method may be
85+ * an expensive operation that requires some computation to determine
86+ * the current memory usage. An implementation should document when
87+ * this is the case.
88+ *
89+ * <h4><a name="PeakUsage">2. Peak Memory Usage</a></h4>
90+ *
91+ * The Java virtual machine maintains the peak memory usage of a memory
92+ * pool since the virtual machine was started or the peak was reset.
93+ * The peak memory usage is returned by the {@link #getPeakUsage} method
94+ * and reset by calling the {@link #resetPeakUsage} method.
95+ *
96+ * <h4><a name="UsageThreshold">3. Usage Threshold</a></h4>
97+ *
98+ * Each memory pool has a manageable attribute
99+ * called the <i>usage threshold</i> which has a default value supplied
100+ * by the Java virtual machine. The default value is platform-dependent.
101+ * The usage threshold can be set via the
102+ * {@link #setUsageThreshold setUsageThreshold} method.
103+ * If the threshold is set to a positive value, the usage threshold crossing
104+ * checking is enabled in this memory pool.
105+ * If the usage threshold is set to zero, usage
106+ * threshold crossing checking on this memory pool is disabled.
107+ * The {@link MemoryPoolMXBean#isUsageThresholdSupported} method can
108+ * be used to determine if this functionality is supported.
109+ * <p>
110+ * A Java virtual machine performs usage threshold crossing checking on a
111+ * memory pool basis at its best appropriate time, typically,
112+ * at garbage collection time.
113+ * Each memory pool maintains a {@link #getUsageThresholdCount
114+ * usage threshold count} that will get incremented
115+ * every time when the Java virtual machine
116+ * detects that the memory pool usage is crossing the threshold.
117+ * <p>
118+ * This manageable usage threshold attribute is designed for monitoring the
119+ * increasing trend of memory usage with low overhead.
120+ * Usage threshold may not be appropriate for some memory pools.
121+ * For example, a generational garbage collector, a common garbage collection
122+ * algorithm used in many Java virtual machine implementations,
123+ * manages two or more generations segregating objects by age.
124+ * Most of the objects are allocated in
125+ * the <em>youngest generation</em> (say a nursery memory pool).
126+ * The nursery memory pool is designed to be filled up and
127+ * collecting the nursery memory pool will free most of its memory space
128+ * since it is expected to contain mostly short-lived objects
129+ * and mostly are unreachable at garbage collection time.
130+ * In this case, it is more appropriate for the nursery memory pool
131+ * not to support a usage threshold. In addition,
132+ * if the cost of an object allocation
133+ * in one memory pool is very low (for example, just atomic pointer exchange),
134+ * the Java virtual machine would probably not support the usage threshold
135+ * for that memory pool since the overhead in comparing the usage with
136+ * the threshold is higher than the cost of object allocation.
137+ *
138+ * <p>
139+ * The memory usage of the system can be monitored using
140+ * <a href="#Polling">polling</a> or
141+ * <a href="#ThresholdNotification">threshold notification</a> mechanisms.
142+ *
143+ * <ol type="a">
144+ * <li><a name="Polling"><b>Polling</b></a>
145+ * <p>
146+ * An application can continuously monitor its memory usage
147+ * by calling either the {@link #getUsage} method for all
148+ * memory pools or the {@link #isUsageThresholdExceeded} method
149+ * for those memory pools that support a usage threshold.
150+ * Below is example code that has a thread delicated for
151+ * task distribution and processing. At every interval,
152+ * it will determine if it should receive and process new tasks based
153+ * on its memory usage. If the memory usage exceeds its usage threshold,
154+ * it will redistribute all outstanding tasks to other VMs and
155+ * stop receiving new tasks until the memory usage returns
156+ * below its usage threshold.
157+ *
158+ * <pre>
159+ * // Assume the usage threshold is supported for this pool.
160+ * // Set the threshold to myThreshold above which no new tasks
161+ * // should be taken.
162+ * pool.setUsageThreshold(myThreshold);
163+ * ....
164+ *
165+ * boolean lowMemory = false;
166+ * while (true) {
167+ * if (pool.isUsageThresholdExceeded()) {
168+ * // potential low memory, so redistribute tasks to other VMs
169+ * lowMemory = true;
170+ * redistributeTasks();
171+ * // stop receiving new tasks
172+ * stopReceivingTasks();
173+ * } else {
174+ * if (lowMemory) {
175+ * // resume receiving tasks
176+ * lowMemory = false;
177+ * resumeReceivingTasks();
178+ * }
179+ * // processing outstanding task
180+ * ...
181+ * }
182+ * // sleep for sometime
183+ * try {
184+ * Thread.sleep(sometime);
185+ * } catch (InterruptedException e) {
186+ * ...
187+ * }
188+ * }
189+ * </pre>
190+ *
191+ * <hr>
192+ * The above example does not differentiate the case where
193+ * the memory usage has temporarily dropped below the usage threshold
194+ * from the case where the memory usage remains above the threshould
195+ * between two iterations. The usage threshold count returned by
196+ * the {@link #getUsageThresholdCount} method
197+ * can be used to determine
198+ * if the memory usage has returned below the threshold
199+ * between two polls.
200+ * <p>
201+ * Below shows another example that takes some action if a
202+ * memory pool is under low memory and ignores the memory usage
203+ * changes during the action processing time.
204+ *
205+ * <pre>
206+ * // Assume the usage threshold is supported for this pool.
207+ * // Set the threshold to myThreshold which determines if
208+ * // the application will take some action under low memory condition.
209+ * pool.setUsageThreshold(myThreshold);
210+ *
211+ * int prevCrossingCount = 0;
212+ * while (true) {
213+ * // A busy loop to detect when the memory usage
214+ * // has exceeded the threshold.
215+ * while (!pool.isUsageThresholdExceeded() ||
216+ * pool.getUsageThresholdCount() == prevCrossingCount) {
217+ * try {
218+ * Thread.sleep(sometime)
219+ * } catch (InterruptException e) {
220+ * ....
221+ * }
222+ * }
223+ *
224+ * // Do some processing such as check for memory usage
225+ * // and issue a warning
226+ * ....
227+ *
228+ * // Gets the current threshold count. The busy loop will then
229+ * // ignore any crossing of threshold happens during the processing.
230+ * prevCrossingCount = pool.getUsageThresholdCount();
231+ * }
232+ * </pre><hr>
233+ * </li>
234+ * <li><a name="ThresholdNotification"><b>Usage Threshold Notifications</b></a>
235+ * <p>
236+ * Usage threshold notification will be emitted by {@link MemoryMXBean}.
237+ * When the Java virtual machine detects that the memory usage of
238+ * a memory pool has reached or exceeded the usage threshold
239+ * the virtual machine will trigger the <tt>MemoryMXBean</tt> to emit an
240+ * {@link MemoryNotificationInfo#MEMORY_THRESHOLD_EXCEEDED
241+ * usage threshold exceeded notification}.
242+ * Another usage threshold exceeded notification will not be
243+ * generated until the usage has fallen below the threshold and
244+ * then exceeded it again.
245+ * <p>
246+ * Below is an example code implementing the same logic as the
247+ * first example above but using the usage threshold notification
248+ * mechanism to detect low memory conditions instead of polling.
249+ * In this example code, upon receiving notification, the notification
250+ * listener notifies another thread to perform the actual action
251+ * such as to redistribute outstanding tasks, stop receiving tasks,
252+ * or resume receiving tasks.
253+ * The <tt>handleNotification</tt> method should be designed to
254+ * do a very minimal amount of work and return without delay to avoid
255+ * causing delay in delivering subsequent notifications. Time-consuming
256+ * actions should be performed by a separate thread.
257+ * The notification listener may be invoked by multiple threads
258+ * concurrently; so the tasks performed by the listener
259+ * should be properly synchronized.
260+ *
261+ * <pre>
262+ * class MyListener implements javax.management.NotificationListener {
263+ * public void handleNotification(Notification notification, Object handback) {
264+ * String notifType = notification.getType();
265+ * if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
266+ * // potential low memory, notify another thread
267+ * // to redistribute outstanding tasks to other VMs
268+ * // and stop receiving new tasks.
269+ * lowMemory = true;
270+ * notifyAnotherThread(lowMemory);
271+ * }
272+ * }
273+ * }
274+ *
275+ * // Register MyListener with MemoryMXBean
276+ * MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
277+ * NotificationEmitter emitter = (NotificationEmitter) mbean;
278+ * MyListener listener = new MyListener();
279+ * emitter.addNotificationListener(listener, null, null);
280+ *
281+ * // Assume this pool supports a usage threshold.
282+ * // Set the threshold to myThreshold above which no new tasks
283+ * // should be taken.
284+ * pool.setUsageThreshold(myThreshold);
285+ *
286+ * // Usage threshold detection is enabled and notification will be
287+ * // handled by MyListener. Continue for other processing.
288+ * ....
289+ *
290+ * </pre>
291+ * <hr>
292+ * <p>
293+ * There is no guarantee about when the <tt>MemoryMXBean</tt> will emit
294+ * a threshold notification and when the notification will be delivered.
295+ * When a notification listener is invoked, the memory usage of
296+ * the memory pool may have crossed the usage threshold more
297+ * than once.
298+ * The {@link MemoryNotificationInfo#getCount} method returns the number
299+ * of times that the memory usage has crossed the usage threshold
300+ * at the point in time when the notification was constructed.
301+ * It can be compared with the current usage threshold count returned
302+ * by the {@link #getUsageThresholdCount} method to determine if
303+ * such situation has occurred.
304+ * </li>
305+ * </ol>
306+ *
307+ * <h4><a name="CollectionThreshold">4. Collection Usage Threshold</a></h4>
308+ *
309+ * Collection usage threshold is a manageable attribute only applicable
310+ * to some garbage-collected memory pools.
311+ * After a Java virtual machine has expended effort in reclaiming memory
312+ * space by recycling unused objects in a memory pool at garbage collection
313+ * time, some number of bytes in the memory pools that are garbaged
314+ * collected will still be in use. The collection usage threshold
315+ * allows a value to be set for this number of bytes such
316+ * that if the threshold is exceeded,
317+ * a {@link MemoryNotificationInfo#MEMORY_THRESHOLD_EXCEEDED
318+ * collection usage threshold exceeded notification}
319+ * will be emitted by the {@link MemoryMXBean}.
320+ * In addition, the {@link #getCollectionUsageThresholdCount
321+ * collection usage threshold count} will then be incremented.
322+ *
323+ * <p>
324+ * The {@link MemoryPoolMXBean#isCollectionUsageThresholdSupported} method can
325+ * be used to determine if this functionality is supported.
326+ *
327+ * <p>
328+ * A Java virtual machine performs collection usage threshold checking
329+ * on a memory pool basis. This checking is enabled if the collection
330+ * usage threshold is set to a positive value.
331+ * If the collection usage threshold is set to zero, this checking
332+ * is disabled on this memory pool. Default value is zero.
333+ * The Java virtual machine performs the collection usage threshold
334+ * checking at garbage collection time.
335+ *
336+ * <p>
337+ * Some garbage-collected memory pools may
338+ * choose not to support the collection usage threshold. For example,
339+ * a memory pool is only managed by a continuous concurrent garbage
340+ * collector. Objects can be allocated in this memory pool by some thread
341+ * while the unused objects are reclaimed by the concurrent garbage
342+ * collector simultaneously. Unless there is a well-defined
343+ * garbage collection time which is the best appropriate time
344+ * to check the memory usage, the collection usage threshold should not
345+ * be supported.
346+ *
347+ * <p>
348+ * The collection usage threshold is designed for monitoring the memory usage
349+ * after the Java virtual machine has expended effort in reclaiming
350+ * memory space. The collection usage could also be monitored
351+ * by the polling and threshold notification mechanism
352+ * described above for the <a href="#UsageThreshold">usage threshold</a>
353+ * in a similar fashion.
354+ *
355+ * @see ManagementFactory#getPlatformMXBeans(Class)
356+ * @see <a href="../../../javax/management/package-summary.html">
357+ * JMX Specification.</a>
358+ * @see <a href="package-summary.html#examples">
359+ * Ways to Access MXBeans</a>
360+ *
361+ * @author Mandy Chung
362+ * @since 1.5
363+ */
364+public interface MemoryPoolMXBean extends PlatformManagedObject {
365+ /**
366+ * Returns the name representing this memory pool.
367+ *
368+ * @return the name of this memory pool.
369+ */
370+ public String getName();
371+
372+ /**
373+ * Returns the type of this memory pool.
374+ *
375+ * <p>
376+ * <b>MBeanServer access</b>:<br>
377+ * The mapped type of <tt>MemoryType</tt> is <tt>String</tt>
378+ * and the value is the name of the <tt>MemoryType</tt>.
379+ *
380+ * @return the type of this memory pool.
381+ */
382+ public MemoryType getType();
383+
384+ /**
385+ * Returns an estimate of the memory usage of this memory pool.
386+ * This method returns <tt>null</tt>
387+ * if this memory pool is not valid (i.e. no longer exists).
388+ *
389+ * <p>
390+ * This method requests the Java virtual machine to make
391+ * a best-effort estimate of the current memory usage of this
392+ * memory pool. For some memory pools, this method may be an
393+ * expensive operation that requires some computation to determine
394+ * the estimate. An implementation should document when
395+ * this is the case.
396+ *
397+ * <p>This method is designed for use in monitoring system
398+ * memory usage and detecting low memory condition.
399+ *
400+ * <p>
401+ * <b>MBeanServer access</b>:<br>
402+ * The mapped type of <tt>MemoryUsage</tt> is
403+ * <tt>CompositeData</tt> with attributes as specified in
404+ * {@link MemoryUsage#from MemoryUsage}.
405+ *
406+ * @return a {@link MemoryUsage} object; or <tt>null</tt> if
407+ * this pool not valid.
408+ */
409+ public MemoryUsage getUsage();
410+
411+ /**
412+ * Returns the peak memory usage of this memory pool since the
413+ * Java virtual machine was started or since the peak was reset.
414+ * This method returns <tt>null</tt>
415+ * if this memory pool is not valid (i.e. no longer exists).
416+ *
417+ * <p>
418+ * <b>MBeanServer access</b>:<br>
419+ * The mapped type of <tt>MemoryUsage</tt> is
420+ * <tt>CompositeData</tt> with attributes as specified in
421+ * {@link MemoryUsage#from MemoryUsage}.
422+ *
423+ * @return a {@link MemoryUsage} object representing the peak
424+ * memory usage; or <tt>null</tt> if this pool is not valid.
425+ *
426+ */
427+ public MemoryUsage getPeakUsage();
428+
429+ /**
430+ * Resets the peak memory usage statistic of this memory pool
431+ * to the current memory usage.
432+ *
433+ * @throws java.lang.SecurityException if a security manager
434+ * exists and the caller does not have
435+ * ManagementPermission("control").
436+ */
437+ public void resetPeakUsage();
438+
439+ /**
440+ * Tests if this memory pool is valid in the Java virtual
441+ * machine. A memory pool becomes invalid once the Java virtual
442+ * machine removes it from the memory system.
443+ *
444+ * @return <tt>true</tt> if the memory pool is valid in the running
445+ * Java virtual machine;
446+ * <tt>false</tt> otherwise.
447+ */
448+ public boolean isValid();
449+
450+ /**
451+ * Returns the name of memory managers that manages this memory pool.
452+ * Each memory pool will be managed by at least one memory manager.
453+ *
454+ * @return an array of <tt>String</tt> objects, each is the name of
455+ * a memory manager managing this memory pool.
456+ */
457+ public String[] getMemoryManagerNames();
458+
459+ /**
460+ * Returns the usage threshold value of this memory pool in bytes.
461+ * Each memory pool has a platform-dependent default threshold value.
462+ * The current usage threshold can be changed via the
463+ * {@link #setUsageThreshold setUsageThreshold} method.
464+ *
465+ * @return the usage threshold value of this memory pool in bytes.
466+ *
467+ * @throws UnsupportedOperationException if this memory pool
468+ * does not support a usage threshold.
469+ *
470+ * @see #isUsageThresholdSupported
471+ */
472+ public long getUsageThreshold();
473+
474+ /**
475+ * Sets the threshold of this memory pool to the given <tt>threshold</tt>
476+ * value if this memory pool supports the usage threshold.
477+ * The usage threshold crossing checking is enabled in this memory pool
478+ * if the threshold is set to a positive value.
479+ * The usage threshold crossing checking is disabled
480+ * if it is set to zero.
481+ *
482+ * @param threshold the new threshold value in bytes. Must be non-negative.
483+ *
484+ * @throws IllegalArgumentException if <tt>threshold</tt> is negative
485+ * or greater than the maximum amount of memory for
486+ * this memory pool if defined.
487+ *
488+ * @throws UnsupportedOperationException if this memory pool
489+ * does not support a usage threshold.
490+ *
491+ * @throws java.lang.SecurityException if a security manager
492+ * exists and the caller does not have
493+ * ManagementPermission("control").
494+ *
495+ * @see #isUsageThresholdSupported
496+ * @see <a href="#UsageThreshold">Usage threshold</a>
497+ */
498+ public void setUsageThreshold(long threshold);
499+
500+ /**
501+ * Tests if the memory usage of this memory pool
502+ * reaches or exceeds its usage threshold value.
503+ *
504+ * @return <tt>true</tt> if the memory usage of
505+ * this memory pool reaches or exceeds the threshold value;
506+ * <tt>false</tt> otherwise.
507+ *
508+ * @throws UnsupportedOperationException if this memory pool
509+ * does not support a usage threshold.
510+ */
511+ public boolean isUsageThresholdExceeded();
512+
513+ /**
514+ * Returns the number of times that the memory usage has crossed
515+ * the usage threshold.
516+ *
517+ * @return the number of times that the memory usage
518+ * has crossed its usage threshold value.
519+ *
520+ * @throws UnsupportedOperationException if this memory pool
521+ * does not support a usage threshold.
522+ */
523+ public long getUsageThresholdCount();
524+
525+ /**
526+ * Tests if this memory pool supports usage threshold.
527+ *
528+ * @return <tt>true</tt> if this memory pool supports usage threshold;
529+ * <tt>false</tt> otherwise.
530+ */
531+ public boolean isUsageThresholdSupported();
532+
533+ /**
534+ * Returns the collection usage threshold value of this memory pool
535+ * in bytes. The default value is zero. The collection usage
536+ * threshold can be changed via the
537+ * {@link #setCollectionUsageThreshold setCollectionUsageThreshold} method.
538+ *
539+ * @return the collection usage threshold of this memory pool in bytes.
540+ *
541+ * @throws UnsupportedOperationException if this memory pool
542+ * does not support a collection usage threshold.
543+ *
544+ * @see #isCollectionUsageThresholdSupported
545+ */
546+ public long getCollectionUsageThreshold();
547+
548+ /**
549+ * Sets the collection usage threshold of this memory pool to
550+ * the given <tt>threshold</tt> value.
551+ * When this threshold is set to positive, the Java virtual machine
552+ * will check the memory usage at its best appropriate time after it has
553+ * expended effort in recycling unused objects in this memory pool.
554+ * <p>
555+ * The collection usage threshold crossing checking is enabled
556+ * in this memory pool if the threshold is set to a positive value.
557+ * The collection usage threshold crossing checking is disabled
558+ * if it is set to zero.
559+ *
560+ * @param threshold the new collection usage threshold value in bytes.
561+ * Must be non-negative.
562+ *
563+ * @throws IllegalArgumentException if <tt>threshold</tt> is negative
564+ * or greater than the maximum amount of memory for
565+ * this memory pool if defined.
566+ *
567+ * @throws UnsupportedOperationException if this memory pool
568+ * does not support a collection usage threshold.
569+ *
570+ * @throws java.lang.SecurityException if a security manager
571+ * exists and the caller does not have
572+ * ManagementPermission("control").
573+ *
574+ * @see #isCollectionUsageThresholdSupported
575+ * @see <a href="#CollectionThreshold">Collection usage threshold</a>
576+ */
577+ public void setCollectionUsageThreshold(long threshold);
578+
579+ /**
580+ * Tests if the memory usage of this memory pool after
581+ * the most recent collection on which the Java virtual
582+ * machine has expended effort has reached or
583+ * exceeded its collection usage threshold.
584+ * This method does not request the Java virtual
585+ * machine to perform any garbage collection other than its normal
586+ * automatic memory management.
587+ *
588+ * @return <tt>true</tt> if the memory usage of this memory pool
589+ * reaches or exceeds the collection usage threshold value
590+ * in the most recent collection;
591+ * <tt>false</tt> otherwise.
592+ *
593+ * @throws UnsupportedOperationException if this memory pool
594+ * does not support a usage threshold.
595+ */
596+ public boolean isCollectionUsageThresholdExceeded();
597+
598+ /**
599+ * Returns the number of times that the Java virtual machine
600+ * has detected that the memory usage has reached or
601+ * exceeded the collection usage threshold.
602+ *
603+ * @return the number of times that the memory
604+ * usage has reached or exceeded the collection usage threshold.
605+ *
606+ * @throws UnsupportedOperationException if this memory pool
607+ * does not support a collection usage threshold.
608+ *
609+ * @see #isCollectionUsageThresholdSupported
610+ */
611+ public long getCollectionUsageThresholdCount();
612+
613+ /**
614+ * Returns the memory usage after the Java virtual machine
615+ * most recently expended effort in recycling unused objects
616+ * in this memory pool.
617+ * This method does not request the Java virtual
618+ * machine to perform any garbage collection other than its normal
619+ * automatic memory management.
620+ * This method returns <tt>null</tt> if the Java virtual
621+ * machine does not support this method.
622+ *
623+ * <p>
624+ * <b>MBeanServer access</b>:<br>
625+ * The mapped type of <tt>MemoryUsage</tt> is
626+ * <tt>CompositeData</tt> with attributes as specified in
627+ * {@link MemoryUsage#from MemoryUsage}.
628+ *
629+ * @return a {@link MemoryUsage} representing the memory usage of
630+ * this memory pool after the Java virtual machine most recently
631+ * expended effort in recycling unused objects;
632+ * <tt>null</tt> if this method is not supported.
633+ */
634+ public MemoryUsage getCollectionUsage();
635+
636+ /**
637+ * Tests if this memory pool supports a collection usage threshold.
638+ *
639+ * @return <tt>true</tt> if this memory pool supports the
640+ * collection usage threshold; <tt>false</tt> otherwise.
641+ */
642+ public boolean isCollectionUsageThresholdSupported();
643+}
java/pkg/java/lang/management/MemoryType.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryType.java+73−0
@@ -0,0 +1,73 @@
1+/*
2+ * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * Types of {@link MemoryPoolMXBean memory pools}.
30+ *
31+ * @author Mandy Chung
32+ * @since 1.5
33+ */
34+public enum MemoryType {
35+
36+ /**
37+ * Heap memory type.
38+ * <p>
39+ * The Java virtual machine has a <i>heap</i>
40+ * that is the runtime data area from which
41+ * memory for all class instances and arrays are allocated.
42+ */
43+ HEAP("Heap memory"),
44+
45+ /**
46+ * Non-heap memory type.
47+ * <p>
48+ * The Java virtual machine manages memory other than the heap
49+ * (referred as <i>non-heap memory</i>). The non-heap memory includes
50+ * the <i>method area</i> and memory required for the internal
51+ * processing or optimization for the Java virtual machine.
52+ * It stores per-class structures such as a runtime
53+ * constant pool, field and method data, and the code for
54+ * methods and constructors.
55+ */
56+ NON_HEAP("Non-heap memory");
57+
58+ private final String description;
59+
60+ private MemoryType(String s) {
61+ this.description = s;
62+ }
63+
64+ /**
65+ * Returns the string representation of this <tt>MemoryType</tt>.
66+ * @return the string representation of this <tt>MemoryType</tt>.
67+ */
68+ public String toString() {
69+ return description;
70+ }
71+
72+ private static final long serialVersionUID = 6992337162326171013L;
73+}
java/pkg/java/lang/management/MemoryUsage.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MemoryUsage.java+303−0
@@ -0,0 +1,303 @@
1+/*
2+ * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.openmbean.CompositeData;
29+import sun.management.MemoryUsageCompositeData;
30+
31+/**
32+ * A <tt>MemoryUsage</tt> object represents a snapshot of memory usage.
33+ * Instances of the <tt>MemoryUsage</tt> class are usually constructed
34+ * by methods that are used to obtain memory usage
35+ * information about individual memory pool of the Java virtual machine or
36+ * the heap or non-heap memory of the Java virtual machine as a whole.
37+ *
38+ * <p> A <tt>MemoryUsage</tt> object contains four values:
39+ * <ul>
40+ * <table>
41+ * <tr>
42+ * <td valign=top> <tt>init</tt> </td>
43+ * <td valign=top> represents the initial amount of memory (in bytes) that
44+ * the Java virtual machine requests from the operating system
45+ * for memory management during startup. The Java virtual machine
46+ * may request additional memory from the operating system and
47+ * may also release memory to the system over time.
48+ * The value of <tt>init</tt> may be undefined.
49+ * </td>
50+ * </tr>
51+ * <tr>
52+ * <td valign=top> <tt>used</tt> </td>
53+ * <td valign=top> represents the amount of memory currently used (in bytes).
54+ * </td>
55+ * </tr>
56+ * <tr>
57+ * <td valign=top> <tt>committed</tt> </td>
58+ * <td valign=top> represents the amount of memory (in bytes) that is
59+ * guaranteed to be available for use by the Java virtual machine.
60+ * The amount of committed memory may change over time (increase
61+ * or decrease). The Java virtual machine may release memory to
62+ * the system and <tt>committed</tt> could be less than <tt>init</tt>.
63+ * <tt>committed</tt> will always be greater than
64+ * or equal to <tt>used</tt>.
65+ * </td>
66+ * </tr>
67+ * <tr>
68+ * <td valign=top> <tt>max</tt> </td>
69+ * <td valign=top> represents the maximum amount of memory (in bytes)
70+ * that can be used for memory management. Its value may be undefined.
71+ * The maximum amount of memory may change over time if defined.
72+ * The amount of used and committed memory will always be less than
73+ * or equal to <tt>max</tt> if <tt>max</tt> is defined.
74+ * A memory allocation may fail if it attempts to increase the
75+ * used memory such that <tt>used &gt committed</tt> even
76+ * if <tt>used &lt= max</tt> would still be true (for example,
77+ * when the system is low on virtual memory).
78+ * </td>
79+ * </tr>
80+ * </table>
81+ * </ul>
82+ *
83+ * Below is a picture showing an example of a memory pool:
84+ * <p>
85+ * <pre>
86+ * +----------------------------------------------+
87+ * +//////////////// | +
88+ * +//////////////// | +
89+ * +----------------------------------------------+
90+ *
91+ * |--------|
92+ * init
93+ * |---------------|
94+ * used
95+ * |---------------------------|
96+ * committed
97+ * |----------------------------------------------|
98+ * max
99+ * </pre>
100+ *
101+ * <h4>MXBean Mapping</h4>
102+ * <tt>MemoryUsage</tt> is mapped to a {@link CompositeData CompositeData}
103+ * with attributes as specified in the {@link #from from} method.
104+ *
105+ * @author Mandy Chung
106+ * @since 1.5
107+ */
108+public class MemoryUsage {
109+ private final long init;
110+ private final long used;
111+ private final long committed;
112+ private final long max;
113+
114+ /**
115+ * Constructs a <tt>MemoryUsage</tt> object.
116+ *
117+ * @param init the initial amount of memory in bytes that
118+ * the Java virtual machine allocates;
119+ * or <tt>-1</tt> if undefined.
120+ * @param used the amount of used memory in bytes.
121+ * @param committed the amount of committed memory in bytes.
122+ * @param max the maximum amount of memory in bytes that
123+ * can be used; or <tt>-1</tt> if undefined.
124+ *
125+ * @throws IllegalArgumentException if
126+ * <ul>
127+ * <li> the value of <tt>init</tt> or <tt>max</tt> is negative
128+ * but not <tt>-1</tt>; or</li>
129+ * <li> the value of <tt>used</tt> or <tt>committed</tt> is negative;
130+ * or</li>
131+ * <li> <tt>used</tt> is greater than the value of <tt>committed</tt>;
132+ * or</li>
133+ * <li> <tt>committed</tt> is greater than the value of <tt>max</tt>
134+ * <tt>max</tt> if defined.</li>
135+ * </ul>
136+ */
137+ public MemoryUsage(long init,
138+ long used,
139+ long committed,
140+ long max) {
141+ if (init < -1) {
142+ throw new IllegalArgumentException( "init parameter = " +
143+ init + " is negative but not -1.");
144+ }
145+ if (max < -1) {
146+ throw new IllegalArgumentException( "max parameter = " +
147+ max + " is negative but not -1.");
148+ }
149+ if (used < 0) {
150+ throw new IllegalArgumentException( "used parameter = " +
151+ used + " is negative.");
152+ }
153+ if (committed < 0) {
154+ throw new IllegalArgumentException( "committed parameter = " +
155+ committed + " is negative.");
156+ }
157+ if (used > committed) {
158+ throw new IllegalArgumentException( "used = " + used +
159+ " should be <= committed = " + committed);
160+ }
161+ if (max >= 0 && committed > max) {
162+ throw new IllegalArgumentException( "committed = " + committed +
163+ " should be < max = " + max);
164+ }
165+
166+ this.init = init;
167+ this.used = used;
168+ this.committed = committed;
169+ this.max = max;
170+ }
171+
172+ /**
173+ * Constructs a <tt>MemoryUsage</tt> object from a
174+ * {@link CompositeData CompositeData}.
175+ */
176+ private MemoryUsage(CompositeData cd) {
177+ // validate the input composite data
178+ MemoryUsageCompositeData.validateCompositeData(cd);
179+
180+ this.init = MemoryUsageCompositeData.getInit(cd);
181+ this.used = MemoryUsageCompositeData.getUsed(cd);
182+ this.committed = MemoryUsageCompositeData.getCommitted(cd);
183+ this.max = MemoryUsageCompositeData.getMax(cd);
184+ }
185+
186+ /**
187+ * Returns the amount of memory in bytes that the Java virtual machine
188+ * initially requests from the operating system for memory management.
189+ * This method returns <tt>-1</tt> if the initial memory size is undefined.
190+ *
191+ * @return the initial size of memory in bytes;
192+ * <tt>-1</tt> if undefined.
193+ */
194+ public long getInit() {
195+ return init;
196+ }
197+
198+ /**
199+ * Returns the amount of used memory in bytes.
200+ *
201+ * @return the amount of used memory in bytes.
202+ *
203+ */
204+ public long getUsed() {
205+ return used;
206+ };
207+
208+ /**
209+ * Returns the amount of memory in bytes that is committed for
210+ * the Java virtual machine to use. This amount of memory is
211+ * guaranteed for the Java virtual machine to use.
212+ *
213+ * @return the amount of committed memory in bytes.
214+ *
215+ */
216+ public long getCommitted() {
217+ return committed;
218+ };
219+
220+ /**
221+ * Returns the maximum amount of memory in bytes that can be
222+ * used for memory management. This method returns <tt>-1</tt>
223+ * if the maximum memory size is undefined.
224+ *
225+ * <p> This amount of memory is not guaranteed to be available
226+ * for memory management if it is greater than the amount of
227+ * committed memory. The Java virtual machine may fail to allocate
228+ * memory even if the amount of used memory does not exceed this
229+ * maximum size.
230+ *
231+ * @return the maximum amount of memory in bytes;
232+ * <tt>-1</tt> if undefined.
233+ */
234+ public long getMax() {
235+ return max;
236+ };
237+
238+ /**
239+ * Returns a descriptive representation of this memory usage.
240+ */
241+ public String toString() {
242+ StringBuffer buf = new StringBuffer();
243+ buf.append("init = " + init + "(" + (init >> 10) + "K) ");
244+ buf.append("used = " + used + "(" + (used >> 10) + "K) ");
245+ buf.append("committed = " + committed + "(" +
246+ (committed >> 10) + "K) " );
247+ buf.append("max = " + max + "(" + (max >> 10) + "K)");
248+ return buf.toString();
249+ }
250+
251+ /**
252+ * Returns a <tt>MemoryUsage</tt> object represented by the
253+ * given <tt>CompositeData</tt>. The given <tt>CompositeData</tt>
254+ * must contain the following attributes:
255+ * <p>
256+ * <blockquote>
257+ * <table border>
258+ * <tr>
259+ * <th align=left>Attribute Name</th>
260+ * <th align=left>Type</th>
261+ * </tr>
262+ * <tr>
263+ * <td>init</td>
264+ * <td><tt>java.lang.Long</tt></td>
265+ * </tr>
266+ * <tr>
267+ * <td>used</td>
268+ * <td><tt>java.lang.Long</tt></td>
269+ * </tr>
270+ * <tr>
271+ * <td>committed</td>
272+ * <td><tt>java.lang.Long</tt></td>
273+ * </tr>
274+ * <tr>
275+ * <td>max</td>
276+ * <td><tt>java.lang.Long</tt></td>
277+ * </tr>
278+ * </table>
279+ * </blockquote>
280+ *
281+ * @param cd <tt>CompositeData</tt> representing a <tt>MemoryUsage</tt>
282+ *
283+ * @throws IllegalArgumentException if <tt>cd</tt> does not
284+ * represent a <tt>MemoryUsage</tt> with the attributes described
285+ * above.
286+ *
287+ * @return a <tt>MemoryUsage</tt> object represented by <tt>cd</tt>
288+ * if <tt>cd</tt> is not <tt>null</tt>;
289+ * <tt>null</tt> otherwise.
290+ */
291+ public static MemoryUsage from(CompositeData cd) {
292+ if (cd == null) {
293+ return null;
294+ }
295+
296+ if (cd instanceof MemoryUsageCompositeData) {
297+ return ((MemoryUsageCompositeData) cd).getMemoryUsage();
298+ } else {
299+ return new MemoryUsage(cd);
300+ }
301+
302+ }
303+}
java/pkg/java/lang/management/MonitorInfo.class+0−0

Binary file not shown.

java/pkg/java/lang/management/MonitorInfo.java+159−0
@@ -0,0 +1,159 @@
1+/*
2+ * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.openmbean.CompositeData;
29+import sun.management.MonitorInfoCompositeData;
30+
31+/**
32+ * Information about an object monitor lock. An object monitor is locked
33+ * when entering a synchronization block or method on that object.
34+ *
35+ * <h4>MXBean Mapping</h4>
36+ * <tt>MonitorInfo</tt> is mapped to a {@link CompositeData CompositeData}
37+ * with attributes as specified in
38+ * the {@link #from from} method.
39+ *
40+ * @author Mandy Chung
41+ * @since 1.6
42+ */
43+public class MonitorInfo extends LockInfo {
44+
45+ private int stackDepth;
46+ private StackTraceElement stackFrame;
47+
48+ /**
49+ * Construct a <tt>MonitorInfo</tt> object.
50+ *
51+ * @param className the fully qualified name of the class of the lock object.
52+ * @param identityHashCode the {@link System#identityHashCode
53+ * identity hash code} of the lock object.
54+ * @param stackDepth the depth in the stack trace where the object monitor
55+ * was locked.
56+ * @param stackFrame the stack frame that locked the object monitor.
57+ * @throws IllegalArgumentException if
58+ * <tt>stackDepth</tt> &ge; 0 but <tt>stackFrame</tt> is <tt>null</tt>,
59+ * or <tt>stackDepth</tt> &lt; 0 but <tt>stackFrame</tt> is not
60+ * <tt>null</tt>.
61+ */
62+ public MonitorInfo(String className,
63+ int identityHashCode,
64+ int stackDepth,
65+ StackTraceElement stackFrame) {
66+ super(className, identityHashCode);
67+ if (stackDepth >= 0 && stackFrame == null) {
68+ throw new IllegalArgumentException("Parameter stackDepth is " +
69+ stackDepth + " but stackFrame is null");
70+ }
71+ if (stackDepth < 0 && stackFrame != null) {
72+ throw new IllegalArgumentException("Parameter stackDepth is " +
73+ stackDepth + " but stackFrame is not null");
74+ }
75+ this.stackDepth = stackDepth;
76+ this.stackFrame = stackFrame;
77+ }
78+
79+ /**
80+ * Returns the depth in the stack trace where the object monitor
81+ * was locked. The depth is the index to the <tt>StackTraceElement</tt>
82+ * array returned in the {@link ThreadInfo#getStackTrace} method.
83+ *
84+ * @return the depth in the stack trace where the object monitor
85+ * was locked, or a negative number if not available.
86+ */
87+ public int getLockedStackDepth() {
88+ return stackDepth;
89+ }
90+
91+ /**
92+ * Returns the stack frame that locked the object monitor.
93+ *
94+ * @return <tt>StackTraceElement</tt> that locked the object monitor,
95+ * or <tt>null</tt> if not available.
96+ */
97+ public StackTraceElement getLockedStackFrame() {
98+ return stackFrame;
99+ }
100+
101+ /**
102+ * Returns a <tt>MonitorInfo</tt> object represented by the
103+ * given <tt>CompositeData</tt>.
104+ * The given <tt>CompositeData</tt> must contain the following attributes
105+ * as well as the attributes specified in the
106+ * <a href="LockInfo.html#MappedType">
107+ * mapped type</a> for the {@link LockInfo} class:
108+ * <blockquote>
109+ * <table border>
110+ * <tr>
111+ * <th align=left>Attribute Name</th>
112+ * <th align=left>Type</th>
113+ * </tr>
114+ * <tr>
115+ * <td>lockedStackFrame</td>
116+ * <td><tt>CompositeData as specified in the
117+ * <a href="ThreadInfo.html#StackTrace">stackTrace</a>
118+ * attribute defined in the {@link ThreadInfo#from
119+ * ThreadInfo.from} method.
120+ * </tt></td>
121+ * </tr>
122+ * <tr>
123+ * <td>lockedStackDepth</td>
124+ * <td><tt>java.lang.Integer</tt></td>
125+ * </tr>
126+ * </table>
127+ * </blockquote>
128+ *
129+ * @param cd <tt>CompositeData</tt> representing a <tt>MonitorInfo</tt>
130+ *
131+ * @throws IllegalArgumentException if <tt>cd</tt> does not
132+ * represent a <tt>MonitorInfo</tt> with the attributes described
133+ * above.
134+
135+ * @return a <tt>MonitorInfo</tt> object represented
136+ * by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
137+ * <tt>null</tt> otherwise.
138+ */
139+ public static MonitorInfo from(CompositeData cd) {
140+ if (cd == null) {
141+ return null;
142+ }
143+
144+ if (cd instanceof MonitorInfoCompositeData) {
145+ return ((MonitorInfoCompositeData) cd).getMonitorInfo();
146+ } else {
147+ MonitorInfoCompositeData.validateCompositeData(cd);
148+ String className = MonitorInfoCompositeData.getClassName(cd);
149+ int identityHashCode = MonitorInfoCompositeData.getIdentityHashCode(cd);
150+ int stackDepth = MonitorInfoCompositeData.getLockedStackDepth(cd);
151+ StackTraceElement stackFrame = MonitorInfoCompositeData.getLockedStackFrame(cd);
152+ return new MonitorInfo(className,
153+ identityHashCode,
154+ stackDepth,
155+ stackFrame);
156+ }
157+ }
158+
159+}
java/pkg/java/lang/management/OperatingSystemMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/OperatingSystemMXBean.java+142−0
@@ -0,0 +1,142 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the operating system on which
30+ * the Java virtual machine is running.
31+ *
32+ * <p> A Java virtual machine has a single instance of the implementation
33+ * class of this interface. This instance implementing this interface is
34+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
35+ * that can be obtained by calling
36+ * the {@link ManagementFactory#getOperatingSystemMXBean} method or
37+ * from the {@link ManagementFactory#getPlatformMBeanServer
38+ * platform <tt>MBeanServer</tt>} method.
39+ *
40+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
41+ * the operating system within an MBeanServer is:
42+ * <blockquote>
43+ * {@link ManagementFactory#OPERATING_SYSTEM_MXBEAN_NAME
44+ * <tt>java.lang:type=OperatingSystem</tt>}
45+ * </blockquote>
46+ *
47+ * It can be obtained by calling the
48+ * {@link PlatformManagedObject#getObjectName} method.
49+ *
50+ * <p> This interface defines several convenient methods for accessing
51+ * system properties about the operating system on which the Java
52+ * virtual machine is running.
53+ *
54+ * @see ManagementFactory#getPlatformMXBeans(Class)
55+ * @see <a href="../../../javax/management/package-summary.html">
56+ * JMX Specification.</a>
57+ * @see <a href="package-summary.html#examples">
58+ * Ways to Access MXBeans</a>
59+ *
60+ * @author Mandy Chung
61+ * @since 1.5
62+ */
63+public interface OperatingSystemMXBean extends PlatformManagedObject {
64+ /**
65+ * Returns the operating system name.
66+ * This method is equivalent to <tt>System.getProperty("os.name")</tt>.
67+ *
68+ * @return the operating system name.
69+ *
70+ * @throws java.lang.SecurityException
71+ * if a security manager exists and its
72+ * <code>checkPropertiesAccess</code> method doesn't allow access
73+ * to this system property.
74+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
75+ * @see java.lang.System#getProperty
76+ */
77+ public String getName();
78+
79+ /**
80+ * Returns the operating system architecture.
81+ * This method is equivalent to <tt>System.getProperty("os.arch")</tt>.
82+ *
83+ * @return the operating system architecture.
84+ *
85+ * @throws java.lang.SecurityException
86+ * if a security manager exists and its
87+ * <code>checkPropertiesAccess</code> method doesn't allow access
88+ * to this system property.
89+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
90+ * @see java.lang.System#getProperty
91+ */
92+ public String getArch();
93+
94+ /**
95+ * Returns the operating system version.
96+ * This method is equivalent to <tt>System.getProperty("os.version")</tt>.
97+ *
98+ * @return the operating system version.
99+ *
100+ * @throws java.lang.SecurityException
101+ * if a security manager exists and its
102+ * <code>checkPropertiesAccess</code> method doesn't allow access
103+ * to this system property.
104+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
105+ * @see java.lang.System#getProperty
106+ */
107+ public String getVersion();
108+
109+ /**
110+ * Returns the number of processors available to the Java virtual machine.
111+ * This method is equivalent to the {@link Runtime#availableProcessors()}
112+ * method.
113+ * <p> This value may change during a particular invocation of
114+ * the virtual machine.
115+ *
116+ * @return the number of processors available to the virtual
117+ * machine; never smaller than one.
118+ */
119+ public int getAvailableProcessors();
120+
121+ /**
122+ * Returns the system load average for the last minute.
123+ * The system load average is the sum of the number of runnable entities
124+ * queued to the {@linkplain #getAvailableProcessors available processors}
125+ * and the number of runnable entities running on the available processors
126+ * averaged over a period of time.
127+ * The way in which the load average is calculated is operating system
128+ * specific but is typically a damped time-dependent average.
129+ * <p>
130+ * If the load average is not available, a negative value is returned.
131+ * <p>
132+ * This method is designed to provide a hint about the system load
133+ * and may be queried frequently.
134+ * The load average may be unavailable on some platform where it is
135+ * expensive to implement this method.
136+ *
137+ * @return the system load average; or a negative value if not available.
138+ *
139+ * @since 1.6
140+ */
141+ public double getSystemLoadAverage();
142+}
java/pkg/java/lang/management/PlatformComponent$1.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$10.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$11.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$12.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$13.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$14.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$15.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$2.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$3.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$4.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$5.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$6.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$7.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$8.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$9.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent$MXBeanFetcher.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformComponent.java+467−0
@@ -0,0 +1,467 @@
1+/*
2+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import java.util.ArrayList;
29+import java.util.Collections;
30+import java.util.List;
31+import java.util.HashSet;
32+import java.util.HashMap;
33+import java.util.Map;
34+import java.util.Set;
35+import javax.management.MBeanServerConnection;
36+import javax.management.ObjectName;
37+
38+import com.sun.management.HotSpotDiagnosticMXBean;
39+import com.sun.management.UnixOperatingSystemMXBean;
40+
41+import sun.management.ManagementFactoryHelper;
42+import sun.management.Util;
43+
44+/**
45+ * This enum class defines the list of platform components
46+ * that provides monitoring and management support.
47+ * Each enum represents one MXBean interface. A MXBean
48+ * instance could implement one or more MXBean interfaces.
49+ *
50+ * For example, com.sun.management.GarbageCollectorMXBean
51+ * extends java.lang.management.GarbageCollectorMXBean
52+ * and there is one set of garbage collection MXBean instances,
53+ * each of which implements both c.s.m. and j.l.m. interfaces.
54+ * There are two separate enums GARBAGE_COLLECTOR
55+ * and SUN_GARBAGE_COLLECTOR so that ManagementFactory.getPlatformMXBeans(Class)
56+ * will return the list of MXBeans of the specified type.
57+ *
58+ * To add a new MXBean interface for the Java platform,
59+ * add a new enum constant and implement the MXBeanFetcher.
60+ */
61+enum PlatformComponent {
62+
63+ /**
64+ * Class loading system of the Java virtual machine.
65+ */
66+ CLASS_LOADING(
67+ "java.lang.management.ClassLoadingMXBean",
68+ "java.lang", "ClassLoading", defaultKeyProperties(),
69+ true, // singleton
70+ new MXBeanFetcher<ClassLoadingMXBean>() {
71+ public List<ClassLoadingMXBean> getMXBeans() {
72+ return Collections.singletonList(ManagementFactoryHelper.getClassLoadingMXBean());
73+ }
74+ }),
75+
76+ /**
77+ * Compilation system of the Java virtual machine.
78+ */
79+ COMPILATION(
80+ "java.lang.management.CompilationMXBean",
81+ "java.lang", "Compilation", defaultKeyProperties(),
82+ true, // singleton
83+ new MXBeanFetcher<CompilationMXBean>() {
84+ public List<CompilationMXBean> getMXBeans() {
85+ CompilationMXBean m = ManagementFactoryHelper.getCompilationMXBean();
86+ if (m == null) {
87+ return Collections.emptyList();
88+ } else {
89+ return Collections.singletonList(m);
90+ }
91+ }
92+ }),
93+
94+ /**
95+ * Memory system of the Java virtual machine.
96+ */
97+ MEMORY(
98+ "java.lang.management.MemoryMXBean",
99+ "java.lang", "Memory", defaultKeyProperties(),
100+ true, // singleton
101+ new MXBeanFetcher<MemoryMXBean>() {
102+ public List<MemoryMXBean> getMXBeans() {
103+ return Collections.singletonList(ManagementFactoryHelper.getMemoryMXBean());
104+ }
105+ }),
106+
107+ /**
108+ * Garbage Collector in the Java virtual machine.
109+ */
110+ GARBAGE_COLLECTOR(
111+ "java.lang.management.GarbageCollectorMXBean",
112+ "java.lang", "GarbageCollector", keyProperties("name"),
113+ false, // zero or more instances
114+ new MXBeanFetcher<GarbageCollectorMXBean>() {
115+ public List<GarbageCollectorMXBean> getMXBeans() {
116+ return ManagementFactoryHelper.
117+ getGarbageCollectorMXBeans();
118+ }
119+ }),
120+
121+ /**
122+ * Memory manager in the Java virtual machine.
123+ */
124+ MEMORY_MANAGER(
125+ "java.lang.management.MemoryManagerMXBean",
126+ "java.lang", "MemoryManager", keyProperties("name"),
127+ false, // zero or more instances
128+ new MXBeanFetcher<MemoryManagerMXBean>() {
129+ public List<MemoryManagerMXBean> getMXBeans() {
130+ return ManagementFactoryHelper.getMemoryManagerMXBeans();
131+ }
132+ },
133+ GARBAGE_COLLECTOR),
134+
135+ /**
136+ * Memory pool in the Java virtual machine.
137+ */
138+ MEMORY_POOL(
139+ "java.lang.management.MemoryPoolMXBean",
140+ "java.lang", "MemoryPool", keyProperties("name"),
141+ false, // zero or more instances
142+ new MXBeanFetcher<MemoryPoolMXBean>() {
143+ public List<MemoryPoolMXBean> getMXBeans() {
144+ return ManagementFactoryHelper.getMemoryPoolMXBeans();
145+ }
146+ }),
147+
148+ /**
149+ * Operating system on which the Java virtual machine is running
150+ */
151+ OPERATING_SYSTEM(
152+ "java.lang.management.OperatingSystemMXBean",
153+ "java.lang", "OperatingSystem", defaultKeyProperties(),
154+ true, // singleton
155+ new MXBeanFetcher<OperatingSystemMXBean>() {
156+ public List<OperatingSystemMXBean> getMXBeans() {
157+ return Collections.singletonList(ManagementFactoryHelper.getOperatingSystemMXBean());
158+ }
159+ }),
160+
161+ /**
162+ * Runtime system of the Java virtual machine.
163+ */
164+ RUNTIME(
165+ "java.lang.management.RuntimeMXBean",
166+ "java.lang", "Runtime", defaultKeyProperties(),
167+ true, // singleton
168+ new MXBeanFetcher<RuntimeMXBean>() {
169+ public List<RuntimeMXBean> getMXBeans() {
170+ return Collections.singletonList(ManagementFactoryHelper.getRuntimeMXBean());
171+ }
172+ }),
173+
174+ /**
175+ * Threading system of the Java virtual machine.
176+ */
177+ THREADING(
178+ "java.lang.management.ThreadMXBean",
179+ "java.lang", "Threading", defaultKeyProperties(),
180+ true, // singleton
181+ new MXBeanFetcher<ThreadMXBean>() {
182+ public List<ThreadMXBean> getMXBeans() {
183+ return Collections.singletonList(ManagementFactoryHelper.getThreadMXBean());
184+ }
185+ }),
186+
187+
188+ /**
189+ * Logging facility.
190+ */
191+ LOGGING(
192+ "java.lang.management.PlatformLoggingMXBean",
193+ "java.util.logging", "Logging", defaultKeyProperties(),
194+ true, // singleton
195+ new MXBeanFetcher<PlatformLoggingMXBean>() {
196+ public List<PlatformLoggingMXBean> getMXBeans() {
197+ PlatformLoggingMXBean m = ManagementFactoryHelper.getPlatformLoggingMXBean();
198+ if (m == null) {
199+ return Collections.emptyList();
200+ } else {
201+ return Collections.singletonList(m);
202+ }
203+ }
204+ }),
205+
206+ /**
207+ * Buffer pools.
208+ */
209+ BUFFER_POOL(
210+ "java.lang.management.BufferPoolMXBean",
211+ "java.nio", "BufferPool", keyProperties("name"),
212+ false, // zero or more instances
213+ new MXBeanFetcher<BufferPoolMXBean>() {
214+ public List<BufferPoolMXBean> getMXBeans() {
215+ return ManagementFactoryHelper.getBufferPoolMXBeans();
216+ }
217+ }),
218+
219+
220+ // Sun Platform Extension
221+
222+ /**
223+ * Sun extension garbage collector that performs collections in cycles.
224+ */
225+ SUN_GARBAGE_COLLECTOR(
226+ "com.sun.management.GarbageCollectorMXBean",
227+ "java.lang", "GarbageCollector", keyProperties("name"),
228+ false, // zero or more instances
229+ new MXBeanFetcher<com.sun.management.GarbageCollectorMXBean>() {
230+ public List<com.sun.management.GarbageCollectorMXBean> getMXBeans() {
231+ return getGcMXBeanList(com.sun.management.GarbageCollectorMXBean.class);
232+ }
233+ }),
234+
235+ /**
236+ * Sun extension operating system on which the Java virtual machine
237+ * is running.
238+ */
239+ SUN_OPERATING_SYSTEM(
240+ "com.sun.management.OperatingSystemMXBean",
241+ "java.lang", "OperatingSystem", defaultKeyProperties(),
242+ true, // singleton
243+ new MXBeanFetcher<com.sun.management.OperatingSystemMXBean>() {
244+ public List<com.sun.management.OperatingSystemMXBean> getMXBeans() {
245+ return getOSMXBeanList(com.sun.management.OperatingSystemMXBean.class);
246+ }
247+ }),
248+
249+ /**
250+ * Unix operating system.
251+ */
252+ SUN_UNIX_OPERATING_SYSTEM(
253+ "com.sun.management.UnixOperatingSystemMXBean",
254+ "java.lang", "OperatingSystem", defaultKeyProperties(),
255+ true, // singleton
256+ new MXBeanFetcher<UnixOperatingSystemMXBean>() {
257+ public List<UnixOperatingSystemMXBean> getMXBeans() {
258+ return getOSMXBeanList(com.sun.management.UnixOperatingSystemMXBean.class);
259+ }
260+ }),
261+
262+ /**
263+ * Diagnostic support for the HotSpot Virtual Machine.
264+ */
265+ HOTSPOT_DIAGNOSTIC(
266+ "com.sun.management.HotSpotDiagnosticMXBean",
267+ "com.sun.management", "HotSpotDiagnostic", defaultKeyProperties(),
268+ true, // singleton
269+ new MXBeanFetcher<HotSpotDiagnosticMXBean>() {
270+ public List<HotSpotDiagnosticMXBean> getMXBeans() {
271+ return Collections.singletonList(ManagementFactoryHelper.getDiagnosticMXBean());
272+ }
273+ });
274+
275+
276+ /**
277+ * A task that returns the MXBeans for a component.
278+ */
279+ interface MXBeanFetcher<T extends PlatformManagedObject> {
280+ public List<T> getMXBeans();
281+ }
282+
283+ /*
284+ * Returns a list of the GC MXBeans of the given type.
285+ */
286+ private static <T extends GarbageCollectorMXBean>
287+ List<T> getGcMXBeanList(Class<T> gcMXBeanIntf) {
288+ List<GarbageCollectorMXBean> list =
289+ ManagementFactoryHelper.getGarbageCollectorMXBeans();
290+ List<T> result = new ArrayList<>(list.size());
291+ for (GarbageCollectorMXBean m : list) {
292+ if (gcMXBeanIntf.isInstance(m)) {
293+ result.add(gcMXBeanIntf.cast(m));
294+ }
295+ }
296+ return result;
297+ }
298+
299+ /*
300+ * Returns the OS mxbean instance of the given type.
301+ */
302+ private static <T extends OperatingSystemMXBean>
303+ List<T> getOSMXBeanList(Class<T> osMXBeanIntf) {
304+ OperatingSystemMXBean m =
305+ ManagementFactoryHelper.getOperatingSystemMXBean();
306+ if (osMXBeanIntf.isInstance(m)) {
307+ return Collections.singletonList(osMXBeanIntf.cast(m));
308+ } else {
309+ return Collections.emptyList();
310+ }
311+ }
312+
313+ private final String mxbeanInterfaceName;
314+ private final String domain;
315+ private final String type;
316+ private final Set<String> keyProperties;
317+ private final MXBeanFetcher fetcher;
318+ private final PlatformComponent[] subComponents;
319+ private final boolean singleton;
320+
321+ private PlatformComponent(String intfName,
322+ String domain, String type,
323+ Set<String> keyProperties,
324+ boolean singleton,
325+ MXBeanFetcher fetcher,
326+ PlatformComponent... subComponents) {
327+ this.mxbeanInterfaceName = intfName;
328+ this.domain = domain;
329+ this.type = type;
330+ this.keyProperties = keyProperties;
331+ this.singleton = singleton;
332+ this.fetcher = fetcher;
333+ this.subComponents = subComponents;
334+ }
335+
336+ private static Set<String> defaultKeyProps;
337+ private static Set<String> defaultKeyProperties() {
338+ if (defaultKeyProps == null) {
339+ defaultKeyProps = Collections.singleton("type");
340+ }
341+ return defaultKeyProps;
342+ }
343+
344+ private static Set<String> keyProperties(String... keyNames) {
345+ Set<String> set = new HashSet<>();
346+ set.add("type");
347+ for (String s : keyNames) {
348+ set.add(s);
349+ }
350+ return set;
351+ }
352+
353+ boolean isSingleton() {
354+ return singleton;
355+ }
356+
357+ String getMXBeanInterfaceName() {
358+ return mxbeanInterfaceName;
359+ }
360+
361+ @SuppressWarnings("unchecked")
362+ Class<? extends PlatformManagedObject> getMXBeanInterface() {
363+ try {
364+ // Lazy loading the MXBean interface only when it is needed
365+ return (Class<? extends PlatformManagedObject>)
366+ Class.forName(mxbeanInterfaceName, false, null);
367+ } catch (ClassNotFoundException x) {
368+ throw new AssertionError(x);
369+ }
370+ }
371+
372+ @SuppressWarnings("unchecked")
373+ <T extends PlatformManagedObject>
374+ List<T> getMXBeans(Class<T> mxbeanInterface)
375+ {
376+ return fetcher.getMXBeans();
377+ }
378+
379+ <T extends PlatformManagedObject> T getSingletonMXBean(Class<T> mxbeanInterface)
380+ {
381+ if (!singleton)
382+ throw new IllegalArgumentException(mxbeanInterfaceName +
383+ " can have zero or more than one instances");
384+
385+ List<T> list = fetcher.getMXBeans();
386+ assert list.size() == 1;
387+ return list.isEmpty() ? null : list.get(0);
388+ }
389+
390+ <T extends PlatformManagedObject>
391+ T getSingletonMXBean(MBeanServerConnection mbs, Class<T> mxbeanInterface)
392+ throws java.io.IOException
393+ {
394+ if (!singleton)
395+ throw new IllegalArgumentException(mxbeanInterfaceName +
396+ " can have zero or more than one instances");
397+
398+ // ObjectName of a singleton MXBean contains only domain and type
399+ assert keyProperties.size() == 1;
400+ String on = domain + ":type=" + type;
401+ return ManagementFactory.newPlatformMXBeanProxy(mbs,
402+ on,
403+ mxbeanInterface);
404+ }
405+
406+ <T extends PlatformManagedObject>
407+ List<T> getMXBeans(MBeanServerConnection mbs, Class<T> mxbeanInterface)
408+ throws java.io.IOException
409+ {
410+ List<T> result = new ArrayList<>();
411+ for (ObjectName on : getObjectNames(mbs)) {
412+ result.add(ManagementFactory.
413+ newPlatformMXBeanProxy(mbs,
414+ on.getCanonicalName(),
415+ mxbeanInterface)
416+ );
417+ }
418+ return result;
419+ }
420+
421+ private Set<ObjectName> getObjectNames(MBeanServerConnection mbs)
422+ throws java.io.IOException
423+ {
424+ String domainAndType = domain + ":type=" + type;
425+ if (keyProperties.size() > 1) {
426+ // if there are more than 1 key properties (i.e. other than "type")
427+ domainAndType += ",*";
428+ }
429+ ObjectName on = Util.newObjectName(domainAndType);
430+ Set<ObjectName> set = mbs.queryNames(on, null);
431+ for (PlatformComponent pc : subComponents) {
432+ set.addAll(pc.getObjectNames(mbs));
433+ }
434+ return set;
435+ }
436+
437+ // a map from MXBean interface name to PlatformComponent
438+ private static Map<String, PlatformComponent> enumMap;
439+ private static synchronized void ensureInitialized() {
440+ if (enumMap == null) {
441+ enumMap = new HashMap<>();
442+ for (PlatformComponent pc: PlatformComponent.values()) {
443+ // Use String as the key rather than Class<?> to avoid
444+ // causing unnecessary class loading of management interface
445+ enumMap.put(pc.getMXBeanInterfaceName(), pc);
446+ }
447+ }
448+ }
449+
450+ static boolean isPlatformMXBean(String cn) {
451+ ensureInitialized();
452+ return enumMap.containsKey(cn);
453+ }
454+
455+ static <T extends PlatformManagedObject>
456+ PlatformComponent getPlatformComponent(Class<T> mxbeanInterface)
457+ {
458+ ensureInitialized();
459+ String cn = mxbeanInterface.getName();
460+ PlatformComponent pc = enumMap.get(cn);
461+ if (pc != null && pc.getMXBeanInterface() == mxbeanInterface)
462+ return pc;
463+ return null;
464+ }
465+
466+ private static final long serialVersionUID = 6992337162326171013L;
467+}
java/pkg/java/lang/management/PlatformLoggingMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformLoggingMXBean.java+138−0
@@ -0,0 +1,138 @@
1+/*
2+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the {@linkplain java.util.logging logging} facility.
30+ *
31+ * <p>There is a single global instance of the <tt>PlatformLoggingMXBean</tt>.
32+ * The {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
33+ * ManagementFactory.getPlatformMXBean} method can be used to obtain
34+ * the {@code PlatformLoggingMXBean} object as follows:
35+ * <pre>
36+ * PlatformLoggingMXBean logging = ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class);
37+ * </pre>
38+ * The {@code PlatformLoggingMXBean} object is also registered with the
39+ * platform {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
40+ * MBeanServer}.
41+ * The {@link javax.management.ObjectName ObjectName} for uniquely
42+ * identifying the {@code PlatformLoggingMXBean} within an MBeanServer is:
43+ * <pre>
44+ * {@link java.util.logging.LogManager#LOGGING_MXBEAN_NAME java.util.logging:type=Logging}
45+ * </pre>
46+ *
47+ * <p>The instance registered in the platform <tt>MBeanServer</tt> with
48+ * this {@code ObjectName} implements all attributes defined by
49+ * {@link java.util.logging.LoggingMXBean}.
50+ *
51+ * @since 1.7
52+ */
53+public interface PlatformLoggingMXBean extends PlatformManagedObject {
54+
55+ /**
56+ * Returns the list of the currently registered
57+ * {@linkplain java.util.logging.Logger logger} names. This method
58+ * calls {@link java.util.logging.LogManager#getLoggerNames} and
59+ * returns a list of the logger names.
60+ *
61+ * @return A list of {@code String} each of which is a
62+ * currently registered {@code Logger} name.
63+ */
64+ java.util.List<String> getLoggerNames();
65+
66+ /**
67+ * Gets the name of the log {@linkplain java.util.logging.Logger#getLevel
68+ * level} associated with the specified logger.
69+ * If the specified logger does not exist, {@code null}
70+ * is returned.
71+ * This method first finds the logger of the given name and
72+ * then returns the name of the log level by calling:
73+ * <blockquote>
74+ * {@link java.util.logging.Logger#getLevel
75+ * Logger.getLevel()}.{@link java.util.logging.Level#getName getName()};
76+ * </blockquote>
77+ *
78+ * <p>
79+ * If the {@code Level} of the specified logger is {@code null},
80+ * which means that this logger's effective level is inherited
81+ * from its parent, an empty string will be returned.
82+ *
83+ * @param loggerName The name of the {@code Logger} to be retrieved.
84+ *
85+ * @return The name of the log level of the specified logger; or
86+ * an empty string if the log level of the specified logger
87+ * is {@code null}. If the specified logger does not
88+ * exist, {@code null} is returned.
89+ *
90+ * @see java.util.logging.Logger#getLevel
91+ */
92+ String getLoggerLevel(String loggerName);
93+
94+ /**
95+ * Sets the specified logger to the specified new
96+ * {@linkplain java.util.logging.Logger#setLevel level}.
97+ * If the {@code levelName} is not {@code null}, the level
98+ * of the specified logger is set to the parsed
99+ * {@link java.util.logging.Level Level}
100+ * matching the {@code levelName}.
101+ * If the {@code levelName} is {@code null}, the level
102+ * of the specified logger is set to {@code null} and
103+ * the effective level of the logger is inherited from
104+ * its nearest ancestor with a specific (non-null) level value.
105+ *
106+ * @param loggerName The name of the {@code Logger} to be set.
107+ * Must be non-null.
108+ * @param levelName The name of the level to set on the specified logger,
109+ * or {@code null} if setting the level to inherit
110+ * from its nearest ancestor.
111+ *
112+ * @throws IllegalArgumentException if the specified logger
113+ * does not exist, or {@code levelName} is not a valid level name.
114+ *
115+ * @throws SecurityException if a security manager exists and if
116+ * the caller does not have LoggingPermission("control").
117+ *
118+ * @see java.util.logging.Logger#setLevel
119+ */
120+ void setLoggerLevel(String loggerName, String levelName);
121+
122+ /**
123+ * Returns the name of the
124+ * {@linkplain java.util.logging.Logger#getParent parent}
125+ * for the specified logger.
126+ * If the specified logger does not exist, {@code null} is returned.
127+ * If the specified logger is the root {@code Logger} in the namespace,
128+ * the result will be an empty string.
129+ *
130+ * @param loggerName The name of a {@code Logger}.
131+ *
132+ * @return the name of the nearest existing parent logger;
133+ * an empty string if the specified logger is the root logger.
134+ * If the specified logger does not exist, {@code null}
135+ * is returned.
136+ */
137+ String getParentLoggerName(String loggerName);
138+}
java/pkg/java/lang/management/PlatformManagedObject.class+0−0

Binary file not shown.

java/pkg/java/lang/management/PlatformManagedObject.java+61−0
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.ObjectName;
29+
30+/**
31+ * A platform managed object is a {@linkplain javax.management.MXBean JMX MXBean}
32+ * for monitoring and managing a component in the Java platform.
33+ * Each platform managed object has a unique
34+ * <a href="ManagementFactory.html#MXBean">object name</a>
35+ * for the {@linkplain ManagementFactory#getPlatformMBeanServer
36+ * platform MBeanServer} access.
37+ * All platform MXBeans will implement this interface.
38+ *
39+ * <p>
40+ * Note:
41+ * The platform MXBean interfaces (i.e. all subinterfaces
42+ * of {@code PlatformManagedObject}) are implemented
43+ * by the Java platform only. New methods may be added in these interfaces
44+ * in future Java SE releases.
45+ * In addition, this {@code PlatformManagedObject} interface is only
46+ * intended for the management interfaces for the platform to extend but
47+ * not for applications.
48+ *
49+ * @see ManagementFactory
50+ * @since 1.7
51+ */
52+public interface PlatformManagedObject {
53+ /**
54+ * Returns an {@link ObjectName ObjectName} instance representing
55+ * the object name of this platform managed object.
56+ *
57+ * @return an {@link ObjectName ObjectName} instance representing
58+ * the object name of this platform managed object.
59+ */
60+ public ObjectName getObjectName();
61+}
java/pkg/java/lang/management/RuntimeMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/RuntimeMXBean.java+339−0
@@ -0,0 +1,339 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+/**
29+ * The management interface for the runtime system of
30+ * the Java virtual machine.
31+ *
32+ * <p> A Java virtual machine has a single instance of the implementation
33+ * class of this interface. This instance implementing this interface is
34+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
35+ * that can be obtained by calling
36+ * the {@link ManagementFactory#getRuntimeMXBean} method or
37+ * from the {@link ManagementFactory#getPlatformMBeanServer
38+ * platform <tt>MBeanServer</tt>} method.
39+ *
40+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
41+ * the runtime system within an MBeanServer is:
42+ * <blockquote>
43+ * {@link ManagementFactory#RUNTIME_MXBEAN_NAME
44+ * <tt>java.lang:type=Runtime</tt>}
45+ * </blockquote>
46+ *
47+ * It can be obtained by calling the
48+ * {@link PlatformManagedObject#getObjectName} method.
49+ *
50+ * <p> This interface defines several convenient methods for accessing
51+ * system properties about the Java virtual machine.
52+ *
53+ * @see ManagementFactory#getPlatformMXBeans(Class)
54+ * @see <a href="../../../javax/management/package-summary.html">
55+ * JMX Specification.</a>
56+ * @see <a href="package-summary.html#examples">
57+ * Ways to Access MXBeans</a>
58+ *
59+ * @author Mandy Chung
60+ * @since 1.5
61+ */
62+public interface RuntimeMXBean extends PlatformManagedObject {
63+ /**
64+ * Returns the name representing the running Java virtual machine.
65+ * The returned name string can be any arbitrary string and
66+ * a Java virtual machine implementation can choose
67+ * to embed platform-specific useful information in the
68+ * returned name string. Each running virtual machine could have
69+ * a different name.
70+ *
71+ * @return the name representing the running Java virtual machine.
72+ */
73+ public String getName();
74+
75+ /**
76+ * Returns the Java virtual machine implementation name.
77+ * This method is equivalent to {@link System#getProperty
78+ * System.getProperty("java.vm.name")}.
79+ *
80+ * @return the Java virtual machine implementation name.
81+ *
82+ * @throws java.lang.SecurityException
83+ * if a security manager exists and its
84+ * <code>checkPropertiesAccess</code> method doesn't allow access
85+ * to this system property.
86+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
87+ * @see java.lang.System#getProperty
88+ */
89+ public String getVmName();
90+
91+ /**
92+ * Returns the Java virtual machine implementation vendor.
93+ * This method is equivalent to {@link System#getProperty
94+ * System.getProperty("java.vm.vendor")}.
95+ *
96+ * @return the Java virtual machine implementation vendor.
97+ *
98+ * @throws java.lang.SecurityException
99+ * if a security manager exists and its
100+ * <code>checkPropertiesAccess</code> method doesn't allow access
101+ * to this system property.
102+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
103+ * @see java.lang.System#getProperty
104+ */
105+ public String getVmVendor();
106+
107+ /**
108+ * Returns the Java virtual machine implementation version.
109+ * This method is equivalent to {@link System#getProperty
110+ * System.getProperty("java.vm.version")}.
111+ *
112+ * @return the Java virtual machine implementation version.
113+ *
114+ * @throws java.lang.SecurityException
115+ * if a security manager exists and its
116+ * <code>checkPropertiesAccess</code> method doesn't allow access
117+ * to this system property.
118+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
119+ * @see java.lang.System#getProperty
120+ */
121+ public String getVmVersion();
122+
123+ /**
124+ * Returns the Java virtual machine specification name.
125+ * This method is equivalent to {@link System#getProperty
126+ * System.getProperty("java.vm.specification.name")}.
127+ *
128+ * @return the Java virtual machine specification name.
129+ *
130+ * @throws java.lang.SecurityException
131+ * if a security manager exists and its
132+ * <code>checkPropertiesAccess</code> method doesn't allow access
133+ * to this system property.
134+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
135+ * @see java.lang.System#getProperty
136+ */
137+ public String getSpecName();
138+
139+ /**
140+ * Returns the Java virtual machine specification vendor.
141+ * This method is equivalent to {@link System#getProperty
142+ * System.getProperty("java.vm.specification.vendor")}.
143+ *
144+ * @return the Java virtual machine specification vendor.
145+ *
146+ * @throws java.lang.SecurityException
147+ * if a security manager exists and its
148+ * <code>checkPropertiesAccess</code> method doesn't allow access
149+ * to this system property.
150+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
151+ * @see java.lang.System#getProperty
152+ */
153+ public String getSpecVendor();
154+
155+ /**
156+ * Returns the Java virtual machine specification version.
157+ * This method is equivalent to {@link System#getProperty
158+ * System.getProperty("java.vm.specification.version")}.
159+ *
160+ * @return the Java virtual machine specification version.
161+ *
162+ * @throws java.lang.SecurityException
163+ * if a security manager exists and its
164+ * <code>checkPropertiesAccess</code> method doesn't allow access
165+ * to this system property.
166+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
167+ * @see java.lang.System#getProperty
168+ */
169+ public String getSpecVersion();
170+
171+
172+ /**
173+ * Returns the version of the specification for the management interface
174+ * implemented by the running Java virtual machine.
175+ *
176+ * @return the version of the specification for the management interface
177+ * implemented by the running Java virtual machine.
178+ */
179+ public String getManagementSpecVersion();
180+
181+ /**
182+ * Returns the Java class path that is used by the system class loader
183+ * to search for class files.
184+ * This method is equivalent to {@link System#getProperty
185+ * System.getProperty("java.class.path")}.
186+ *
187+ * <p> Multiple paths in the Java class path are separated by the
188+ * path separator character of the platform of the Java virtual machine
189+ * being monitored.
190+ *
191+ * @return the Java class path.
192+ *
193+ * @throws java.lang.SecurityException
194+ * if a security manager exists and its
195+ * <code>checkPropertiesAccess</code> method doesn't allow access
196+ * to this system property.
197+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
198+ * @see java.lang.System#getProperty
199+ */
200+ public String getClassPath();
201+
202+ /**
203+ * Returns the Java library path.
204+ * This method is equivalent to {@link System#getProperty
205+ * System.getProperty("java.library.path")}.
206+ *
207+ * <p> Multiple paths in the Java library path are separated by the
208+ * path separator character of the platform of the Java virtual machine
209+ * being monitored.
210+ *
211+ * @return the Java library path.
212+ *
213+ * @throws java.lang.SecurityException
214+ * if a security manager exists and its
215+ * <code>checkPropertiesAccess</code> method doesn't allow access
216+ * to this system property.
217+ * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
218+ * @see java.lang.System#getProperty
219+ */
220+ public String getLibraryPath();
221+
222+ /**
223+ * Tests if the Java virtual machine supports the boot class path
224+ * mechanism used by the bootstrap class loader to search for class
225+ * files.
226+ *
227+ * @return <tt>true</tt> if the Java virtual machine supports the
228+ * class path mechanism; <tt>false</tt> otherwise.
229+ */
230+ public boolean isBootClassPathSupported();
231+
232+ /**
233+ * Returns the boot class path that is used by the bootstrap class loader
234+ * to search for class files.
235+ *
236+ * <p> Multiple paths in the boot class path are separated by the
237+ * path separator character of the platform on which the Java
238+ * virtual machine is running.
239+ *
240+ * <p>A Java virtual machine implementation may not support
241+ * the boot class path mechanism for the bootstrap class loader
242+ * to search for class files.
243+ * The {@link #isBootClassPathSupported} method can be used
244+ * to determine if the Java virtual machine supports this method.
245+ *
246+ * @return the boot class path.
247+ *
248+ * @throws java.lang.UnsupportedOperationException
249+ * if the Java virtual machine does not support this operation.
250+ *
251+ * @throws java.lang.SecurityException
252+ * if a security manager exists and the caller does not have
253+ * ManagementPermission("monitor").
254+ */
255+ public String getBootClassPath();
256+
257+ /**
258+ * Returns the input arguments passed to the Java virtual machine
259+ * which does not include the arguments to the <tt>main</tt> method.
260+ * This method returns an empty list if there is no input argument
261+ * to the Java virtual machine.
262+ * <p>
263+ * Some Java virtual machine implementations may take input arguments
264+ * from multiple different sources: for examples, arguments passed from
265+ * the application that launches the Java virtual machine such as
266+ * the 'java' command, environment variables, configuration files, etc.
267+ * <p>
268+ * Typically, not all command-line options to the 'java' command
269+ * are passed to the Java virtual machine.
270+ * Thus, the returned input arguments may not
271+ * include all command-line options.
272+ *
273+ * <p>
274+ * <b>MBeanServer access</b>:<br>
275+ * The mapped type of <tt>List<String></tt> is <tt>String[]</tt>.
276+ *
277+ * @return a list of <tt>String</tt> objects; each element
278+ * is an argument passed to the Java virtual machine.
279+ *
280+ * @throws java.lang.SecurityException
281+ * if a security manager exists and the caller does not have
282+ * ManagementPermission("monitor").
283+ */
284+ public java.util.List<String> getInputArguments();
285+
286+ /**
287+ * Returns the uptime of the Java virtual machine in milliseconds.
288+ *
289+ * @return uptime of the Java virtual machine in milliseconds.
290+ */
291+ public long getUptime();
292+
293+ /**
294+ * Returns the start time of the Java virtual machine in milliseconds.
295+ * This method returns the approximate time when the Java virtual
296+ * machine started.
297+ *
298+ * @return start time of the Java virtual machine in milliseconds.
299+ *
300+ */
301+ public long getStartTime();
302+
303+ /**
304+ * Returns a map of names and values of all system properties.
305+ * This method calls {@link System#getProperties} to get all
306+ * system properties. Properties whose name or value is not
307+ * a <tt>String</tt> are omitted.
308+ *
309+ * <p>
310+ * <b>MBeanServer access</b>:<br>
311+ * The mapped type of <tt>Map<String,String></tt> is
312+ * {@link javax.management.openmbean.TabularData TabularData}
313+ * with two items in each row as follows:
314+ * <blockquote>
315+ * <table border>
316+ * <tr>
317+ * <th>Item Name</th>
318+ * <th>Item Type</th>
319+ * </tr>
320+ * <tr>
321+ * <td><tt>key</tt></td>
322+ * <td><tt>String</tt></td>
323+ * </tr>
324+ * <tr>
325+ * <td><tt>value</tt></td>
326+ * <td><tt>String</tt></td>
327+ * </tr>
328+ * </table>
329+ * </blockquote>
330+ *
331+ * @return a map of names and values of all system properties.
332+ *
333+ * @throws java.lang.SecurityException
334+ * if a security manager exists and its
335+ * <code>checkPropertiesAccess</code> method doesn't allow access
336+ * to the system properties.
337+ */
338+ public java.util.Map<String, String> getSystemProperties();
339+}
java/pkg/java/lang/management/ThreadInfo$1.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ThreadInfo.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ThreadInfo.java+839−0
@@ -0,0 +1,839 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import javax.management.openmbean.CompositeData;
29+import sun.management.ManagementFactoryHelper;
30+import sun.management.ThreadInfoCompositeData;
31+import static java.lang.Thread.State.*;
32+
33+/**
34+ * Thread information. <tt>ThreadInfo</tt> contains the information
35+ * about a thread including:
36+ * <h4>General thread information</h4>
37+ * <ul>
38+ * <li>Thread ID.</li>
39+ * <li>Name of the thread.</li>
40+ * </ul>
41+ *
42+ * <h4>Execution information</h4>
43+ * <ul>
44+ * <li>Thread state.</li>
45+ * <li>The object upon which the thread is blocked due to:
46+ * <ul>
47+ * <li>waiting to enter a synchronization block/method, or</li>
48+ * <li>waiting to be notified in a {@link Object#wait Object.wait} method,
49+ * or</li>
50+ * <li>parking due to a {@link java.util.concurrent.locks.LockSupport#park
51+ * LockSupport.park} call.</li>
52+ * </ul>
53+ * </li>
54+ * <li>The ID of the thread that owns the object
55+ * that the thread is blocked.</li>
56+ * <li>Stack trace of the thread.</li>
57+ * <li>List of object monitors locked by the thread.</li>
58+ * <li>List of <a href="LockInfo.html#OwnableSynchronizer">
59+ * ownable synchronizers</a> locked by the thread.</li>
60+ * </ul>
61+ *
62+ * <h4><a name="SyncStats">Synchronization Statistics</a></h4>
63+ * <ul>
64+ * <li>The number of times that the thread has blocked for
65+ * synchronization or waited for notification.</li>
66+ * <li>The accumulated elapsed time that the thread has blocked
67+ * for synchronization or waited for notification
68+ * since {@link ThreadMXBean#setThreadContentionMonitoringEnabled
69+ * thread contention monitoring}
70+ * was enabled. Some Java virtual machine implementation
71+ * may not support this. The
72+ * {@link ThreadMXBean#isThreadContentionMonitoringSupported()}
73+ * method can be used to determine if a Java virtual machine
74+ * supports this.</li>
75+ * </ul>
76+ *
77+ * <p>This thread information class is designed for use in monitoring of
78+ * the system, not for synchronization control.
79+ *
80+ * <h4>MXBean Mapping</h4>
81+ * <tt>ThreadInfo</tt> is mapped to a {@link CompositeData CompositeData}
82+ * with attributes as specified in
83+ * the {@link #from from} method.
84+ *
85+ * @see ThreadMXBean#getThreadInfo
86+ * @see ThreadMXBean#dumpAllThreads
87+ *
88+ * @author Mandy Chung
89+ * @since 1.5
90+ */
91+
92+public class ThreadInfo {
93+ private String threadName;
94+ private long threadId;
95+ private long blockedTime;
96+ private long blockedCount;
97+ private long waitedTime;
98+ private long waitedCount;
99+ private LockInfo lock;
100+ private String lockName;
101+ private long lockOwnerId;
102+ private String lockOwnerName;
103+ private boolean inNative;
104+ private boolean suspended;
105+ private Thread.State threadState;
106+ private StackTraceElement[] stackTrace;
107+ private MonitorInfo[] lockedMonitors;
108+ private LockInfo[] lockedSynchronizers;
109+
110+ private static MonitorInfo[] EMPTY_MONITORS = new MonitorInfo[0];
111+ private static LockInfo[] EMPTY_SYNCS = new LockInfo[0];
112+
113+ /**
114+ * Constructor of ThreadInfo created by the JVM
115+ *
116+ * @param t Thread
117+ * @param state Thread state
118+ * @param lockObj Object on which the thread is blocked
119+ * @param lockOwner the thread holding the lock
120+ * @param blockedCount Number of times blocked to enter a lock
121+ * @param blockedTime Approx time blocked to enter a lock
122+ * @param waitedCount Number of times waited on a lock
123+ * @param waitedTime Approx time waited on a lock
124+ * @param stackTrace Thread stack trace
125+ */
126+ private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
127+ long blockedCount, long blockedTime,
128+ long waitedCount, long waitedTime,
129+ StackTraceElement[] stackTrace) {
130+ initialize(t, state, lockObj, lockOwner,
131+ blockedCount, blockedTime,
132+ waitedCount, waitedTime, stackTrace,
133+ EMPTY_MONITORS, EMPTY_SYNCS);
134+ }
135+
136+ /**
137+ * Constructor of ThreadInfo created by the JVM
138+ * for {@link ThreadMXBean#getThreadInfo(long[],boolean,boolean)}
139+ * and {@link ThreadMXBean#dumpAllThreads}
140+ *
141+ * @param t Thread
142+ * @param state Thread state
143+ * @param lockObj Object on which the thread is blocked
144+ * @param lockOwner the thread holding the lock
145+ * @param blockedCount Number of times blocked to enter a lock
146+ * @param blockedTime Approx time blocked to enter a lock
147+ * @param waitedCount Number of times waited on a lock
148+ * @param waitedTime Approx time waited on a lock
149+ * @param stackTrace Thread stack trace
150+ * @param lockedMonitors List of locked monitors
151+ * @param lockedSynchronizers List of locked synchronizers
152+ */
153+ private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
154+ long blockedCount, long blockedTime,
155+ long waitedCount, long waitedTime,
156+ StackTraceElement[] stackTrace,
157+ Object[] monitors,
158+ int[] stackDepths,
159+ Object[] synchronizers) {
160+ int numMonitors = (monitors == null ? 0 : monitors.length);
161+ MonitorInfo[] lockedMonitors;
162+ if (numMonitors == 0) {
163+ lockedMonitors = EMPTY_MONITORS;
164+ } else {
165+ lockedMonitors = new MonitorInfo[numMonitors];
166+ for (int i = 0; i < numMonitors; i++) {
167+ Object lock = monitors[i];
168+ String className = lock.getClass().getName();
169+ int identityHashCode = System.identityHashCode(lock);
170+ int depth = stackDepths[i];
171+ StackTraceElement ste = (depth >= 0 ? stackTrace[depth]
172+ : null);
173+ lockedMonitors[i] = new MonitorInfo(className,
174+ identityHashCode,
175+ depth,
176+ ste);
177+ }
178+ }
179+
180+ int numSyncs = (synchronizers == null ? 0 : synchronizers.length);
181+ LockInfo[] lockedSynchronizers;
182+ if (numSyncs == 0) {
183+ lockedSynchronizers = EMPTY_SYNCS;
184+ } else {
185+ lockedSynchronizers = new LockInfo[numSyncs];
186+ for (int i = 0; i < numSyncs; i++) {
187+ Object lock = synchronizers[i];
188+ String className = lock.getClass().getName();
189+ int identityHashCode = System.identityHashCode(lock);
190+ lockedSynchronizers[i] = new LockInfo(className,
191+ identityHashCode);
192+ }
193+ }
194+
195+ initialize(t, state, lockObj, lockOwner,
196+ blockedCount, blockedTime,
197+ waitedCount, waitedTime, stackTrace,
198+ lockedMonitors, lockedSynchronizers);
199+ }
200+
201+ /**
202+ * Initialize ThreadInfo object
203+ *
204+ * @param t Thread
205+ * @param state Thread state
206+ * @param lockObj Object on which the thread is blocked
207+ * @param lockOwner the thread holding the lock
208+ * @param blockedCount Number of times blocked to enter a lock
209+ * @param blockedTime Approx time blocked to enter a lock
210+ * @param waitedCount Number of times waited on a lock
211+ * @param waitedTime Approx time waited on a lock
212+ * @param stackTrace Thread stack trace
213+ * @param lockedMonitors List of locked monitors
214+ * @param lockedSynchronizers List of locked synchronizers
215+ */
216+ private void initialize(Thread t, int state, Object lockObj, Thread lockOwner,
217+ long blockedCount, long blockedTime,
218+ long waitedCount, long waitedTime,
219+ StackTraceElement[] stackTrace,
220+ MonitorInfo[] lockedMonitors,
221+ LockInfo[] lockedSynchronizers) {
222+ this.threadId = t.getId();
223+ this.threadName = t.getName();
224+ this.threadState = ManagementFactoryHelper.toThreadState(state);
225+ this.suspended = ManagementFactoryHelper.isThreadSuspended(state);
226+ this.inNative = ManagementFactoryHelper.isThreadRunningNative(state);
227+ this.blockedCount = blockedCount;
228+ this.blockedTime = blockedTime;
229+ this.waitedCount = waitedCount;
230+ this.waitedTime = waitedTime;
231+
232+ if (lockObj == null) {
233+ this.lock = null;
234+ this.lockName = null;
235+ } else {
236+ this.lock = new LockInfo(lockObj);
237+ this.lockName =
238+ lock.getClassName() + '@' +
239+ Integer.toHexString(lock.getIdentityHashCode());
240+ }
241+ if (lockOwner == null) {
242+ this.lockOwnerId = -1;
243+ this.lockOwnerName = null;
244+ } else {
245+ this.lockOwnerId = lockOwner.getId();
246+ this.lockOwnerName = lockOwner.getName();
247+ }
248+ if (stackTrace == null) {
249+ this.stackTrace = NO_STACK_TRACE;
250+ } else {
251+ this.stackTrace = stackTrace;
252+ }
253+ this.lockedMonitors = lockedMonitors;
254+ this.lockedSynchronizers = lockedSynchronizers;
255+ }
256+
257+ /*
258+ * Constructs a <tt>ThreadInfo</tt> object from a
259+ * {@link CompositeData CompositeData}.
260+ */
261+ private ThreadInfo(CompositeData cd) {
262+ ThreadInfoCompositeData ticd = ThreadInfoCompositeData.getInstance(cd);
263+
264+ threadId = ticd.threadId();
265+ threadName = ticd.threadName();
266+ blockedTime = ticd.blockedTime();
267+ blockedCount = ticd.blockedCount();
268+ waitedTime = ticd.waitedTime();
269+ waitedCount = ticd.waitedCount();
270+ lockName = ticd.lockName();
271+ lockOwnerId = ticd.lockOwnerId();
272+ lockOwnerName = ticd.lockOwnerName();
273+ threadState = ticd.threadState();
274+ suspended = ticd.suspended();
275+ inNative = ticd.inNative();
276+ stackTrace = ticd.stackTrace();
277+
278+ // 6.0 attributes
279+ if (ticd.isCurrentVersion()) {
280+ lock = ticd.lockInfo();
281+ lockedMonitors = ticd.lockedMonitors();
282+ lockedSynchronizers = ticd.lockedSynchronizers();
283+ } else {
284+ // lockInfo is a new attribute added in 1.6 ThreadInfo
285+ // If cd is a 5.0 version, construct the LockInfo object
286+ // from the lockName value.
287+ if (lockName != null) {
288+ String result[] = lockName.split("@");
289+ if (result.length == 2) {
290+ int identityHashCode = Integer.parseInt(result[1], 16);
291+ lock = new LockInfo(result[0], identityHashCode);
292+ } else {
293+ assert result.length == 2;
294+ lock = null;
295+ }
296+ } else {
297+ lock = null;
298+ }
299+ lockedMonitors = EMPTY_MONITORS;
300+ lockedSynchronizers = EMPTY_SYNCS;
301+ }
302+ }
303+
304+ /**
305+ * Returns the ID of the thread associated with this <tt>ThreadInfo</tt>.
306+ *
307+ * @return the ID of the associated thread.
308+ */
309+ public long getThreadId() {
310+ return threadId;
311+ }
312+
313+ /**
314+ * Returns the name of the thread associated with this <tt>ThreadInfo</tt>.
315+ *
316+ * @return the name of the associated thread.
317+ */
318+ public String getThreadName() {
319+ return threadName;
320+ }
321+
322+ /**
323+ * Returns the state of the thread associated with this <tt>ThreadInfo</tt>.
324+ *
325+ * @return <tt>Thread.State</tt> of the associated thread.
326+ */
327+ public Thread.State getThreadState() {
328+ return threadState;
329+ }
330+
331+ /**
332+ * Returns the approximate accumulated elapsed time (in milliseconds)
333+ * that the thread associated with this <tt>ThreadInfo</tt>
334+ * has blocked to enter or reenter a monitor
335+ * since thread contention monitoring is enabled.
336+ * I.e. the total accumulated time the thread has been in the
337+ * {@link java.lang.Thread.State#BLOCKED BLOCKED} state since thread
338+ * contention monitoring was last enabled.
339+ * This method returns <tt>-1</tt> if thread contention monitoring
340+ * is disabled.
341+ *
342+ * <p>The Java virtual machine may measure the time with a high
343+ * resolution timer. This statistic is reset when
344+ * the thread contention monitoring is reenabled.
345+ *
346+ * @return the approximate accumulated elapsed time in milliseconds
347+ * that a thread entered the <tt>BLOCKED</tt> state;
348+ * <tt>-1</tt> if thread contention monitoring is disabled.
349+ *
350+ * @throws java.lang.UnsupportedOperationException if the Java
351+ * virtual machine does not support this operation.
352+ *
353+ * @see ThreadMXBean#isThreadContentionMonitoringSupported
354+ * @see ThreadMXBean#setThreadContentionMonitoringEnabled
355+ */
356+ public long getBlockedTime() {
357+ return blockedTime;
358+ }
359+
360+ /**
361+ * Returns the total number of times that
362+ * the thread associated with this <tt>ThreadInfo</tt>
363+ * blocked to enter or reenter a monitor.
364+ * I.e. the number of times a thread has been in the
365+ * {@link java.lang.Thread.State#BLOCKED BLOCKED} state.
366+ *
367+ * @return the total number of times that the thread
368+ * entered the <tt>BLOCKED</tt> state.
369+ */
370+ public long getBlockedCount() {
371+ return blockedCount;
372+ }
373+
374+ /**
375+ * Returns the approximate accumulated elapsed time (in milliseconds)
376+ * that the thread associated with this <tt>ThreadInfo</tt>
377+ * has waited for notification
378+ * since thread contention monitoring is enabled.
379+ * I.e. the total accumulated time the thread has been in the
380+ * {@link java.lang.Thread.State#WAITING WAITING}
381+ * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
382+ * since thread contention monitoring is enabled.
383+ * This method returns <tt>-1</tt> if thread contention monitoring
384+ * is disabled.
385+ *
386+ * <p>The Java virtual machine may measure the time with a high
387+ * resolution timer. This statistic is reset when
388+ * the thread contention monitoring is reenabled.
389+ *
390+ * @return the approximate accumulated elapsed time in milliseconds
391+ * that a thread has been in the <tt>WAITING</tt> or
392+ * <tt>TIMED_WAITING</tt> state;
393+ * <tt>-1</tt> if thread contention monitoring is disabled.
394+ *
395+ * @throws java.lang.UnsupportedOperationException if the Java
396+ * virtual machine does not support this operation.
397+ *
398+ * @see ThreadMXBean#isThreadContentionMonitoringSupported
399+ * @see ThreadMXBean#setThreadContentionMonitoringEnabled
400+ */
401+ public long getWaitedTime() {
402+ return waitedTime;
403+ }
404+
405+ /**
406+ * Returns the total number of times that
407+ * the thread associated with this <tt>ThreadInfo</tt>
408+ * waited for notification.
409+ * I.e. the number of times that a thread has been
410+ * in the {@link java.lang.Thread.State#WAITING WAITING}
411+ * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state.
412+ *
413+ * @return the total number of times that the thread
414+ * was in the <tt>WAITING</tt> or <tt>TIMED_WAITING</tt> state.
415+ */
416+ public long getWaitedCount() {
417+ return waitedCount;
418+ }
419+
420+ /**
421+ * Returns the <tt>LockInfo</tt> of an object for which
422+ * the thread associated with this <tt>ThreadInfo</tt>
423+ * is blocked waiting.
424+ * A thread can be blocked waiting for one of the following:
425+ * <ul>
426+ * <li>an object monitor to be acquired for entering or reentering
427+ * a synchronization block/method.
428+ * <br>The thread is in the {@link java.lang.Thread.State#BLOCKED BLOCKED}
429+ * state waiting to enter the <tt>synchronized</tt> statement
430+ * or method.
431+ * <p></li>
432+ * <li>an object monitor to be notified by another thread.
433+ * <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
434+ * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
435+ * due to a call to the {@link Object#wait Object.wait} method.
436+ * <p></li>
437+ * <li>a synchronization object responsible for the thread parking.
438+ * <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
439+ * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
440+ * due to a call to the
441+ * {@link java.util.concurrent.locks.LockSupport#park(Object)
442+ * LockSupport.park} method. The synchronization object
443+ * is the object returned from
444+ * {@link java.util.concurrent.locks.LockSupport#getBlocker
445+ * LockSupport.getBlocker} method. Typically it is an
446+ * <a href="LockInfo.html#OwnableSynchronizer"> ownable synchronizer</a>
447+ * or a {@link java.util.concurrent.locks.Condition Condition}.</li>
448+ * </ul>
449+ *
450+ * <p>This method returns <tt>null</tt> if the thread is not in any of
451+ * the above conditions.
452+ *
453+ * @return <tt>LockInfo</tt> of an object for which the thread
454+ * is blocked waiting if any; <tt>null</tt> otherwise.
455+ * @since 1.6
456+ */
457+ public LockInfo getLockInfo() {
458+ return lock;
459+ }
460+
461+ /**
462+ * Returns the {@link LockInfo#toString string representation}
463+ * of an object for which the thread associated with this
464+ * <tt>ThreadInfo</tt> is blocked waiting.
465+ * This method is equivalent to calling:
466+ * <blockquote>
467+ * <pre>
468+ * getLockInfo().toString()
469+ * </pre></blockquote>
470+ *
471+ * <p>This method will return <tt>null</tt> if this thread is not blocked
472+ * waiting for any object or if the object is not owned by any thread.
473+ *
474+ * @return the string representation of the object on which
475+ * the thread is blocked if any;
476+ * <tt>null</tt> otherwise.
477+ *
478+ * @see #getLockInfo
479+ */
480+ public String getLockName() {
481+ return lockName;
482+ }
483+
484+ /**
485+ * Returns the ID of the thread which owns the object
486+ * for which the thread associated with this <tt>ThreadInfo</tt>
487+ * is blocked waiting.
488+ * This method will return <tt>-1</tt> if this thread is not blocked
489+ * waiting for any object or if the object is not owned by any thread.
490+ *
491+ * @return the thread ID of the owner thread of the object
492+ * this thread is blocked on;
493+ * <tt>-1</tt> if this thread is not blocked
494+ * or if the object lis not owned by any thread.
495+ *
496+ * @see #getLockInfo
497+ */
498+ public long getLockOwnerId() {
499+ return lockOwnerId;
500+ }
501+
502+ /**
503+ * Returns the name of the thread which owns the object
504+ * for which the thread associated with this <tt>ThreadInfo</tt>
505+ * is blocked waiting.
506+ * This method will return <tt>null</tt> if this thread is not blocked
507+ * waiting for any object or if the object is not owned by any thread.
508+ *
509+ * @return the name of the thread that owns the object
510+ * this thread is blocked on;
511+ * <tt>null</tt> if this thread is not blocked
512+ * or if the object is not owned by any thread.
513+ *
514+ * @see #getLockInfo
515+ */
516+ public String getLockOwnerName() {
517+ return lockOwnerName;
518+ }
519+
520+ /**
521+ * Returns the stack trace of the thread
522+ * associated with this <tt>ThreadInfo</tt>.
523+ * If no stack trace was requested for this thread info, this method
524+ * will return a zero-length array.
525+ * If the returned array is of non-zero length then the first element of
526+ * the array represents the top of the stack, which is the most recent
527+ * method invocation in the sequence. The last element of the array
528+ * represents the bottom of the stack, which is the least recent method
529+ * invocation in the sequence.
530+ *
531+ * <p>Some Java virtual machines may, under some circumstances, omit one
532+ * or more stack frames from the stack trace. In the extreme case,
533+ * a virtual machine that has no stack trace information concerning
534+ * the thread associated with this <tt>ThreadInfo</tt>
535+ * is permitted to return a zero-length array from this method.
536+ *
537+ * @return an array of <tt>StackTraceElement</tt> objects of the thread.
538+ */
539+ public StackTraceElement[] getStackTrace() {
540+ return stackTrace;
541+ }
542+
543+ /**
544+ * Tests if the thread associated with this <tt>ThreadInfo</tt>
545+ * is suspended. This method returns <tt>true</tt> if
546+ * {@link Thread#suspend} has been called.
547+ *
548+ * @return <tt>true</tt> if the thread is suspended;
549+ * <tt>false</tt> otherwise.
550+ */
551+ public boolean isSuspended() {
552+ return suspended;
553+ }
554+
555+ /**
556+ * Tests if the thread associated with this <tt>ThreadInfo</tt>
557+ * is executing native code via the Java Native Interface (JNI).
558+ * The JNI native code does not include
559+ * the virtual machine support code or the compiled native
560+ * code generated by the virtual machine.
561+ *
562+ * @return <tt>true</tt> if the thread is executing native code;
563+ * <tt>false</tt> otherwise.
564+ */
565+ public boolean isInNative() {
566+ return inNative;
567+ }
568+
569+ /**
570+ * Returns a string representation of this thread info.
571+ * The format of this string depends on the implementation.
572+ * The returned string will typically include
573+ * the {@linkplain #getThreadName thread name},
574+ * the {@linkplain #getThreadId thread ID},
575+ * its {@linkplain #getThreadState state},
576+ * and a {@linkplain #getStackTrace stack trace} if any.
577+ *
578+ * @return a string representation of this thread info.
579+ */
580+ public String toString() {
581+ StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" +
582+ " Id=" + getThreadId() + " " +
583+ getThreadState());
584+ if (getLockName() != null) {
585+ sb.append(" on " + getLockName());
586+ }
587+ if (getLockOwnerName() != null) {
588+ sb.append(" owned by \"" + getLockOwnerName() +
589+ "\" Id=" + getLockOwnerId());
590+ }
591+ if (isSuspended()) {
592+ sb.append(" (suspended)");
593+ }
594+ if (isInNative()) {
595+ sb.append(" (in native)");
596+ }
597+ sb.append('\n');
598+ int i = 0;
599+ for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
600+ StackTraceElement ste = stackTrace[i];
601+ sb.append("\tat " + ste.toString());
602+ sb.append('\n');
603+ if (i == 0 && getLockInfo() != null) {
604+ Thread.State ts = getThreadState();
605+ switch (ts) {
606+ case BLOCKED:
607+ sb.append("\t- blocked on " + getLockInfo());
608+ sb.append('\n');
609+ break;
610+ case WAITING:
611+ sb.append("\t- waiting on " + getLockInfo());
612+ sb.append('\n');
613+ break;
614+ case TIMED_WAITING:
615+ sb.append("\t- waiting on " + getLockInfo());
616+ sb.append('\n');
617+ break;
618+ default:
619+ }
620+ }
621+
622+ for (MonitorInfo mi : lockedMonitors) {
623+ if (mi.getLockedStackDepth() == i) {
624+ sb.append("\t- locked " + mi);
625+ sb.append('\n');
626+ }
627+ }
628+ }
629+ if (i < stackTrace.length) {
630+ sb.append("\t...");
631+ sb.append('\n');
632+ }
633+
634+ LockInfo[] locks = getLockedSynchronizers();
635+ if (locks.length > 0) {
636+ sb.append("\n\tNumber of locked synchronizers = " + locks.length);
637+ sb.append('\n');
638+ for (LockInfo li : locks) {
639+ sb.append("\t- " + li);
640+ sb.append('\n');
641+ }
642+ }
643+ sb.append('\n');
644+ return sb.toString();
645+ }
646+ private static final int MAX_FRAMES = 8;
647+
648+ /**
649+ * Returns a <tt>ThreadInfo</tt> object represented by the
650+ * given <tt>CompositeData</tt>.
651+ * The given <tt>CompositeData</tt> must contain the following attributes
652+ * unless otherwise specified below:
653+ * <blockquote>
654+ * <table border>
655+ * <tr>
656+ * <th align=left>Attribute Name</th>
657+ * <th align=left>Type</th>
658+ * </tr>
659+ * <tr>
660+ * <td>threadId</td>
661+ * <td><tt>java.lang.Long</tt></td>
662+ * </tr>
663+ * <tr>
664+ * <td>threadName</td>
665+ * <td><tt>java.lang.String</tt></td>
666+ * </tr>
667+ * <tr>
668+ * <td>threadState</td>
669+ * <td><tt>java.lang.String</tt></td>
670+ * </tr>
671+ * <tr>
672+ * <td>suspended</td>
673+ * <td><tt>java.lang.Boolean</tt></td>
674+ * </tr>
675+ * <tr>
676+ * <td>inNative</td>
677+ * <td><tt>java.lang.Boolean</tt></td>
678+ * </tr>
679+ * <tr>
680+ * <td>blockedCount</td>
681+ * <td><tt>java.lang.Long</tt></td>
682+ * </tr>
683+ * <tr>
684+ * <td>blockedTime</td>
685+ * <td><tt>java.lang.Long</tt></td>
686+ * </tr>
687+ * <tr>
688+ * <td>waitedCount</td>
689+ * <td><tt>java.lang.Long</tt></td>
690+ * </tr>
691+ * <tr>
692+ * <td>waitedTime</td>
693+ * <td><tt>java.lang.Long</tt></td>
694+ * </tr>
695+ * <tr>
696+ * <td>lockInfo</td>
697+ * <td><tt>javax.management.openmbean.CompositeData</tt>
698+ * - the mapped type for {@link LockInfo} as specified in the
699+ * <a href="../../../javax/management/MXBean.html#mapping-rules">
700+ * type mapping rules</a> of
701+ * {@linkplain javax.management.MXBean MXBeans}.
702+ * <p>
703+ * If <tt>cd</tt> does not contain this attribute,
704+ * the <tt>LockInfo</tt> object will be constructed from
705+ * the value of the <tt>lockName</tt> attribute. </td>
706+ * </tr>
707+ * <tr>
708+ * <td>lockName</td>
709+ * <td><tt>java.lang.String</tt></td>
710+ * </tr>
711+ * <tr>
712+ * <td>lockOwnerId</td>
713+ * <td><tt>java.lang.Long</tt></td>
714+ * </tr>
715+ * <tr>
716+ * <td>lockOwnerName</td>
717+ * <td><tt>java.lang.String</tt></td>
718+ * </tr>
719+ * <tr>
720+ * <td><a name="StackTrace">stackTrace</a></td>
721+ * <td><tt>javax.management.openmbean.CompositeData[]</tt>
722+ * <p>
723+ * Each element is a <tt>CompositeData</tt> representing
724+ * StackTraceElement containing the following attributes:
725+ * <blockquote>
726+ * <table cellspacing=1 cellpadding=0>
727+ * <tr>
728+ * <th align=left>Attribute Name</th>
729+ * <th align=left>Type</th>
730+ * </tr>
731+ * <tr>
732+ * <td>className</td>
733+ * <td><tt>java.lang.String</tt></td>
734+ * </tr>
735+ * <tr>
736+ * <td>methodName</td>
737+ * <td><tt>java.lang.String</tt></td>
738+ * </tr>
739+ * <tr>
740+ * <td>fileName</td>
741+ * <td><tt>java.lang.String</tt></td>
742+ * </tr>
743+ * <tr>
744+ * <td>lineNumber</td>
745+ * <td><tt>java.lang.Integer</tt></td>
746+ * </tr>
747+ * <tr>
748+ * <td>nativeMethod</td>
749+ * <td><tt>java.lang.Boolean</tt></td>
750+ * </tr>
751+ * </table>
752+ * </blockquote>
753+ * </td>
754+ * </tr>
755+ * <tr>
756+ * <td>lockedMonitors</td>
757+ * <td><tt>javax.management.openmbean.CompositeData[]</tt>
758+ * whose element type is the mapped type for
759+ * {@link MonitorInfo} as specified in the
760+ * {@link MonitorInfo#from Monitor.from} method.
761+ * <p>
762+ * If <tt>cd</tt> does not contain this attribute,
763+ * this attribute will be set to an empty array. </td>
764+ * </tr>
765+ * <tr>
766+ * <td>lockedSynchronizers</td>
767+ * <td><tt>javax.management.openmbean.CompositeData[]</tt>
768+ * whose element type is the mapped type for
769+ * {@link LockInfo} as specified in the
770+ * <a href="../../../javax/management/MXBean.html#mapping-rules">
771+ * type mapping rules</a> of
772+ * {@linkplain javax.management.MXBean MXBeans}.
773+ * <p>
774+ * If <tt>cd</tt> does not contain this attribute,
775+ * this attribute will be set to an empty array. </td>
776+ * </tr>
777+ * </table>
778+ * </blockquote>
779+ *
780+ * @param cd <tt>CompositeData</tt> representing a <tt>ThreadInfo</tt>
781+ *
782+ * @throws IllegalArgumentException if <tt>cd</tt> does not
783+ * represent a <tt>ThreadInfo</tt> with the attributes described
784+ * above.
785+ *
786+ * @return a <tt>ThreadInfo</tt> object represented
787+ * by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
788+ * <tt>null</tt> otherwise.
789+ */
790+ public static ThreadInfo from(CompositeData cd) {
791+ if (cd == null) {
792+ return null;
793+ }
794+
795+ if (cd instanceof ThreadInfoCompositeData) {
796+ return ((ThreadInfoCompositeData) cd).getThreadInfo();
797+ } else {
798+ return new ThreadInfo(cd);
799+ }
800+ }
801+
802+ /**
803+ * Returns an array of {@link MonitorInfo} objects, each of which
804+ * represents an object monitor currently locked by the thread
805+ * associated with this <tt>ThreadInfo</tt>.
806+ * If no locked monitor was requested for this thread info or
807+ * no monitor is locked by the thread, this method
808+ * will return a zero-length array.
809+ *
810+ * @return an array of <tt>MonitorInfo</tt> objects representing
811+ * the object monitors locked by the thread.
812+ *
813+ * @since 1.6
814+ */
815+ public MonitorInfo[] getLockedMonitors() {
816+ return lockedMonitors;
817+ }
818+
819+ /**
820+ * Returns an array of {@link LockInfo} objects, each of which
821+ * represents an <a href="LockInfo.html#OwnableSynchronizer">ownable
822+ * synchronizer</a> currently locked by the thread associated with
823+ * this <tt>ThreadInfo</tt>. If no locked synchronizer was
824+ * requested for this thread info or no synchronizer is locked by
825+ * the thread, this method will return a zero-length array.
826+ *
827+ * @return an array of <tt>LockInfo</tt> objects representing
828+ * the ownable synchronizers locked by the thread.
829+ *
830+ * @since 1.6
831+ */
832+ public LockInfo[] getLockedSynchronizers() {
833+ // represents an <a href="LockInfo.html#OwnableSynchronizer">
834+ return lockedSynchronizers;
835+ }
836+
837+ private static final StackTraceElement[] NO_STACK_TRACE =
838+ new StackTraceElement[0];
839+}
java/pkg/java/lang/management/ThreadMXBean.class+0−0

Binary file not shown.

java/pkg/java/lang/management/ThreadMXBean.java+806−0
@@ -0,0 +1,806 @@
1+/*
2+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.lang.management;
27+
28+import java.util.Map;
29+
30+/**
31+ * The management interface for the thread system of
32+ * the Java virtual machine.
33+ *
34+ * <p> A Java virtual machine has a single instance of the implementation
35+ * class of this interface. This instance implementing this interface is
36+ * an <a href="ManagementFactory.html#MXBean">MXBean</a>
37+ * that can be obtained by calling
38+ * the {@link ManagementFactory#getThreadMXBean} method or
39+ * from the {@link ManagementFactory#getPlatformMBeanServer
40+ * platform <tt>MBeanServer</tt>} method.
41+ *
42+ * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
43+ * the thread system within an MBeanServer is:
44+ * <blockquote>
45+ * {@link ManagementFactory#THREAD_MXBEAN_NAME
46+ * <tt>java.lang:type=Threading</tt>}
47+ * </blockquote>
48+ *
49+ * It can be obtained by calling the
50+ * {@link PlatformManagedObject#getObjectName} method.
51+ *
52+ * <h4>Thread ID</h4>
53+ * Thread ID is a positive long value returned by calling the
54+ * {@link java.lang.Thread#getId} method for a thread.
55+ * The thread ID is unique during its lifetime. When a thread
56+ * is terminated, this thread ID may be reused.
57+ *
58+ * <p> Some methods in this interface take a thread ID or an array
59+ * of thread IDs as the input parameter and return per-thread information.
60+ *
61+ * <h4>Thread CPU time</h4>
62+ * A Java virtual machine implementation may support measuring
63+ * the CPU time for the current thread, for any thread, or for no threads.
64+ *
65+ * <p>
66+ * The {@link #isThreadCpuTimeSupported} method can be used to determine
67+ * if a Java virtual machine supports measuring of the CPU time for any
68+ * thread. The {@link #isCurrentThreadCpuTimeSupported} method can
69+ * be used to determine if a Java virtual machine supports measuring of
70+ * the CPU time for the current thread.
71+ * A Java virtual machine implementation that supports CPU time measurement
72+ * for any thread will also support that for the current thread.
73+ *
74+ * <p> The CPU time provided by this interface has nanosecond precision
75+ * but not necessarily nanosecond accuracy.
76+ *
77+ * <p>
78+ * A Java virtual machine may disable CPU time measurement
79+ * by default.
80+ * The {@link #isThreadCpuTimeEnabled} and {@link #setThreadCpuTimeEnabled}
81+ * methods can be used to test if CPU time measurement is enabled
82+ * and to enable/disable this support respectively.
83+ * Enabling thread CPU measurement could be expensive in some
84+ * Java virtual machine implementations.
85+ *
86+ * <h4>Thread Contention Monitoring</h4>
87+ * Some Java virtual machines may support thread contention monitoring.
88+ * When thread contention monitoring is enabled, the accumulated elapsed
89+ * time that the thread has blocked for synchronization or waited for
90+ * notification will be collected and returned in the
91+ * <a href="ThreadInfo.html#SyncStats"><tt>ThreadInfo</tt></a> object.
92+ * <p>
93+ * The {@link #isThreadContentionMonitoringSupported} method can be used to
94+ * determine if a Java virtual machine supports thread contention monitoring.
95+ * The thread contention monitoring is disabled by default. The
96+ * {@link #setThreadContentionMonitoringEnabled} method can be used to enable
97+ * thread contention monitoring.
98+ *
99+ * <h4>Synchronization Information and Deadlock Detection</h4>
100+ * Some Java virtual machines may support monitoring of
101+ * {@linkplain #isObjectMonitorUsageSupported object monitor usage} and
102+ * {@linkplain #isSynchronizerUsageSupported ownable synchronizer usage}.
103+ * The {@link #getThreadInfo(long[], boolean, boolean)} and
104+ * {@link #dumpAllThreads} methods can be used to obtain the thread stack trace
105+ * and synchronization information including which
106+ * {@linkplain LockInfo <i>lock</i>} a thread is blocked to
107+ * acquire or waiting on and which locks the thread currently owns.
108+ * <p>
109+ * The <tt>ThreadMXBean</tt> interface provides the
110+ * {@link #findMonitorDeadlockedThreads} and
111+ * {@link #findDeadlockedThreads} methods to find deadlocks in
112+ * the running application.
113+ *
114+ * @see ManagementFactory#getPlatformMXBeans(Class)
115+ * @see <a href="../../../javax/management/package-summary.html">
116+ * JMX Specification.</a>
117+ * @see <a href="package-summary.html#examples">
118+ * Ways to Access MXBeans</a>
119+ *
120+ * @author Mandy Chung
121+ * @since 1.5
122+ */
123+
124+public interface ThreadMXBean extends PlatformManagedObject {
125+ /**
126+ * Returns the current number of live threads including both
127+ * daemon and non-daemon threads.
128+ *
129+ * @return the current number of live threads.
130+ */
131+ public int getThreadCount();
132+
133+ /**
134+ * Returns the peak live thread count since the Java virtual machine
135+ * started or peak was reset.
136+ *
137+ * @return the peak live thread count.
138+ */
139+ public int getPeakThreadCount();
140+
141+ /**
142+ * Returns the total number of threads created and also started
143+ * since the Java virtual machine started.
144+ *
145+ * @return the total number of threads started.
146+ */
147+ public long getTotalStartedThreadCount();
148+
149+ /**
150+ * Returns the current number of live daemon threads.
151+ *
152+ * @return the current number of live daemon threads.
153+ */
154+ public int getDaemonThreadCount();
155+
156+ /**
157+ * Returns all live thread IDs.
158+ * Some threads included in the returned array
159+ * may have been terminated when this method returns.
160+ *
161+ * @return an array of <tt>long</tt>, each is a thread ID.
162+ *
163+ * @throws java.lang.SecurityException if a security manager
164+ * exists and the caller does not have
165+ * ManagementPermission("monitor").
166+ */
167+ public long[] getAllThreadIds();
168+
169+ /**
170+ * Returns the thread info for a thread of the specified
171+ * <tt>id</tt> with no stack trace.
172+ * This method is equivalent to calling:
173+ * <blockquote>
174+ * {@link #getThreadInfo(long, int) getThreadInfo(id, 0);}
175+ * </blockquote>
176+ *
177+ * <p>
178+ * This method returns a <tt>ThreadInfo</tt> object representing
179+ * the thread information for the thread of the specified ID.
180+ * The stack trace, locked monitors, and locked synchronizers
181+ * in the returned <tt>ThreadInfo</tt> object will
182+ * be empty.
183+ *
184+ * If a thread of the given ID is not alive or does not exist,
185+ * this method will return <tt>null</tt>. A thread is alive if
186+ * it has been started and has not yet died.
187+ *
188+ * <p>
189+ * <b>MBeanServer access</b>:<br>
190+ * The mapped type of <tt>ThreadInfo</tt> is
191+ * <tt>CompositeData</tt> with attributes as specified in the
192+ * {@link ThreadInfo#from ThreadInfo.from} method.
193+ *
194+ * @param id the thread ID of the thread. Must be positive.
195+ *
196+ * @return a {@link ThreadInfo} object for the thread of the given ID
197+ * with no stack trace, no locked monitor and no synchronizer info;
198+ * <tt>null</tt> if the thread of the given ID is not alive or
199+ * it does not exist.
200+ *
201+ * @throws IllegalArgumentException if <tt>id &lt= 0</tt>.
202+ * @throws java.lang.SecurityException if a security manager
203+ * exists and the caller does not have
204+ * ManagementPermission("monitor").
205+ */
206+ public ThreadInfo getThreadInfo(long id);
207+
208+ /**
209+ * Returns the thread info for each thread
210+ * whose ID is in the input array <tt>ids</tt> with no stack trace.
211+ * This method is equivalent to calling:
212+ * <blockquote><pre>
213+ * {@link #getThreadInfo(long[], int) getThreadInfo}(ids, 0);
214+ * </pre></blockquote>
215+ *
216+ * <p>
217+ * This method returns an array of the <tt>ThreadInfo</tt> objects.
218+ * The stack trace, locked monitors, and locked synchronizers
219+ * in each <tt>ThreadInfo</tt> object will be empty.
220+ *
221+ * If a thread of a given ID is not alive or does not exist,
222+ * the corresponding element in the returned array will
223+ * contain <tt>null</tt>. A thread is alive if
224+ * it has been started and has not yet died.
225+ *
226+ * <p>
227+ * <b>MBeanServer access</b>:<br>
228+ * The mapped type of <tt>ThreadInfo</tt> is
229+ * <tt>CompositeData</tt> with attributes as specified in the
230+ * {@link ThreadInfo#from ThreadInfo.from} method.
231+ *
232+ * @param ids an array of thread IDs.
233+ * @return an array of the {@link ThreadInfo} objects, each containing
234+ * information about a thread whose ID is in the corresponding
235+ * element of the input array of IDs
236+ * with no stack trace, no locked monitor and no synchronizer info.
237+ *
238+ * @throws IllegalArgumentException if any element in the input array
239+ * <tt>ids</tt> is <tt>&lt= 0</tt>.
240+ * @throws java.lang.SecurityException if a security manager
241+ * exists and the caller does not have
242+ * ManagementPermission("monitor").
243+ */
244+ public ThreadInfo[] getThreadInfo(long[] ids);
245+
246+ /**
247+ * Returns a thread info for a thread of the specified <tt>id</tt>,
248+ * with stack trace of a specified number of stack trace elements.
249+ * The <tt>maxDepth</tt> parameter indicates the maximum number of
250+ * {@link StackTraceElement} to be retrieved from the stack trace.
251+ * If <tt>maxDepth == Integer.MAX_VALUE</tt>, the entire stack trace of
252+ * the thread will be dumped.
253+ * If <tt>maxDepth == 0</tt>, no stack trace of the thread
254+ * will be dumped.
255+ * This method does not obtain the locked monitors and locked
256+ * synchronizers of the thread.
257+ * <p>
258+ * When the Java virtual machine has no stack trace information
259+ * about a thread or <tt>maxDepth == 0</tt>,
260+ * the stack trace in the
261+ * <tt>ThreadInfo</tt> object will be an empty array of
262+ * <tt>StackTraceElement</tt>.
263+ *
264+ * <p>
265+ * If a thread of the given ID is not alive or does not exist,
266+ * this method will return <tt>null</tt>. A thread is alive if
267+ * it has been started and has not yet died.
268+ *
269+ * <p>
270+ * <b>MBeanServer access</b>:<br>
271+ * The mapped type of <tt>ThreadInfo</tt> is
272+ * <tt>CompositeData</tt> with attributes as specified in the
273+ * {@link ThreadInfo#from ThreadInfo.from} method.
274+ *
275+ * @param id the thread ID of the thread. Must be positive.
276+ * @param maxDepth the maximum number of entries in the stack trace
277+ * to be dumped. <tt>Integer.MAX_VALUE</tt> could be used to request
278+ * the entire stack to be dumped.
279+ *
280+ * @return a {@link ThreadInfo} of the thread of the given ID
281+ * with no locked monitor and synchronizer info.
282+ * <tt>null</tt> if the thread of the given ID is not alive or
283+ * it does not exist.
284+ *
285+ * @throws IllegalArgumentException if <tt>id &lt= 0</tt>.
286+ * @throws IllegalArgumentException if <tt>maxDepth is negative</tt>.
287+ * @throws java.lang.SecurityException if a security manager
288+ * exists and the caller does not have
289+ * ManagementPermission("monitor").
290+ *
291+ */
292+ public ThreadInfo getThreadInfo(long id, int maxDepth);
293+
294+ /**
295+ * Returns the thread info for each thread
296+ * whose ID is in the input array <tt>ids</tt>,
297+ * with stack trace of a specified number of stack trace elements.
298+ * The <tt>maxDepth</tt> parameter indicates the maximum number of
299+ * {@link StackTraceElement} to be retrieved from the stack trace.
300+ * If <tt>maxDepth == Integer.MAX_VALUE</tt>, the entire stack trace of
301+ * the thread will be dumped.
302+ * If <tt>maxDepth == 0</tt>, no stack trace of the thread
303+ * will be dumped.
304+ * This method does not obtain the locked monitors and locked
305+ * synchronizers of the threads.
306+ * <p>
307+ * When the Java virtual machine has no stack trace information
308+ * about a thread or <tt>maxDepth == 0</tt>,
309+ * the stack trace in the
310+ * <tt>ThreadInfo</tt> object will be an empty array of
311+ * <tt>StackTraceElement</tt>.
312+ * <p>
313+ * This method returns an array of the <tt>ThreadInfo</tt> objects,
314+ * each is the thread information about the thread with the same index
315+ * as in the <tt>ids</tt> array.
316+ * If a thread of the given ID is not alive or does not exist,
317+ * <tt>null</tt> will be set in the corresponding element
318+ * in the returned array. A thread is alive if
319+ * it has been started and has not yet died.
320+ *
321+ * <p>
322+ * <b>MBeanServer access</b>:<br>
323+ * The mapped type of <tt>ThreadInfo</tt> is
324+ * <tt>CompositeData</tt> with attributes as specified in the
325+ * {@link ThreadInfo#from ThreadInfo.from} method.
326+ *
327+ * @param ids an array of thread IDs
328+ * @param maxDepth the maximum number of entries in the stack trace
329+ * to be dumped. <tt>Integer.MAX_VALUE</tt> could be used to request
330+ * the entire stack to be dumped.
331+ *
332+ * @return an array of the {@link ThreadInfo} objects, each containing
333+ * information about a thread whose ID is in the corresponding
334+ * element of the input array of IDs with no locked monitor and
335+ * synchronizer info.
336+ *
337+ * @throws IllegalArgumentException if <tt>maxDepth is negative</tt>.
338+ * @throws IllegalArgumentException if any element in the input array
339+ * <tt>ids</tt> is <tt>&lt= 0</tt>.
340+ * @throws java.lang.SecurityException if a security manager
341+ * exists and the caller does not have
342+ * ManagementPermission("monitor").
343+ *
344+ */
345+ public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);
346+
347+ /**
348+ * Tests if the Java virtual machine supports thread contention monitoring.
349+ *
350+ * @return
351+ * <tt>true</tt>
352+ * if the Java virtual machine supports thread contention monitoring;
353+ * <tt>false</tt> otherwise.
354+ */
355+ public boolean isThreadContentionMonitoringSupported();
356+
357+ /**
358+ * Tests if thread contention monitoring is enabled.
359+ *
360+ * @return <tt>true</tt> if thread contention monitoring is enabled;
361+ * <tt>false</tt> otherwise.
362+ *
363+ * @throws java.lang.UnsupportedOperationException if the Java virtual
364+ * machine does not support thread contention monitoring.
365+ *
366+ * @see #isThreadContentionMonitoringSupported
367+ */
368+ public boolean isThreadContentionMonitoringEnabled();
369+
370+ /**
371+ * Enables or disables thread contention monitoring.
372+ * Thread contention monitoring is disabled by default.
373+ *
374+ * @param enable <tt>true</tt> to enable;
375+ * <tt>false</tt> to disable.
376+ *
377+ * @throws java.lang.UnsupportedOperationException if the Java
378+ * virtual machine does not support thread contention monitoring.
379+ *
380+ * @throws java.lang.SecurityException if a security manager
381+ * exists and the caller does not have
382+ * ManagementPermission("control").
383+ *
384+ * @see #isThreadContentionMonitoringSupported
385+ */
386+ public void setThreadContentionMonitoringEnabled(boolean enable);
387+
388+ /**
389+ * Returns the total CPU time for the current thread in nanoseconds.
390+ * The returned value is of nanoseconds precision but
391+ * not necessarily nanoseconds accuracy.
392+ * If the implementation distinguishes between user mode time and system
393+ * mode time, the returned CPU time is the amount of time that
394+ * the current thread has executed in user mode or system mode.
395+ *
396+ * <p>
397+ * This is a convenient method for local management use and is
398+ * equivalent to calling:
399+ * <blockquote><pre>
400+ * {@link #getThreadCpuTime getThreadCpuTime}(Thread.currentThread().getId());
401+ * </pre></blockquote>
402+ *
403+ * @return the total CPU time for the current thread if CPU time
404+ * measurement is enabled; <tt>-1</tt> otherwise.
405+ *
406+ * @throws java.lang.UnsupportedOperationException if the Java
407+ * virtual machine does not support CPU time measurement for
408+ * the current thread.
409+ *
410+ * @see #getCurrentThreadUserTime
411+ * @see #isCurrentThreadCpuTimeSupported
412+ * @see #isThreadCpuTimeEnabled
413+ * @see #setThreadCpuTimeEnabled
414+ */
415+ public long getCurrentThreadCpuTime();
416+
417+ /**
418+ * Returns the CPU time that the current thread has executed
419+ * in user mode in nanoseconds.
420+ * The returned value is of nanoseconds precision but
421+ * not necessarily nanoseconds accuracy.
422+ *
423+ * <p>
424+ * This is a convenient method for local management use and is
425+ * equivalent to calling:
426+ * <blockquote><pre>
427+ * {@link #getThreadUserTime getThreadUserTime}(Thread.currentThread().getId());
428+ * </pre></blockquote>
429+ *
430+ * @return the user-level CPU time for the current thread if CPU time
431+ * measurement is enabled; <tt>-1</tt> otherwise.
432+ *
433+ * @throws java.lang.UnsupportedOperationException if the Java
434+ * virtual machine does not support CPU time measurement for
435+ * the current thread.
436+ *
437+ * @see #getCurrentThreadCpuTime
438+ * @see #isCurrentThreadCpuTimeSupported
439+ * @see #isThreadCpuTimeEnabled
440+ * @see #setThreadCpuTimeEnabled
441+ */
442+ public long getCurrentThreadUserTime();
443+
444+ /**
445+ * Returns the total CPU time for a thread of the specified ID in nanoseconds.
446+ * The returned value is of nanoseconds precision but
447+ * not necessarily nanoseconds accuracy.
448+ * If the implementation distinguishes between user mode time and system
449+ * mode time, the returned CPU time is the amount of time that
450+ * the thread has executed in user mode or system mode.
451+ *
452+ * <p>
453+ * If the thread of the specified ID is not alive or does not exist,
454+ * this method returns <tt>-1</tt>. If CPU time measurement
455+ * is disabled, this method returns <tt>-1</tt>.
456+ * A thread is alive if it has been started and has not yet died.
457+ * <p>
458+ * If CPU time measurement is enabled after the thread has started,
459+ * the Java virtual machine implementation may choose any time up to
460+ * and including the time that the capability is enabled as the point
461+ * where CPU time measurement starts.
462+ *
463+ * @param id the thread ID of a thread
464+ * @return the total CPU time for a thread of the specified ID
465+ * if the thread of the specified ID exists, the thread is alive,
466+ * and CPU time measurement is enabled;
467+ * <tt>-1</tt> otherwise.
468+ *
469+ * @throws IllegalArgumentException if <tt>id &lt= 0 </tt>.
470+ * @throws java.lang.UnsupportedOperationException if the Java
471+ * virtual machine does not support CPU time measurement for
472+ * other threads.
473+ *
474+ * @see #getThreadUserTime
475+ * @see #isThreadCpuTimeSupported
476+ * @see #isThreadCpuTimeEnabled
477+ * @see #setThreadCpuTimeEnabled
478+ */
479+ public long getThreadCpuTime(long id);
480+
481+ /**
482+ * Returns the CPU time that a thread of the specified ID
483+ * has executed in user mode in nanoseconds.
484+ * The returned value is of nanoseconds precision but
485+ * not necessarily nanoseconds accuracy.
486+ *
487+ * <p>
488+ * If the thread of the specified ID is not alive or does not exist,
489+ * this method returns <tt>-1</tt>. If CPU time measurement
490+ * is disabled, this method returns <tt>-1</tt>.
491+ * A thread is alive if it has been started and has not yet died.
492+ * <p>
493+ * If CPU time measurement is enabled after the thread has started,
494+ * the Java virtual machine implementation may choose any time up to
495+ * and including the time that the capability is enabled as the point
496+ * where CPU time measurement starts.
497+ *
498+ * @param id the thread ID of a thread
499+ * @return the user-level CPU time for a thread of the specified ID
500+ * if the thread of the specified ID exists, the thread is alive,
501+ * and CPU time measurement is enabled;
502+ * <tt>-1</tt> otherwise.
503+ *
504+ * @throws IllegalArgumentException if <tt>id &lt= 0 </tt>.
505+ * @throws java.lang.UnsupportedOperationException if the Java
506+ * virtual machine does not support CPU time measurement for
507+ * other threads.
508+ *
509+ * @see #getThreadCpuTime
510+ * @see #isThreadCpuTimeSupported
511+ * @see #isThreadCpuTimeEnabled
512+ * @see #setThreadCpuTimeEnabled
513+ */
514+ public long getThreadUserTime(long id);
515+
516+ /**
517+ * Tests if the Java virtual machine implementation supports CPU time
518+ * measurement for any thread.
519+ * A Java virtual machine implementation that supports CPU time
520+ * measurement for any thread will also support CPU time
521+ * measurement for the current thread.
522+ *
523+ * @return
524+ * <tt>true</tt>
525+ * if the Java virtual machine supports CPU time
526+ * measurement for any thread;
527+ * <tt>false</tt> otherwise.
528+ */
529+ public boolean isThreadCpuTimeSupported();
530+
531+ /**
532+ * Tests if the Java virtual machine supports CPU time
533+ * measurement for the current thread.
534+ * This method returns <tt>true</tt> if {@link #isThreadCpuTimeSupported}
535+ * returns <tt>true</tt>.
536+ *
537+ * @return
538+ * <tt>true</tt>
539+ * if the Java virtual machine supports CPU time
540+ * measurement for current thread;
541+ * <tt>false</tt> otherwise.
542+ */
543+ public boolean isCurrentThreadCpuTimeSupported();
544+
545+ /**
546+ * Tests if thread CPU time measurement is enabled.
547+ *
548+ * @return <tt>true</tt> if thread CPU time measurement is enabled;
549+ * <tt>false</tt> otherwise.
550+ *
551+ * @throws java.lang.UnsupportedOperationException if the Java virtual
552+ * machine does not support CPU time measurement for other threads
553+ * nor for the current thread.
554+ *
555+ * @see #isThreadCpuTimeSupported
556+ * @see #isCurrentThreadCpuTimeSupported
557+ */
558+ public boolean isThreadCpuTimeEnabled();
559+
560+ /**
561+ * Enables or disables thread CPU time measurement. The default
562+ * is platform dependent.
563+ *
564+ * @param enable <tt>true</tt> to enable;
565+ * <tt>false</tt> to disable.
566+ *
567+ * @throws java.lang.UnsupportedOperationException if the Java
568+ * virtual machine does not support CPU time measurement for
569+ * any threads nor for the current thread.
570+ *
571+ * @throws java.lang.SecurityException if a security manager
572+ * exists and the caller does not have
573+ * ManagementPermission("control").
574+ *
575+ * @see #isThreadCpuTimeSupported
576+ * @see #isCurrentThreadCpuTimeSupported
577+ */
578+ public void setThreadCpuTimeEnabled(boolean enable);
579+
580+ /**
581+ * Finds cycles of threads that are in deadlock waiting to acquire
582+ * object monitors. That is, threads that are blocked waiting to enter a
583+ * synchronization block or waiting to reenter a synchronization block
584+ * after an {@link Object#wait Object.wait} call,
585+ * where each thread owns one monitor while
586+ * trying to obtain another monitor already held by another thread
587+ * in a cycle.
588+ * <p>
589+ * More formally, a thread is <em>monitor deadlocked</em> if it is
590+ * part of a cycle in the relation "is waiting for an object monitor
591+ * owned by". In the simplest case, thread A is blocked waiting
592+ * for a monitor owned by thread B, and thread B is blocked waiting
593+ * for a monitor owned by thread A.
594+ * <p>
595+ * This method is designed for troubleshooting use, but not for
596+ * synchronization control. It might be an expensive operation.
597+ * <p>
598+ * This method finds deadlocks involving only object monitors.
599+ * To find deadlocks involving both object monitors and
600+ * <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>,
601+ * the {@link #findDeadlockedThreads findDeadlockedThreads} method
602+ * should be used.
603+ *
604+ * @return an array of IDs of the threads that are monitor
605+ * deadlocked, if any; <tt>null</tt> otherwise.
606+ *
607+ * @throws java.lang.SecurityException if a security manager
608+ * exists and the caller does not have
609+ * ManagementPermission("monitor").
610+ *
611+ * @see #findDeadlockedThreads
612+ */
613+ public long[] findMonitorDeadlockedThreads();
614+
615+ /**
616+ * Resets the peak thread count to the current number of
617+ * live threads.
618+ *
619+ * @throws java.lang.SecurityException if a security manager
620+ * exists and the caller does not have
621+ * ManagementPermission("control").
622+ *
623+ * @see #getPeakThreadCount
624+ * @see #getThreadCount
625+ */
626+ public void resetPeakThreadCount();
627+
628+ /**
629+ * Finds cycles of threads that are in deadlock waiting to acquire
630+ * object monitors or
631+ * <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>.
632+ *
633+ * Threads are <em>deadlocked</em> in a cycle waiting for a lock of
634+ * these two types if each thread owns one lock while
635+ * trying to acquire another lock already held
636+ * by another thread in the cycle.
637+ * <p>
638+ * This method is designed for troubleshooting use, but not for
639+ * synchronization control. It might be an expensive operation.
640+ *
641+ * @return an array of IDs of the threads that are
642+ * deadlocked waiting for object monitors or ownable synchronizers, if any;
643+ * <tt>null</tt> otherwise.
644+ *
645+ * @throws java.lang.SecurityException if a security manager
646+ * exists and the caller does not have
647+ * ManagementPermission("monitor").
648+ * @throws java.lang.UnsupportedOperationException if the Java virtual
649+ * machine does not support monitoriing of ownable synchronizer usage.
650+ *
651+ * @see #isSynchronizerUsageSupported
652+ * @see #findMonitorDeadlockedThreads
653+ * @since 1.6
654+ */
655+ public long[] findDeadlockedThreads();
656+
657+ /**
658+ * Tests if the Java virtual machine supports monitoring of
659+ * object monitor usage.
660+ *
661+ * @return
662+ * <tt>true</tt>
663+ * if the Java virtual machine supports monitoring of
664+ * object monitor usage;
665+ * <tt>false</tt> otherwise.
666+ *
667+ * @see #dumpAllThreads
668+ * @since 1.6
669+ */
670+ public boolean isObjectMonitorUsageSupported();
671+
672+ /**
673+ * Tests if the Java virtual machine supports monitoring of
674+ * <a href="LockInfo.html#OwnableSynchronizer">
675+ * ownable synchronizer</a> usage.
676+ *
677+ * @return
678+ * <tt>true</tt>
679+ * if the Java virtual machine supports monitoring of ownable
680+ * synchronizer usage;
681+ * <tt>false</tt> otherwise.
682+ *
683+ * @see #dumpAllThreads
684+ * @since 1.6
685+ */
686+ public boolean isSynchronizerUsageSupported();
687+
688+ /**
689+ * Returns the thread info for each thread
690+ * whose ID is in the input array <tt>ids</tt>, with stack trace
691+ * and synchronization information.
692+ *
693+ * <p>
694+ * This method obtains a snapshot of the thread information
695+ * for each thread including:
696+ * <ul>
697+ * <li>the entire stack trace,</li>
698+ * <li>the object monitors currently locked by the thread
699+ * if <tt>lockedMonitors</tt> is <tt>true</tt>, and</li>
700+ * <li>the <a href="LockInfo.html#OwnableSynchronizer">
701+ * ownable synchronizers</a> currently locked by the thread
702+ * if <tt>lockedSynchronizers</tt> is <tt>true</tt>.</li>
703+ * </ul>
704+ * <p>
705+ * This method returns an array of the <tt>ThreadInfo</tt> objects,
706+ * each is the thread information about the thread with the same index
707+ * as in the <tt>ids</tt> array.
708+ * If a thread of the given ID is not alive or does not exist,
709+ * <tt>null</tt> will be set in the corresponding element
710+ * in the returned array. A thread is alive if
711+ * it has been started and has not yet died.
712+ * <p>
713+ * If a thread does not lock any object monitor or <tt>lockedMonitors</tt>
714+ * is <tt>false</tt>, the returned <tt>ThreadInfo</tt> object will have an
715+ * empty <tt>MonitorInfo</tt> array. Similarly, if a thread does not
716+ * lock any synchronizer or <tt>lockedSynchronizers</tt> is <tt>false</tt>,
717+ * the returned <tt>ThreadInfo</tt> object
718+ * will have an empty <tt>LockInfo</tt> array.
719+ *
720+ * <p>
721+ * When both <tt>lockedMonitors</tt> and <tt>lockedSynchronizers</tt>
722+ * parameters are <tt>false</tt>, it is equivalent to calling:
723+ * <blockquote><pre>
724+ * {@link #getThreadInfo(long[], int) getThreadInfo(ids, Integer.MAX_VALUE)}
725+ * </pre></blockquote>
726+ *
727+ * <p>
728+ * This method is designed for troubleshooting use, but not for
729+ * synchronization control. It might be an expensive operation.
730+ *
731+ * <p>
732+ * <b>MBeanServer access</b>:<br>
733+ * The mapped type of <tt>ThreadInfo</tt> is
734+ * <tt>CompositeData</tt> with attributes as specified in the
735+ * {@link ThreadInfo#from ThreadInfo.from} method.
736+ *
737+ * @param ids an array of thread IDs.
738+ * @param lockedMonitors if <tt>true</tt>, retrieves all locked monitors.
739+ * @param lockedSynchronizers if <tt>true</tt>, retrieves all locked
740+ * ownable synchronizers.
741+ *
742+ * @return an array of the {@link ThreadInfo} objects, each containing
743+ * information about a thread whose ID is in the corresponding
744+ * element of the input array of IDs.
745+ *
746+ * @throws java.lang.SecurityException if a security manager
747+ * exists and the caller does not have
748+ * ManagementPermission("monitor").
749+ * @throws java.lang.UnsupportedOperationException
750+ * <ul>
751+ * <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
752+ * the Java virtual machine does not support monitoring
753+ * of {@linkplain #isObjectMonitorUsageSupported
754+ * object monitor usage}; or</li>
755+ * <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
756+ * the Java virtual machine does not support monitoring
757+ * of {@linkplain #isSynchronizerUsageSupported
758+ * ownable synchronizer usage}.</li>
759+ * </ul>
760+ *
761+ * @see #isObjectMonitorUsageSupported
762+ * @see #isSynchronizerUsageSupported
763+ *
764+ * @since 1.6
765+ */
766+ public ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors, boolean lockedSynchronizers);
767+
768+ /**
769+ * Returns the thread info for all live threads with stack trace
770+ * and synchronization information.
771+ * Some threads included in the returned array
772+ * may have been terminated when this method returns.
773+ *
774+ * <p>
775+ * This method returns an array of {@link ThreadInfo} objects
776+ * as specified in the {@link #getThreadInfo(long[], boolean, boolean)}
777+ * method.
778+ *
779+ * @param lockedMonitors if <tt>true</tt>, dump all locked monitors.
780+ * @param lockedSynchronizers if <tt>true</tt>, dump all locked
781+ * ownable synchronizers.
782+ *
783+ * @return an array of {@link ThreadInfo} for all live threads.
784+ *
785+ * @throws java.lang.SecurityException if a security manager
786+ * exists and the caller does not have
787+ * ManagementPermission("monitor").
788+ * @throws java.lang.UnsupportedOperationException
789+ * <ul>
790+ * <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
791+ * the Java virtual machine does not support monitoring
792+ * of {@linkplain #isObjectMonitorUsageSupported
793+ * object monitor usage}; or</li>
794+ * <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
795+ * the Java virtual machine does not support monitoring
796+ * of {@linkplain #isSynchronizerUsageSupported
797+ * ownable synchronizer usage}.</li>
798+ * </ul>
799+ *
800+ * @see #isObjectMonitorUsageSupported
801+ * @see #isSynchronizerUsageSupported
802+ *
803+ * @since 1.6
804+ */
805+ public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers);
806+}
java/pkg/java/lang/management/mkfile+28−0
@@ -0,0 +1,28 @@
1+<../../../../../mkconfig
2+
3+TARG=\
4+ BufferPoolMXBean.dis\
5+ ClassLoadingMXBean.dis\
6+ CompilationMXBean.dis\
7+ GarbageCollectorMXBean.dis\
8+ LockInfo.dis\
9+ ManagementFactory.dis\
10+ ManagementPermission.dis\
11+ MemoryManagerMXBean.dis\
12+ MemoryMXBean.dis\
13+ MemoryNotificationInfo.dis\
14+ MemoryPoolMXBean.dis\
15+ MemoryType.dis\
16+ MemoryUsage.dis\
17+ MonitorInfo.dis\
18+ OperatingSystemMXBean.dis\
19+ PlatformComponent.dis\
20+ PlatformLoggingMXBean.dis\
21+ PlatformManagedObject.dis\
22+ RuntimeMXBean.dis\
23+ ThreadInfo.dis\
24+ ThreadMXBean.dis\
25+
26+DISBIN=$ROOT/java/dis/java/java/java/lang/management
27+
28+<$ROOT/mkfiles/mkjava
java/pkg/java/lang/management/package.html+248−0
@@ -0,0 +1,248 @@
1+<!--
2+ Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
3+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
5+ This code is free software; you can redistribute it and/or modify it
6+ under the terms of the GNU General Public License version 2 only, as
7+ published by the Free Software Foundation. Oracle designates this
8+ particular file as subject to the "Classpath" exception as provided
9+ by Oracle in the LICENSE file that accompanied this code.
10+
11+ This code is distributed in the hope that it will be useful, but WITHOUT
12+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ version 2 for more details (a copy is included in the LICENSE file that
15+ accompanied this code).
16+
17+ You should have received a copy of the GNU General Public License version
18+ 2 along with this work; if not, write to the Free Software Foundation,
19+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
21+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ or visit www.oracle.com if you need additional information or have any
23+ questions.
24+-->
25+
26+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
27+<html>
28+<body bgcolor="white">
29+
30+Provides the management interfaces for monitoring and management of the
31+Java virtual machine and other components in the Java runtime.
32+It allows both local and remote
33+monitoring and management of the running Java virtual machine.
34+<p>
35+
36+<h4><a name="MXBean">Platform MXBean</a></h4>
37+<p>
38+A platform MXBean is a <i>managed bean</i> that
39+conforms to the <a href="../../../javax/management/package-summary.html">JMX</a>
40+Instrumentation Specification and only uses a set of basic data types.
41+Each platform MXBean is a {@link java.lang.management.PlatformManagedObject}
42+with a unique
43+{@linkplain java.lang.management.PlatformManagedObject#getObjectName name}.
44+<p>
45+<h4>ManagementFactory</h4>
46+
47+<p>The {@link java.lang.management.ManagementFactory} class is the management
48+factory class for the Java platform. This class provides a set of
49+static factory methods to obtain the MXBeans for the Java platform
50+to allow an application to access the MXBeans directly.
51+
52+<p>A <em>platform MBeanServer</em> can be accessed with the
53+{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
54+ getPlatformMBeanServer} method. On the first call to this method,
55+it creates the platform MBeanServer and registers all platform MXBeans
56+including {@linkplain java.lang.management.PlatformManagedObject
57+platform MXBeans}.
58+Each platform MXBean is registered with a unique name defined in
59+the specification of the management interface.
60+This is a single MBeanServer that can be shared by different managed
61+components running within the same Java virtual machine.
62+
63+<h4>Interoperability</h4>
64+
65+<p>A management application and a platform MBeanServer of a running
66+virtual machine can interoperate
67+without requiring classes used by the platform MXBean interfaces.
68+The data types being transmitted between the JMX connector
69+server and the connector client are JMX
70+{@linkplain javax.management.openmbean.OpenType open types} and
71+this allows interoperation across versions.
72+A data type used by the MXBean interfaces are mapped to an
73+open type when being accessed via MBeanServer interface.
74+See the <a href="../../../javax/management/MXBean.html#MXBean-spec">
75+MXBean</a> specification for details.
76+
77+<h4><a name="examples">Ways to Access MXBeans</a></h4>
78+
79+<p>An application can monitor the instrumentation of the
80+Java virtual machine and the runtime in the following ways:
81+<p>
82+<b>1. Direct access to an MXBean interface</b>
83+<p>
84+<ul>
85+<li>Get an MXBean instance locally in the running Java virtual machine:<p>
86+<pre>
87+ RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
88+
89+ // Get the standard attribute "VmVendor"
90+ String vendor = mxbean.getVmVendor();
91+</pre>
92+<p>Or by calling the
93+ {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
94+ getPlatformMXBean} or
95+ {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
96+ getPlatformMXBeans} method:
97+<pre>
98+ RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);
99+
100+ // Get the standard attribute "VmVendor"
101+ String vendor = mxbean.getVmVendor();
102+</pre>
103+<p>
104+</li>
105+<li>Construct an MXBean proxy instance that forwards the
106+ method calls to a given MBeanServer:<p>
107+<pre>
108+ MBeanServerConnection mbs;
109+
110+ // Connect to a running JVM (or itself) and get MBeanServerConnection
111+ // that has the JVM MBeans registered in it
112+ ...
113+
114+ // Get a MBean proxy for RuntimeMXBean interface
115+ RuntimeMXBean proxy =
116+ {@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class)
117+ ManagementFactory.getPlatformMXBean}(mbs,
118+ RuntimeMXBean.class);
119+ // Get standard attribute "VmVendor"
120+ String vendor = proxy.getVmVendor();
121+</pre>
122+<p>A proxy is typically used to access an MXBean
123+ in a remote Java virtual machine.
124+ An alternative way to create an MXBean proxy is:
125+<pre>
126+ RuntimeMXBean proxy =
127+ {@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
128+ ManagementFactory.newPlatformMXBeanProxy}(mbs,
129+ ManagementFactory.RUNTIME_MXBEAN_NAME,
130+ RuntimeMXBean.class);
131+</pre>
132+</li>
133+</ul>
134+<p>
135+<b>2. Indirect access to an MXBean interface via MBeanServer</b><p>
136+<ul>
137+<li>Go through the
138+ {@link java.lang.management.ManagementFactory#getPlatformMBeanServer
139+ platform MBeanServer} to access MXBeans locally or
140+ a specific {@code MBeanServerConnection} to access
141+ MXBeans remotely.
142+ The attributes and operations of an MXBean use only
143+ <em>JMX open types</em> which include basic data types,
144+ {@link javax.management.openmbean.CompositeData CompositeData},
145+ and {@link javax.management.openmbean.TabularData TabularData}
146+ defined in {@link javax.management.openmbean.OpenType OpenType}.<p>
147+<pre>
148+ MBeanServerConnection mbs;
149+
150+ // Connect to a running JVM (or itself) and get MBeanServerConnection
151+ // that has the JVM MXBeans registered in it
152+ ...
153+
154+ try {
155+ // Assuming the RuntimeMXBean has been registered in mbs
156+ ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
157+
158+ // Get standard attribute "VmVendor"
159+ String vendor = (String) mbs.getAttribute(oname, "VmVendor");
160+ } catch (....) {
161+ // Catch the exceptions thrown by ObjectName constructor
162+ // and MBeanServer.getAttribute method
163+ ...
164+ }
165+</pre>
166+</li>
167+</ul>
168+
169+
170+<h4><a name="extension">Platform Extension</a></h4>
171+
172+<p>A Java virtual machine implementation may add its platform extension to
173+the management interface by defining platform-dependent
174+interfaces that extend the standard management interfaces to include
175+platform-specific metrics and management operations.
176+The static factory methods in the <tt>ManagementFactory</tt> class will
177+return the MXBeans with the platform extension.
178+
179+<p>
180+It is recommended to name the platform-specific attributes with
181+a vendor-specific prefix such as the vendor's name to
182+avoid collisions of the attribute name between the future extension
183+to the standard management interface and the platform extension.
184+If the future extension to the standard management interface defines
185+a new attribute for a management interface and the attribute name
186+is happened to be same as some vendor-specific attribute's name,
187+the applications accessing that vendor-specific attribute would have
188+to be modified to cope with versioning and compatibility issues.
189+
190+<p>Below is an example showing how to access an attribute
191+from the platform extension:
192+
193+<p>
194+1) Direct access to the Oracle-specific MXBean interface
195+<blockquote>
196+<pre>
197+ List&lt;com.sun.management.GarbageCollectorMXBean&gt; mxbeans =
198+ ManagementFactory.getPlatformMXBeans(com.sun.management.GarbageCollectorMXBean.class);
199+
200+ for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
201+ // Get the standard attribute "CollectionCount"
202+ String count = mxbean.getCollectionCount();
203+
204+ // Get the platform-specific attribute "LastGcInfo"
205+ GcInfo gcinfo = gc.getLastGcInfo();
206+ ...
207+ }
208+</pre>
209+</blockquote>
210+
211+<p>
212+2) Access the Oracle-specific MXBean interface via <tt>MBeanServer</tt>
213+ through proxy
214+
215+<blockquote><pre>
216+ MBeanServerConnection mbs;
217+
218+ // Connect to a running JVM (or itself) and get MBeanServerConnection
219+ // that has the JVM MXBeans registered in it
220+ ...
221+
222+ List&lt;com.sun.management.GarbageCollectorMXBean&gt; mxbeans =
223+ ManagementFactory.getPlatformMXBeans(mbs, com.sun.management.GarbageCollectorMXBean.class);
224+
225+ for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
226+ // Get the standard attribute "CollectionCount"
227+ String count = mxbean.getCollectionCount();
228+
229+ // Get the platform-specific attribute "LastGcInfo"
230+ GcInfo gcinfo = gc.getLastGcInfo();
231+ ...
232+ }
233+</pre></blockquote>
234+
235+<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
236+or method in any class or interface in this package will cause a {@link
237+java.lang.NullPointerException NullPointerException} to be thrown.
238+
239+<p> The java.lang.management API is thread-safe.
240+
241+@see <a href="../../../javax/management/package-summary.html">
242+ JMX Specification.</a>
243+
244+@author Mandy Chung
245+@since 1.5
246+
247+</body>
248+</html>

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t