jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4173 d01972926813
child 11530 a9d059c15b80
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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: 4173
diff changeset
     2
 * Copyright (c) 2004, 2008, 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: 4173
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: 4173
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: 4173
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
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 sun.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.management.ThreadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.management.MonitorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.management.LockInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.openmbean.OpenType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A CompositeData for ThreadInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class ThreadInfoCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final ThreadInfo threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final CompositeData cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private final boolean currentVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private ThreadInfoCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.threadInfo = ti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.currentVersion = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.cdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private ThreadInfoCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.threadInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.currentVersion = ThreadInfoCompositeData.isCurrentVersion(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.cdata = cd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public ThreadInfo getThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public boolean isCurrentVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return currentVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static ThreadInfoCompositeData getInstance(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return new ThreadInfoCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static CompositeData toCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        ThreadInfoCompositeData ticd = new ThreadInfoCompositeData(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return ticd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // Convert StackTraceElement[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        StackTraceElement[] stackTrace = threadInfo.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            new CompositeData[stackTrace.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        for (int i = 0; i < stackTrace.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        LockDataConverter converter = new LockDataConverter(threadInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        CompositeData lockInfoData = converter.toLockInfoCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        CompositeData[] lockedSyncsData = converter.toLockedSynchronizersCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Convert MonitorInfo[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            new CompositeData[lockedMonitors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (int i = 0; i < lockedMonitors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            MonitorInfo mi = lockedMonitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // threadInfoItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        final Object[] threadInfoItemValues = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            new Long(threadInfo.getThreadId()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            threadInfo.getThreadName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            threadInfo.getThreadState().name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            new Long(threadInfo.getBlockedTime()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            new Long(threadInfo.getBlockedCount()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            new Long(threadInfo.getWaitedTime()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            new Long(threadInfo.getWaitedCount()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            lockInfoData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            threadInfo.getLockName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            new Long(threadInfo.getLockOwnerId()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            threadInfo.getLockOwnerName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            stackTraceData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            new Boolean(threadInfo.isSuspended()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            new Boolean(threadInfo.isInNative()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            lockedMonitorsData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            lockedSyncsData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return new CompositeDataSupport(threadInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                            threadInfoItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                            threadInfoItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   129
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // Attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static final String THREAD_ID       = "threadId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private static final String THREAD_NAME     = "threadName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static final String THREAD_STATE    = "threadState";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static final String BLOCKED_TIME    = "blockedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final String BLOCKED_COUNT   = "blockedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final String WAITED_TIME     = "waitedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static final String WAITED_COUNT    = "waitedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static final String LOCK_INFO       = "lockInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static final String LOCK_NAME       = "lockName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static final String LOCK_OWNER_ID   = "lockOwnerId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static final String LOCK_OWNER_NAME = "lockOwnerName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final String STACK_TRACE     = "stackTrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static final String SUSPENDED       = "suspended";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static final String IN_NATIVE       = "inNative";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final String LOCKED_MONITORS = "lockedMonitors";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private static final String LOCKED_SYNCS    = "lockedSynchronizers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final String[] threadInfoItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        THREAD_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        THREAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        THREAD_STATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        BLOCKED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        BLOCKED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        WAITED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        WAITED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        LOCK_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        LOCK_OWNER_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        LOCK_OWNER_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        STACK_TRACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        SUSPENDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        IN_NATIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        LOCKED_SYNCS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // New attributes added in 6.0 ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private static final String[] threadInfoV6Attributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        LOCKED_SYNCS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // Current version of ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final CompositeType threadInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    // Previous version of ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static final CompositeType threadInfoV5CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final CompositeType lockInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            threadInfoCompositeType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                MappedMXBeanType.toOpenType(ThreadInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // Form a CompositeType for JDK 5.0 ThreadInfo version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            String[] itemNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                threadInfoCompositeType.keySet().toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            int numV5Attributes = threadInfoItemNames.length -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                      threadInfoV6Attributes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            String[] v5ItemNames = new String[numV5Attributes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            String[] v5ItemDescs = new String[numV5Attributes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            OpenType[] v5ItemTypes = new OpenType[numV5Attributes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            for (String n : itemNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (isV5Attribute(n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    v5ItemNames[i] = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    v5ItemDescs[i] = threadInfoCompositeType.getDescription(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    v5ItemTypes[i] = threadInfoCompositeType.getType(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            threadInfoV5CompositeType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                new CompositeType("java.lang.management.ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                  "J2SE 5.0 java.lang.management.ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                  v5ItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                  v5ItemDescs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                  v5ItemTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   212
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // Each CompositeData object has its CompositeType associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // with it.  So we can get the CompositeType representing LockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // from a mapped CompositeData for any LockInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // Thus we construct a random LockInfo object and pass it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // to LockDataConverter to do the conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Object o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        LockInfo li = new LockInfo(o.getClass().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                   System.identityHashCode(o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        CompositeData cd = LockDataConverter.toLockInfoCompositeData(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        lockInfoCompositeType = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private static boolean isV5Attribute(String itemName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        for (String n : threadInfoV6Attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (itemName.equals(n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static boolean isCurrentVersion(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return isTypeMatched(threadInfoCompositeType, cd.getCompositeType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public long threadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return getLong(cdata, THREAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public String threadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // The ThreadName item cannot be null so we check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // it is present with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        String name = getString(cdata, THREAD_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw new IllegalArgumentException("Invalid composite data: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                "Attribute " + THREAD_NAME + " has null value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public Thread.State threadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return Thread.State.valueOf(getString(cdata, THREAD_STATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public long blockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return getLong(cdata, BLOCKED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public long blockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return getLong(cdata, BLOCKED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public long waitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return getLong(cdata, WAITED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public long waitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return getLong(cdata, WAITED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public String lockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // The LockName and LockOwnerName can legitimately be null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        // we don't bother to check the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return getString(cdata, LOCK_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public long lockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return getLong(cdata, LOCK_OWNER_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public String lockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return getString(cdata, LOCK_OWNER_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public boolean suspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return getBoolean(cdata, SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public boolean inNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return getBoolean(cdata, IN_NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public StackTraceElement[] stackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            (CompositeData[]) cdata.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // The StackTrace item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        StackTraceElement[] stackTrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            new StackTraceElement[stackTraceData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        for (int i = 0; i < stackTraceData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            CompositeData cdi = stackTraceData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            stackTrace[i] = StackTraceElementCompositeData.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    // 6.0 new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public LockInfo lockInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        LockDataConverter converter = new LockDataConverter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return converter.toLockInfo(lockInfoData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public MonitorInfo[] lockedMonitors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            (CompositeData[]) cdata.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // The LockedMonitors item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        MonitorInfo[] monitors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            new MonitorInfo[lockedMonitorsData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        for (int i = 0; i < lockedMonitorsData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            CompositeData cdi = lockedMonitorsData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            monitors[i] = MonitorInfo.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public LockInfo[] lockedSynchronizers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        LockDataConverter converter = new LockDataConverter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        CompositeData[] lockedSyncsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            (CompositeData[]) cdata.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // The LockedSynchronizers item cannot be null, but if it is we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // get a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return converter.toLockedSynchronizers(lockedSyncsData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        CompositeType type = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        boolean currentVersion = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (!isTypeMatched(threadInfoCompositeType, type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            currentVersion = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            // check if cd is an older version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if (!isTypeMatched(threadInfoV5CompositeType, type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    "Unexpected composite type for ThreadInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            (CompositeData[]) cd.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (stackTraceData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                "StackTraceElement[] is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (stackTraceData.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // validate v6 attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (currentVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            CompositeData li = (CompositeData) cd.get(LOCK_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (li != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                   li.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        LOCK_INFO + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (lms == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                throw new IllegalArgumentException("MonitorInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (lms.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                MonitorInfoCompositeData.validateCompositeData(lms[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (lsyncs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                throw new IllegalArgumentException("LockInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (lsyncs.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                   lsyncs[0].getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        LOCKED_SYNCS + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   413
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   414
    private static final long serialVersionUID = 2464378539119753175L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
}