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