jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.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, 2004, 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
// java imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.management.ThreadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.management.ThreadMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.jmx.snmp.SnmpDefinitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.SnmpOidTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.jmx.snmp.SnmpOidRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.management.snmp.jvmmib.JvmThreadInstanceEntryMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIBOidTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.management.snmp.util.MibLogger;
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 "JvmThreadInstanceEntry" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class JvmThreadInstanceEntryImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    implements JvmThreadInstanceEntryMBean, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    56
    static final long serialVersionUID = 910173589985461347L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    57
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public final static class ThreadStateMap {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        public final static class Byte0 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            public final static byte inNative     = (byte)0x80; // bit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            public final static byte suspended    = (byte)0x40; // bit 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            public final static byte newThread    = (byte)0x20; // bit 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            public final static byte runnable     = (byte)0x10; // bit 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            public final static byte blocked      = (byte)0x08; // bit 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            public final static byte terminated   = (byte)0x04; // bit 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            public final static byte waiting      = (byte)0x02; // bit 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            public final static byte timedWaiting = (byte)0x01; // bit 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public final static class Byte1 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            public final static byte other        = (byte)0x80; // bit 9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            public final static byte reserved10   = (byte)0x40; // bit 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            public final static byte reserved11   = (byte)0x20; // bit 11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            public final static byte reserved12   = (byte)0x10; // bit 12
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            public final static byte reserved13   = (byte)0x08; // bit 13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            public final static byte reserved14   = (byte)0x04; // bit 14
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            public final static byte reserved15   = (byte)0x02; // bit 15
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            public final static byte reserved16   = (byte)0x01; // bit 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        public final static byte mask0 = (byte)0x3F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        public final static byte mask1 = (byte)0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        private static void setBit(byte[] bitmap, int index, byte state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            bitmap[index] = (byte) (bitmap[index] | state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        public static void setNative(byte[] bitmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            setBit(bitmap,0,Byte0.inNative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public static void setSuspended(byte[] bitmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            setBit(bitmap,0,Byte0.suspended);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        public static void setState(byte[] bitmap, Thread.State state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            switch(state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            case BLOCKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                setBit(bitmap,0,Byte0.blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            case NEW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                setBit(bitmap,0,Byte0.newThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            case RUNNABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                setBit(bitmap,0,Byte0.runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            case TERMINATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                setBit(bitmap,0,Byte0.terminated);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            case TIMED_WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                setBit(bitmap,0,Byte0.timedWaiting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            case WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                setBit(bitmap,0,Byte0.waiting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        public static void checkOther(byte[] bitmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (((bitmap[0]&mask0)==(byte)0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                ((bitmap[1]&mask1)==(byte)0x00))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                setBit(bitmap,1,Byte1.other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        public static Byte[] getState(ThreadInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                final Thread.State state = info.getThreadState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                final boolean inNative  = info.isInNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                final boolean suspended = info.isSuspended();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                log.debug("getJvmThreadInstState",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                          "[State=" + state +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                          ",isInNative=" + inNative +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                          ",isSuspended=" + suspended + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                setState(bitmap,state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (inNative)  setNative(bitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (suspended) setSuspended(bitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                checkOther(bitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            } catch (RuntimeException r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                bitmap[0]=(byte)0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                bitmap[1]=Byte1.other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                log.trace("getJvmThreadInstState",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                          "Unexpected exception: " + r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                log.debug("getJvmThreadInstState",r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private final ThreadInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private final Byte[] index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Constructor for the "JvmThreadInstanceEntry" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public JvmThreadInstanceEntryImpl(ThreadInfo info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                      Byte[] index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static String  jvmThreadInstIndexOid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public static String getJvmThreadInstIndexOid()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (jvmThreadInstIndexOid == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            final SnmpOidTable  table = new JVM_MANAGEMENT_MIBOidTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            final SnmpOidRecord record =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                table.resolveVarName("jvmThreadInstIndex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            jvmThreadInstIndexOid = record.getOid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return jvmThreadInstIndexOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Getter for the "JvmThreadInstLockedOwnerId" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public String getJvmThreadInstLockOwnerPtr() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
       long id = info.getLockOwnerId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
       if(id == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
           return new String("0.0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
       SnmpOid oid = JvmThreadInstanceTableMetaImpl.makeOid(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
       return getJvmThreadInstIndexOid() + "." + oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private String validDisplayStringTC(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return JVM_MANAGEMENT_MIB_IMPL.validDisplayStringTC(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private String validJavaObjectNameTC(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private String validPathElementTC(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Getter for the "JvmThreadInstLockName" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public String getJvmThreadInstLockName() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return validJavaObjectNameTC(info.getLockName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Getter for the "JvmThreadInstName" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public String getJvmThreadInstName() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return validJavaObjectNameTC(info.getThreadName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Getter for the "JvmThreadInstCpuTimeNs" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        long l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (tmb.isThreadCpuTimeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                l = tmb.getThreadCpuTime(info.getThreadId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                //Cpu time measurement is disabled or the id is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                if(l == -1) l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } catch (UnsatisfiedLinkError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // XXX Revisit: catch TO BE EVENTUALLY REMOVED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            log.debug("getJvmThreadInstCpuTimeNs",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                      "Operation not supported: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return new Long(l);
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 "JvmThreadInstBlockTimeMs" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        long l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (tmb.isThreadContentionMonitoringSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            l = info.getBlockedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            //Monitoring is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if(l == -1) l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return new Long(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Getter for the "JvmThreadInstBlockCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Long getJvmThreadInstBlockCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return new Long(info.getBlockedCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Getter for the "JvmThreadInstWaitTimeMs" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public Long getJvmThreadInstWaitTimeMs() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        long l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (tmb.isThreadContentionMonitoringSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            l = info.getWaitedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            //Monitoring is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if(l == -1) l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return new Long(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Getter for the "JvmThreadInstWaitCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Long getJvmThreadInstWaitCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return new Long(info.getWaitedCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Getter for the "JvmThreadInstState" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public Byte[] getJvmThreadInstState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return ThreadStateMap.getState(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Getter for the "JvmThreadInstId" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public Long getJvmThreadInstId() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return new Long(info.getThreadId());
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
     * Getter for the "JvmThreadInstIndex" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Byte[] getJvmThreadInstIndex() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Getter for the "JvmThreadInstStackTrace" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private String getJvmThreadInstStackTrace() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        StackTraceElement[] stackTrace = info.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        //We append the stack trace in a buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // XXX Revisit: should check isDebugOn()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        StringBuffer b = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        final int stackSize = stackTrace.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        log.debug("getJvmThreadInstStackTrace", "Stack size : " + stackSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        for(int i = 0; i < stackSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            log.debug("getJvmThreadInstStackTrace", "Append " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                      stackTrace[i].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            b.append(stackTrace[i].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            //Append \n at the end of each line except the last one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if(i < stackSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                b.append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        //The stack trace is truncated if its size exceeds 255.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return validPathElementTC(b.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    static final MibLogger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        new MibLogger(JvmThreadInstanceEntryImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}