jdk/src/java.management/share/classes/sun/management/ThreadInfoCompositeData.java
author jmanson
Tue, 24 Feb 2015 09:46:29 +0100
changeset 29101 55f7a91aaa32
parent 25859 3317bb8137f4
child 36511 9d0388c6b336
permissions -rw-r--r--
6588467: Add isDaemon() and getPriority() to ThreadInfo Reviewed-by: mchung, sla, dholmes, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13803
diff changeset
     2
 * Copyright (c) 2004, 2012, 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;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    46
    private final boolean hasV6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private ThreadInfoCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.threadInfo = ti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.currentVersion = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.cdata = null;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    52
        this.hasV6 = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private ThreadInfoCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.threadInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.currentVersion = ThreadInfoCompositeData.isCurrentVersion(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.cdata = cd;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    59
        this.hasV6 = ThreadInfoCompositeData.hasV6(cd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public ThreadInfo getThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    66
    public boolean hasV6() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    67
        return hasV6;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    68
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    69
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public boolean isCurrentVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return currentVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static ThreadInfoCompositeData getInstance(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return new ThreadInfoCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static CompositeData toCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        ThreadInfoCompositeData ticd = new ThreadInfoCompositeData(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return ticd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Convert StackTraceElement[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        StackTraceElement[] stackTrace = threadInfo.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            new CompositeData[stackTrace.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < stackTrace.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    95
        CompositeData lockInfoData =
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    96
            LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    98
        // Convert LockInfo[] and MonitorInfo[] to CompositeData[]
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    99
        LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   100
        CompositeData[] lockedSyncsData =
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   101
            new CompositeData[lockedSyncs.length];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   102
        for (int i = 0; i < lockedSyncs.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   103
            LockInfo li = lockedSyncs[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   104
            lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   105
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            new CompositeData[lockedMonitors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (int i = 0; i < lockedMonitors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            MonitorInfo mi = lockedMonitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // threadInfoItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        final Object[] threadInfoItemValues = {
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   118
            threadInfo.getThreadId(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            threadInfo.getThreadName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            threadInfo.getThreadState().name(),
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   121
            threadInfo.getBlockedTime(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   122
            threadInfo.getBlockedCount(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   123
            threadInfo.getWaitedTime(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   124
            threadInfo.getWaitedCount(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            lockInfoData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            threadInfo.getLockName(),
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   127
            threadInfo.getLockOwnerId(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            threadInfo.getLockOwnerName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            stackTraceData,
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 14342
diff changeset
   130
                threadInfo.isSuspended(),
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 14342
diff changeset
   131
                threadInfo.isInNative(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            lockedMonitorsData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            lockedSyncsData,
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   134
            threadInfo.isDaemon(),
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   135
            threadInfo.getPriority(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return new CompositeDataSupport(threadInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                            threadInfoItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                            threadInfoItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   144
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // Attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private static final String THREAD_ID       = "threadId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private static final String THREAD_NAME     = "threadName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final String THREAD_STATE    = "threadState";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final String BLOCKED_TIME    = "blockedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static final String BLOCKED_COUNT   = "blockedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private static final String WAITED_TIME     = "waitedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static final String WAITED_COUNT    = "waitedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private static final String LOCK_INFO       = "lockInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private static final String LOCK_NAME       = "lockName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static final String LOCK_OWNER_ID   = "lockOwnerId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static final String LOCK_OWNER_NAME = "lockOwnerName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static final String STACK_TRACE     = "stackTrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static final String SUSPENDED       = "suspended";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private static final String IN_NATIVE       = "inNative";
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   163
    private static final String DAEMON          = "daemon";
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   164
    private static final String PRIORITY        = "priority";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private static final String LOCKED_MONITORS = "lockedMonitors";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static final String LOCKED_SYNCS    = "lockedSynchronizers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private static final String[] threadInfoItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        THREAD_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        THREAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        THREAD_STATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        BLOCKED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        BLOCKED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        WAITED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        WAITED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        LOCK_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        LOCK_OWNER_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        LOCK_OWNER_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        STACK_TRACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        SUSPENDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        IN_NATIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        LOCKED_SYNCS,
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   185
        DAEMON,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   186
        PRIORITY,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    // New attributes added in 6.0 ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static final String[] threadInfoV6Attributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        LOCKED_SYNCS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   196
    private static final String[] threadInfoV9Attributes = {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   197
        DAEMON,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   198
        PRIORITY,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   199
    };
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   200
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // Current version of ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static final CompositeType threadInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // Previous version of ThreadInfo
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   204
    private static final CompositeType threadInfoV6CompositeType;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   205
    // Previous-previous version of ThreadInfo
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private static final CompositeType threadInfoV5CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private static final CompositeType lockInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            threadInfoCompositeType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                MappedMXBeanType.toOpenType(ThreadInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            // Form a CompositeType for JDK 5.0 ThreadInfo version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            String[] itemNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                threadInfoCompositeType.keySet().toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            int numV5Attributes = threadInfoItemNames.length -
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   216
                threadInfoV6Attributes.length - threadInfoV9Attributes.length;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            String[] v5ItemNames = new String[numV5Attributes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            String[] v5ItemDescs = new String[numV5Attributes];
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   219
            OpenType<?>[] v5ItemTypes = new OpenType<?>[numV5Attributes];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            for (String n : itemNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                if (isV5Attribute(n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    v5ItemNames[i] = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    v5ItemDescs[i] = threadInfoCompositeType.getDescription(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    v5ItemTypes[i] = threadInfoCompositeType.getType(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            threadInfoV5CompositeType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                new CompositeType("java.lang.management.ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                  "J2SE 5.0 java.lang.management.ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                  v5ItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                  v5ItemDescs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                  v5ItemTypes);
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   236
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   237
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   238
            // Form a CompositeType for JDK 6.0 ThreadInfo version
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   239
            int numV6Attributes = threadInfoItemNames.length -
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   240
                                      threadInfoV9Attributes.length;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   241
            String[] v6ItemNames = new String[numV6Attributes];
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   242
            String[] v6ItemDescs = new String[numV6Attributes];
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   243
            OpenType<?>[] v6ItemTypes = new OpenType<?>[numV6Attributes];
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   244
            i = 0;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   245
            for (String n : itemNames) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   246
                if (isV5Attribute(n) || isV6Attribute(n)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   247
                    v6ItemNames[i] = n;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   248
                    v6ItemDescs[i] = threadInfoCompositeType.getDescription(n);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   249
                    v6ItemTypes[i] = threadInfoCompositeType.getType(n);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   250
                    i++;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   251
                }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   252
            }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   253
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   254
            threadInfoV6CompositeType =
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   255
                new CompositeType("java.lang.management.ThreadInfo",
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   256
                                  "Java SE 6 java.lang.management.ThreadInfo",
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   257
                                  v6ItemNames,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   258
                                  v6ItemDescs,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   259
                                  v6ItemTypes);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   263
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // Each CompositeData object has its CompositeType associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // with it.  So we can get the CompositeType representing LockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // from a mapped CompositeData for any LockInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Thus we construct a random LockInfo object and pass it
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   270
        // to LockInfoCompositeData to do the conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        Object o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        LockInfo li = new LockInfo(o.getClass().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                   System.identityHashCode(o));
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   274
        CompositeData cd = LockInfoCompositeData.toCompositeData(li);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        lockInfoCompositeType = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static boolean isV5Attribute(String itemName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        for (String n : threadInfoV6Attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (itemName.equals(n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   284
        for (String n : threadInfoV9Attributes) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   285
            if (itemName.equals(n)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   286
                return false;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   287
            }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   288
        }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   289
        return true;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   290
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   291
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   292
    private static boolean isV6Attribute(String itemName) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   293
        for (String n : threadInfoV9Attributes) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   294
            if (itemName.equals(n)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   295
                return false;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   296
            }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   297
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return true;
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 static boolean isCurrentVersion(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return isTypeMatched(threadInfoCompositeType, cd.getCompositeType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   309
    private static boolean hasV6(CompositeData cd) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   310
        if (cd == null) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   311
            throw new NullPointerException("Null CompositeData");
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   312
        }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   313
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   314
        return isTypeMatched(threadInfoCompositeType, cd.getCompositeType()) ||
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   315
               isTypeMatched(threadInfoV6CompositeType, cd.getCompositeType());
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   316
     }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   317
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public long threadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return getLong(cdata, THREAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public String threadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // The ThreadName item cannot be null so we check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // it is present with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        String name = getString(cdata, THREAD_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            throw new IllegalArgumentException("Invalid composite data: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                "Attribute " + THREAD_NAME + " has null value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public Thread.State threadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return Thread.State.valueOf(getString(cdata, THREAD_STATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public long blockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return getLong(cdata, BLOCKED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public long blockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return getLong(cdata, BLOCKED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public long waitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return getLong(cdata, WAITED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public long waitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return getLong(cdata, WAITED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public String lockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // The LockName and LockOwnerName can legitimately be null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        // we don't bother to check the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return getString(cdata, LOCK_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public long lockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return getLong(cdata, LOCK_OWNER_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public String lockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return getString(cdata, LOCK_OWNER_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public boolean suspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return getBoolean(cdata, SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public boolean inNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return getBoolean(cdata, IN_NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   375
    public boolean isDaemon() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   376
        return getBoolean(cdata, DAEMON);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   377
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   378
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   379
    public int getPriority(){
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   380
        return getInt(cdata, PRIORITY);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   381
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   382
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public StackTraceElement[] stackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            (CompositeData[]) cdata.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // The StackTrace item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        StackTraceElement[] stackTrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            new StackTraceElement[stackTraceData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        for (int i = 0; i < stackTraceData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            CompositeData cdi = stackTraceData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            stackTrace[i] = StackTraceElementCompositeData.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    // 6.0 new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public LockInfo lockInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO);
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   401
        return LockInfo.from(lockInfoData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public MonitorInfo[] lockedMonitors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            (CompositeData[]) cdata.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // The LockedMonitors item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        MonitorInfo[] monitors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            new MonitorInfo[lockedMonitorsData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        for (int i = 0; i < lockedMonitorsData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            CompositeData cdi = lockedMonitorsData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            monitors[i] = MonitorInfo.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public LockInfo[] lockedSynchronizers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        CompositeData[] lockedSyncsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            (CompositeData[]) cdata.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // The LockedSynchronizers item cannot be null, but if it is we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // get a NullPointerException when we ask for its length.
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   425
        LockInfo[] locks = new LockInfo[lockedSyncsData.length];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   426
        for (int i = 0; i < lockedSyncsData.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   427
            CompositeData cdi = lockedSyncsData[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   428
            locks[i] = LockInfo.from(cdi);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   429
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   430
        return locks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        CompositeType type = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        boolean currentVersion = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (!isTypeMatched(threadInfoCompositeType, type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            currentVersion = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            // check if cd is an older version
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   447
            if (!isTypeMatched(threadInfoV5CompositeType, type) &&
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   448
                !isTypeMatched(threadInfoV6CompositeType, type)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   449
              throw new IllegalArgumentException(
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   450
                  "Unexpected composite type for ThreadInfo");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            (CompositeData[]) cd.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (stackTraceData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                "StackTraceElement[] is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (stackTraceData.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // validate v6 attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (currentVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            CompositeData li = (CompositeData) cd.get(LOCK_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (li != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                   li.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        LOCK_INFO + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            if (lms == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                throw new IllegalArgumentException("MonitorInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (lms.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                MonitorInfoCompositeData.validateCompositeData(lms[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            if (lsyncs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                throw new IllegalArgumentException("LockInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if (lsyncs.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                   lsyncs[0].getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        LOCKED_SYNCS + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   499
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   500
    private static final long serialVersionUID = 2464378539119753175L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
}