jdk/src/share/classes/java/lang/management/MemoryUsage.java
author jfranck
Mon, 30 Sep 2013 11:18:18 +0200
changeset 20481 2735b307d256
parent 18799 31062cb3cc8e
child 21334 c60dfce46a77
permissions -rw-r--r--
8007072: Update Core Reflection for Type Annotations to match latest spec 8022324: j.l.Class.getAnnotatedInterfaces() for array type returns wrong value 8024915: j.l.r.Executable.getAnnotatedReceiverType() should return null for static methods Summary: Update javadoc and implementation of reflection for type annotations to match latest spec Reviewed-by: darcy
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: 18156
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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
import sun.management.MemoryUsageCompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A <tt>MemoryUsage</tt> object represents a snapshot of memory usage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Instances of the <tt>MemoryUsage</tt> class are usually constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * by methods that are used to obtain memory usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * information about individual memory pool of the Java virtual machine or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the heap or non-heap memory of the Java virtual machine as a whole.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p> A <tt>MemoryUsage</tt> object contains four values:
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 18156
diff changeset
    39
 * <table summary="Describes the MemoryUsage object content">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <td valign=top> <tt>init</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <td valign=top> represents the initial amount of memory (in bytes) that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      the Java virtual machine requests from the operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      for memory management during startup.  The Java virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      may request additional memory from the operating system and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      may also release memory to the system over time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      The value of <tt>init</tt> may be undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <td valign=top> <tt>used</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <td valign=top> represents the amount of memory currently used (in bytes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <td valign=top> <tt>committed</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <td valign=top> represents the amount of memory (in bytes) that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      guaranteed to be available for use by the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      The amount of committed memory may change over time (increase
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      or decrease).  The Java virtual machine may release memory to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      the system and <tt>committed</tt> could be less than <tt>init</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      <tt>committed</tt> will always be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      or equal to <tt>used</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <td valign=top> <tt>max</tt> </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <td valign=top> represents the maximum amount of memory (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *      that can be used for memory management. Its value may be undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *      The maximum amount of memory may change over time if defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *      The amount of used and committed memory will always be less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *      or equal to <tt>max</tt> if <tt>max</tt> is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *      A memory allocation may fail if it attempts to increase the
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
    74
 *      used memory such that <tt>used &gt; committed</tt> even
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
    75
 *      if <tt>used &lt;= max</tt> would still be true (for example,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *      when the system is low on virtual memory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Below is a picture showing an example of a memory pool:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *        +----------------------------------------------+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *        +////////////////           |                  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *        +////////////////           |                  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *        +----------------------------------------------+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *        |--------|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *           init
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *        |---------------|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *               used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *        |---------------------------|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *                  committed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *        |----------------------------------------------|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *                            max
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 18156
diff changeset
    99
 * <h3>MXBean Mapping</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <tt>MemoryUsage</tt> is mapped to a {@link CompositeData CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * with attributes as specified in the {@link #from from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @author   Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
public class MemoryUsage {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private final long init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private final long used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private final long committed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private final long max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Constructs a <tt>MemoryUsage</tt> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param init      the initial amount of memory in bytes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *                  the Java virtual machine allocates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *                  or <tt>-1</tt> if undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param used      the amount of used memory in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param committed the amount of committed memory in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param max       the maximum amount of memory in bytes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *                  can be used; or <tt>-1</tt> if undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <li> the value of <tt>init</tt> or <tt>max</tt> is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *      but not <tt>-1</tt>; or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <li> the value of <tt>used</tt> or <tt>committed</tt> is negative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *      or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <li> <tt>used</tt> is greater than the value of <tt>committed</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *      or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <li> <tt>committed</tt> is greater than the value of <tt>max</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *      <tt>max</tt> if defined.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public MemoryUsage(long init,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                       long used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                       long committed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                       long max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (init < -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException( "init parameter = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                init + " is negative but not -1.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (max < -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throw new IllegalArgumentException( "max parameter = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                max + " is negative but not -1.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (used < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new IllegalArgumentException( "used parameter = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                used + " is negative.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (committed < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new IllegalArgumentException( "committed parameter = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                committed + " is negative.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (used > committed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new IllegalArgumentException( "used = " + used +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                " should be <= committed = " + committed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (max >= 0 && committed > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new IllegalArgumentException( "committed = " + committed +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                " should be < max = " + max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this.init = init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.used = used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.committed = committed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        this.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Constructs a <tt>MemoryUsage</tt> object from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * {@link CompositeData CompositeData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private MemoryUsage(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // validate the input composite data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        MemoryUsageCompositeData.validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this.init = MemoryUsageCompositeData.getInit(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.used = MemoryUsageCompositeData.getUsed(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.committed = MemoryUsageCompositeData.getCommitted(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        this.max = MemoryUsageCompositeData.getMax(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns the amount of memory in bytes that the Java virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * initially requests from the operating system for memory management.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * This method returns <tt>-1</tt> if the initial memory size is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the initial size of memory in bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <tt>-1</tt> if undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public long getInit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Returns the amount of used memory in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the amount of used memory in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public long getUsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns the amount of memory in bytes that is committed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * the Java virtual machine to use.  This amount of memory is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * guaranteed for the Java virtual machine to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the amount of committed memory in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public long getCommitted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return committed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the maximum amount of memory in bytes that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * used for memory management.  This method returns <tt>-1</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * if the maximum memory size is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <p> This amount of memory is not guaranteed to be available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * for memory management if it is greater than the amount of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * committed memory.  The Java virtual machine may fail to allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * memory even if the amount of used memory does not exceed this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * maximum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the maximum amount of memory in bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <tt>-1</tt> if undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public long getMax() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Returns a descriptive representation of this memory usage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        buf.append("init = " + init + "(" + (init >> 10) + "K) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        buf.append("used = " + used + "(" + (used >> 10) + "K) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        buf.append("committed = " + committed + "(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                   (committed >> 10) + "K) " );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        buf.append("max = " + max + "(" + (max >> 10) + "K)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns a <tt>MemoryUsage</tt> object represented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * given <tt>CompositeData</tt>. The given <tt>CompositeData</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * must contain the following attributes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <blockquote>
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 18156
diff changeset
   255
     * <table border summary="The attributes and the types the given CompositeData contains">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *   <th align=left>Attribute Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *   <th align=left>Type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *   <td>init</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *   <td>used</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *   <td>committed</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *   <td>max</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param cd <tt>CompositeData</tt> representing a <tt>MemoryUsage</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws IllegalArgumentException if <tt>cd</tt> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *   represent a <tt>MemoryUsage</tt> with the attributes described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *   above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @return a <tt>MemoryUsage</tt> object represented by <tt>cd</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *         if <tt>cd</tt> is not <tt>null</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *         <tt>null</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public static MemoryUsage from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (cd instanceof MemoryUsageCompositeData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return ((MemoryUsageCompositeData) cd).getMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return new MemoryUsage(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
}