jdk/src/java.management/share/classes/sun/management/ThreadInfoCompositeData.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
parent 29101 55f7a91aaa32
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A CompositeData for ThreadInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class ThreadInfoCompositeData extends LazyCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private final ThreadInfo threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final CompositeData cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final boolean currentVersion;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    45
    private final boolean hasV6;
2
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;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    51
        this.hasV6 = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private ThreadInfoCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.threadInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.currentVersion = ThreadInfoCompositeData.isCurrentVersion(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.cdata = cd;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    58
        this.hasV6 = ThreadInfoCompositeData.hasV6(cd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public ThreadInfo getThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    65
    public boolean hasV6() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    66
        return hasV6;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    67
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    68
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public boolean isCurrentVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return currentVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static ThreadInfoCompositeData getInstance(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return new ThreadInfoCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static CompositeData toCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ThreadInfoCompositeData ticd = new ThreadInfoCompositeData(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return ticd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // Convert StackTraceElement[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        StackTraceElement[] stackTrace = threadInfo.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            new CompositeData[stackTrace.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        for (int i = 0; i < stackTrace.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    94
        CompositeData lockInfoData =
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    95
            LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    97
        // Convert LockInfo[] and MonitorInfo[] to CompositeData[]
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    98
        LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    99
        CompositeData[] lockedSyncsData =
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   100
            new CompositeData[lockedSyncs.length];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   101
        for (int i = 0; i < lockedSyncs.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   102
            LockInfo li = lockedSyncs[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   103
            lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   104
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   105
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            new CompositeData[lockedMonitors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        for (int i = 0; i < lockedMonitors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            MonitorInfo mi = lockedMonitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // threadInfoItemNames!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        final Object[] threadInfoItemValues = {
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   117
            threadInfo.getThreadId(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            threadInfo.getThreadName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            threadInfo.getThreadState().name(),
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   120
            threadInfo.getBlockedTime(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   121
            threadInfo.getBlockedCount(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   122
            threadInfo.getWaitedTime(),
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   123
            threadInfo.getWaitedCount(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            lockInfoData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            threadInfo.getLockName(),
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   126
            threadInfo.getLockOwnerId(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            threadInfo.getLockOwnerName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            stackTraceData,
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 14342
diff changeset
   129
                threadInfo.isSuspended(),
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 14342
diff changeset
   130
                threadInfo.isInNative(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            lockedMonitorsData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            lockedSyncsData,
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   133
            threadInfo.isDaemon(),
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   134
            threadInfo.getPriority(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return new CompositeDataSupport(threadInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                            threadInfoItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                            threadInfoItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   143
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // Attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final String THREAD_ID       = "threadId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private static final String THREAD_NAME     = "threadName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private static final String THREAD_STATE    = "threadState";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final String BLOCKED_TIME    = "blockedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final String BLOCKED_COUNT   = "blockedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static final String WAITED_TIME     = "waitedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private static final String WAITED_COUNT    = "waitedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static final String LOCK_INFO       = "lockInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private static final String LOCK_NAME       = "lockName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private static final String LOCK_OWNER_ID   = "lockOwnerId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static final String LOCK_OWNER_NAME = "lockOwnerName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static final String STACK_TRACE     = "stackTrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static final String SUSPENDED       = "suspended";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static final String IN_NATIVE       = "inNative";
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   162
    private static final String DAEMON          = "daemon";
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   163
    private static final String PRIORITY        = "priority";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private static final String LOCKED_MONITORS = "lockedMonitors";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private static final String LOCKED_SYNCS    = "lockedSynchronizers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static final String[] threadInfoItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        THREAD_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        THREAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        THREAD_STATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        BLOCKED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        BLOCKED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        WAITED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        WAITED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        LOCK_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        LOCK_OWNER_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        LOCK_OWNER_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        STACK_TRACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        SUSPENDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        IN_NATIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        LOCKED_SYNCS,
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   184
        DAEMON,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   185
        PRIORITY,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // New attributes added in 6.0 ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private static final String[] threadInfoV6Attributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        LOCKED_SYNCS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   195
    private static final String[] threadInfoV9Attributes = {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   196
        DAEMON,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   197
        PRIORITY,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   198
    };
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // Current version of ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final CompositeType threadInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // Previous version of ThreadInfo
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   203
    private static final CompositeType threadInfoV6CompositeType;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   204
    // Previous-previous version of ThreadInfo
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private static final CompositeType threadInfoV5CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private static final CompositeType lockInfoCompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            threadInfoCompositeType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                MappedMXBeanType.toOpenType(ThreadInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // Form a CompositeType for JDK 5.0 ThreadInfo version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            threadInfoV5CompositeType =
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   214
                TypeVersionMapper.getInstance().getVersionedCompositeType(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   215
                    threadInfoCompositeType, TypeVersionMapper.V5
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   216
                );
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   217
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   218
            threadInfoV6CompositeType =
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   219
                TypeVersionMapper.getInstance().getVersionedCompositeType(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   220
                    threadInfoCompositeType, TypeVersionMapper.V6
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   221
                );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   224
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // Each CompositeData object has its CompositeType associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // with it.  So we can get the CompositeType representing LockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // from a mapped CompositeData for any LockInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // 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
   231
        // to LockInfoCompositeData to do the conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Object o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        LockInfo li = new LockInfo(o.getClass().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                   System.identityHashCode(o));
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   235
        CompositeData cd = LockInfoCompositeData.toCompositeData(li);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        lockInfoCompositeType = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   239
    static boolean isV5Attribute(String itemName) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        for (String n : threadInfoV6Attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (itemName.equals(n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   245
        for (String n : threadInfoV9Attributes) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   246
            if (itemName.equals(n)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   247
                return false;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   248
            }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   249
        }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   250
        return true;
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
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   253
    static boolean isV6Attribute(String itemName) {
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   254
        for (String n : threadInfoV9Attributes) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   255
            if (itemName.equals(n)) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   256
                return false;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   257
            }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   258
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public static boolean isCurrentVersion(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return isTypeMatched(threadInfoCompositeType, cd.getCompositeType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   270
    private static boolean hasV6(CompositeData cd) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   271
        if (cd == null) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   272
            throw new NullPointerException("Null CompositeData");
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   273
        }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   274
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   275
        return isTypeMatched(threadInfoCompositeType, cd.getCompositeType()) ||
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   276
               isTypeMatched(threadInfoV6CompositeType, cd.getCompositeType());
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   277
     }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   278
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public long threadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return getLong(cdata, THREAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public String threadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // The ThreadName item cannot be null so we check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // it is present with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        String name = getString(cdata, THREAD_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new IllegalArgumentException("Invalid composite data: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                "Attribute " + THREAD_NAME + " has null value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public Thread.State threadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return Thread.State.valueOf(getString(cdata, THREAD_STATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public long blockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return getLong(cdata, BLOCKED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public long blockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return getLong(cdata, BLOCKED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public long waitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return getLong(cdata, WAITED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public long waitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return getLong(cdata, WAITED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public String lockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // The LockName and LockOwnerName can legitimately be null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // we don't bother to check the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return getString(cdata, LOCK_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public long lockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return getLong(cdata, LOCK_OWNER_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public String lockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return getString(cdata, LOCK_OWNER_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public boolean suspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return getBoolean(cdata, SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public boolean inNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return getBoolean(cdata, IN_NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   336
    public boolean isDaemon() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   337
        return getBoolean(cdata, DAEMON);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   338
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   339
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   340
    public int getPriority(){
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   341
        return getInt(cdata, PRIORITY);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   342
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   343
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public StackTraceElement[] stackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            (CompositeData[]) cdata.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // The StackTrace item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        StackTraceElement[] stackTrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            new StackTraceElement[stackTraceData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        for (int i = 0; i < stackTraceData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            CompositeData cdi = stackTraceData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            stackTrace[i] = StackTraceElementCompositeData.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    // 6.0 new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public LockInfo lockInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO);
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   362
        return LockInfo.from(lockInfoData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public MonitorInfo[] lockedMonitors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (CompositeData[]) cdata.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // The LockedMonitors item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        MonitorInfo[] monitors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            new MonitorInfo[lockedMonitorsData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        for (int i = 0; i < lockedMonitorsData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            CompositeData cdi = lockedMonitorsData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            monitors[i] = MonitorInfo.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public LockInfo[] lockedSynchronizers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        CompositeData[] lockedSyncsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            (CompositeData[]) cdata.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // The LockedSynchronizers item cannot be null, but if it is we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // 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
   386
        LockInfo[] locks = new LockInfo[lockedSyncsData.length];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   387
        for (int i = 0; i < lockedSyncsData.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   388
            CompositeData cdi = lockedSyncsData[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   389
            locks[i] = LockInfo.from(cdi);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   390
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   391
        return locks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /** Validate if the input CompositeData has the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        CompositeType type = cd.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        boolean currentVersion = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (!isTypeMatched(threadInfoCompositeType, type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            currentVersion = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // check if cd is an older version
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   408
            if (!isTypeMatched(threadInfoV5CompositeType, type) &&
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   409
                !isTypeMatched(threadInfoV6CompositeType, type)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   410
                throw new IllegalArgumentException(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 29101
diff changeset
   411
                    "Unexpected composite type for ThreadInfo");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            (CompositeData[]) cd.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (stackTraceData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                "StackTraceElement[] is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (stackTraceData.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // validate v6 attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (currentVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            CompositeData li = (CompositeData) cd.get(LOCK_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (li != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                   li.getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        LOCK_INFO + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (lms == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                throw new IllegalArgumentException("MonitorInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (lms.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                MonitorInfoCompositeData.validateCompositeData(lms[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (lsyncs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                throw new IllegalArgumentException("LockInfo[] is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (lsyncs.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                if (!isTypeMatched(lockInfoCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                   lsyncs[0].getCompositeType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        "Unexpected composite type for \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        LOCKED_SYNCS + "\" attribute.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   460
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   461
    private static final long serialVersionUID = 2464378539119753175L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}