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