jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java
author mchung
Tue, 17 Jan 2012 15:55:40 -0800
changeset 11530 a9d059c15b80
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7117570: Warnings in sun.mangement.* and its subpackages Reviewed-by: mchung, dsamersoff Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2006, 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
package sun.management.snmp.jvminstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.snmp.SnmpDefinitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.management.MemoryUsage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.management.MemoryType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.management.MemoryMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.management.snmp.jvmmib.JvmMemoryMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.management.snmp.jvmmib.EnumJvmMemoryGCCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.management.snmp.jvmmib.EnumJvmMemoryGCVerboseLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.management.snmp.util.MibLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.management.snmp.util.JvmContextFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The class is used for implementing the "JvmMemory" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class JvmMemoryImpl implements JvmMemoryMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Variable for storing the value of "JvmMemoryGCCall".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * "This object makes it possible to remotelly trigger the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Garbage Collector in the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * This object's syntax is an enumeration which defines:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * * Two state values, that can be returned from a GET request:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * unsupported(1): means that remote invocation of gc() is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * supported by the SNMP agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * supported(2)  : means that remote invocation of gc() is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * by the SNMP agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * * One action value, that can be provided in a SET request to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * trigger the garbage collector:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * start(3)      : means that a manager wishes to trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * garbage collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * * Two result value, that will be returned as a result of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * SET request when remote invocation of gc is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * by the SNMP agent:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * started(4)       : means that garbage collection was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * successfully triggered. It does not mean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * however that the action was successfullly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * completed: gc might still be running when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * this value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * failed(5)     : means that garbage collection couldn't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * * If remote invocation is not supported by the SNMP agent, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * unsupported(1) will always be returned as a result of either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * a GET request, or a SET request with start(3) as input value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * * If a SET request with anything but start(3) is received, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the agent will return a wrongValue error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * See java.management.MemoryMXBean.gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    final static EnumJvmMemoryGCCall JvmMemoryGCCallSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        = new EnumJvmMemoryGCCall("supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    final static EnumJvmMemoryGCCall JvmMemoryGCCallStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        = new EnumJvmMemoryGCCall("start");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    final static EnumJvmMemoryGCCall JvmMemoryGCCallFailed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        = new EnumJvmMemoryGCCall("failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    final static EnumJvmMemoryGCCall JvmMemoryGCCallStarted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        = new EnumJvmMemoryGCCall("started");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Variable for storing the value of "JvmMemoryGCVerboseLevel".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * "State of the -verbose:gc state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * verbose: if the -verbose:gc flag is on,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * silent:  otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * See java.management.MemoryMXBean.isVerbose(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * java.management.MemoryMXBean.setVerbose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    final static EnumJvmMemoryGCVerboseLevel JvmMemoryGCVerboseLevelVerbose =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        new EnumJvmMemoryGCVerboseLevel("verbose");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    final static EnumJvmMemoryGCVerboseLevel JvmMemoryGCVerboseLevelSilent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        new EnumJvmMemoryGCVerboseLevel("silent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Constructor for the "JvmMemory" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * If the group contains a table, the entries created through an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * SNMP SET will not be registered in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public JvmMemoryImpl(SnmpMib myMib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Constructor for the "JvmMemory" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * If the group contains a table, the entries created through an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * SNMP SET will be AUTOMATICALLY REGISTERED in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public JvmMemoryImpl(SnmpMib myMib, MBeanServer server) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // no entry will be registered since the table is virtual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    final static String heapMemoryTag = "jvmMemory.getHeapMemoryUsage";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    final static String nonHeapMemoryTag = "jvmMemory.getNonHeapMemoryUsage";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private MemoryUsage getMemoryUsage(MemoryType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (type == MemoryType.HEAP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    MemoryUsage getNonHeapMemoryUsage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                final MemoryUsage cached = (MemoryUsage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    m.get(nonHeapMemoryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (cached != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    log.debug("getNonHeapMemoryUsage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                          "jvmMemory.getNonHeapMemoryUsage found in cache.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                final MemoryUsage u = getMemoryUsage(MemoryType.NON_HEAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                //  getNonHeapMemoryUsage() never returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                // if (u == null) u=MemoryUsage.INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                m.put(nonHeapMemoryTag,u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            // Should never come here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            // Log error!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            log.trace("getNonHeapMemoryUsage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                      "ERROR: should never come here!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return getMemoryUsage(MemoryType.NON_HEAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            log.trace("getNonHeapMemoryUsage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                  "Failed to get NonHeapMemoryUsage: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            log.debug("getNonHeapMemoryUsage",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    MemoryUsage getHeapMemoryUsage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                final MemoryUsage cached = (MemoryUsage)m.get(heapMemoryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (cached != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    log.debug("getHeapMemoryUsage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                          "jvmMemory.getHeapMemoryUsage found in cache.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                final MemoryUsage u = getMemoryUsage(MemoryType.HEAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                // getHeapMemoryUsage() never returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                // if (u == null) u=MemoryUsage.INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                m.put(heapMemoryTag,u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            // Should never come here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            // Log error!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            log.trace("getHeapMemoryUsage", "ERROR: should never come here!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return getMemoryUsage(MemoryType.HEAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            log.trace("getHeapMemoryUsage",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                  "Failed to get HeapMemoryUsage: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            log.debug("getHeapMemoryUsage",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static final Long Long0 = new Long(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Getter for the "JvmMemoryNonHeapMaxSize" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Long getJvmMemoryNonHeapMaxSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        final long val = getNonHeapMemoryUsage().getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (val > -1) return  new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Getter for the "JvmMemoryNonHeapCommitted" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public Long getJvmMemoryNonHeapCommitted() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        final long val = getNonHeapMemoryUsage().getCommitted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Getter for the "JvmMemoryNonHeapUsed" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public Long getJvmMemoryNonHeapUsed() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        final long val = getNonHeapMemoryUsage().getUsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Getter for the "JvmMemoryNonHeapInitSize" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public Long getJvmMemoryNonHeapInitSize() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        final long val = getNonHeapMemoryUsage().getInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Getter for the "JvmMemoryHeapMaxSize" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public Long getJvmMemoryHeapMaxSize() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        final long val = getHeapMemoryUsage().getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        else return Long0;
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
     * Getter for the "JvmMemoryGCCall" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public EnumJvmMemoryGCCall getJvmMemoryGCCall()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        throws SnmpStatusException {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   278
        final Map<Object,Object> m = JvmContextFactory.getUserData();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            final EnumJvmMemoryGCCall cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                = (EnumJvmMemoryGCCall) m.get("jvmMemory.getJvmMemoryGCCall");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (cached != null) return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return JvmMemoryGCCallSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Setter for the "JvmMemoryGCCall" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void setJvmMemoryGCCall(EnumJvmMemoryGCCall x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (x.intValue() == JvmMemoryGCCallStart.intValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                ManagementFactory.getMemoryMXBean().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                if (m != null) m.put("jvmMemory.getJvmMemoryGCCall",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                     JvmMemoryGCCallStarted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                if (m != null) m.put("jvmMemory.getJvmMemoryGCCall",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                     JvmMemoryGCCallFailed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Checker for the "JvmMemoryGCCall" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void checkJvmMemoryGCCall(EnumJvmMemoryGCCall x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (x.intValue() != JvmMemoryGCCallStart.intValue())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Getter for the "JvmMemoryHeapCommitted" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public Long getJvmMemoryHeapCommitted() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        final long val = getHeapMemoryUsage().getCommitted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Getter for the "JvmMemoryGCVerboseLevel" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public EnumJvmMemoryGCVerboseLevel getJvmMemoryGCVerboseLevel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (ManagementFactory.getMemoryMXBean().isVerbose())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return JvmMemoryGCVerboseLevelVerbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return JvmMemoryGCVerboseLevelSilent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Setter for the "JvmMemoryGCVerboseLevel" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public void setJvmMemoryGCVerboseLevel(EnumJvmMemoryGCVerboseLevel x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (JvmMemoryGCVerboseLevelVerbose.intValue() == x.intValue())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            ManagementFactory.getMemoryMXBean().setVerbose(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            ManagementFactory.getMemoryMXBean().setVerbose(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Checker for the "JvmMemoryGCVerboseLevel" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public void checkJvmMemoryGCVerboseLevel(EnumJvmMemoryGCVerboseLevel x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // Nothing to check...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Getter for the "JvmMemoryHeapUsed" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public Long getJvmMemoryHeapUsed() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        final long val = getHeapMemoryUsage().getUsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Getter for the "JvmMemoryHeapInitSize" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public Long getJvmMemoryHeapInitSize() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        final long val = getHeapMemoryUsage().getInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (val > -1) return new Long(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        else return Long0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Getter for the "JvmMemoryPendingFinalCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public Long getJvmMemoryPendingFinalCount()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        final long val = ManagementFactory.getMemoryMXBean().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            getObjectPendingFinalizationCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (val > -1) return new Long((int)val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // Should never happen... but stay safe all the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        else return new Long(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    static final MibLogger log = new MibLogger(JvmMemoryImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
}