src/java.management/share/classes/sun/management/ThreadInfoCompositeData.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 52288 2b29df6dfa68
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
     2
 * Copyright (c) 2004, 2019, 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;
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    31
import java.util.Arrays;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    32
import java.util.HashMap;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    33
import java.util.Map;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    34
import java.util.stream.Stream;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    35
import javax.management.openmbean.ArrayType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.openmbean.OpenDataException;
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    40
import javax.management.openmbean.OpenType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A CompositeData for ThreadInfo for the local management support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class avoids the performance penalty paid to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * construction of a CompositeData use in the local case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class ThreadInfoCompositeData extends LazyCompositeData {
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
    48
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final ThreadInfo threadInfo;
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52288
diff changeset
    50
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final CompositeData cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private ThreadInfoCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.threadInfo = ti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.cdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private ThreadInfoCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.threadInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.cdata = cd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public ThreadInfo getThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return threadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static ThreadInfoCompositeData getInstance(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return new ThreadInfoCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static CompositeData toCompositeData(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        ThreadInfoCompositeData ticd = new ThreadInfoCompositeData(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return ticd.getCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // Convert StackTraceElement[] to CompositeData[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        StackTraceElement[] stackTrace = threadInfo.getStackTrace();
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    80
        CompositeData[] stackTraceData = new CompositeData[stackTrace.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        for (int i = 0; i < stackTrace.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    87
        CompositeData lockInfoData =
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    88
            LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    90
        // Convert LockInfo[] and MonitorInfo[] to CompositeData[]
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    91
        LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    92
        CompositeData[] lockedSyncsData = new CompositeData[lockedSyncs.length];
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    93
        for (int i = 0; i < lockedSyncs.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    94
            LockInfo li = lockedSyncs[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    95
            lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    96
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
    97
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
    99
        CompositeData[] lockedMonitorsData = new CompositeData[lockedMonitors.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (int i = 0; i < lockedMonitors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            MonitorInfo mi = lockedMonitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   105
        // values may be null; can't use Map.of
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   106
        Map<String,Object> items = new HashMap<>();
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   107
        items.put(THREAD_ID,        threadInfo.getThreadId());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   108
        items.put(THREAD_NAME,      threadInfo.getThreadName());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   109
        items.put(THREAD_STATE,     threadInfo.getThreadState().name());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   110
        items.put(BLOCKED_TIME,     threadInfo.getBlockedTime());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   111
        items.put(BLOCKED_COUNT,    threadInfo.getBlockedCount());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   112
        items.put(WAITED_TIME,      threadInfo.getWaitedTime());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   113
        items.put(WAITED_COUNT,     threadInfo.getWaitedCount());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   114
        items.put(LOCK_INFO,        lockInfoData);
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   115
        items.put(LOCK_NAME,        threadInfo.getLockName());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   116
        items.put(LOCK_OWNER_ID,    threadInfo.getLockOwnerId());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   117
        items.put(LOCK_OWNER_NAME,  threadInfo.getLockOwnerName());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   118
        items.put(STACK_TRACE,      stackTraceData);
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   119
        items.put(SUSPENDED,        threadInfo.isSuspended());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   120
        items.put(IN_NATIVE,        threadInfo.isInNative());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   121
        items.put(LOCKED_MONITORS,  lockedMonitorsData);
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   122
        items.put(LOCKED_SYNCS,     lockedSyncsData);
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   123
        items.put(DAEMON,           threadInfo.isDaemon());
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   124
        items.put(PRIORITY,         threadInfo.getPriority());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try {
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   127
            return new CompositeDataSupport(ThreadInfoCompositeTypes.ofVersion(RUNTIME_VERSION), items);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // Should never reach here
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   130
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // Attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private static final String THREAD_ID       = "threadId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static final String THREAD_NAME     = "threadName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static final String THREAD_STATE    = "threadState";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final String BLOCKED_TIME    = "blockedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final String BLOCKED_COUNT   = "blockedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static final String WAITED_TIME     = "waitedTime";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static final String WAITED_COUNT    = "waitedCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static final String LOCK_INFO       = "lockInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static final String LOCK_NAME       = "lockName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static final String LOCK_OWNER_ID   = "lockOwnerId";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final String LOCK_OWNER_NAME = "lockOwnerName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static final String STACK_TRACE     = "stackTrace";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static final String SUSPENDED       = "suspended";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final String IN_NATIVE       = "inNative";
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   149
    private static final String DAEMON          = "daemon";
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   150
    private static final String PRIORITY        = "priority";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final String LOCKED_MONITORS = "lockedMonitors";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final String LOCKED_SYNCS    = "lockedSynchronizers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   154
    private static final String[] V5_ATTRIBUTES = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        THREAD_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        THREAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        THREAD_STATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        BLOCKED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        BLOCKED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        WAITED_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        WAITED_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        LOCK_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        LOCK_OWNER_ID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        LOCK_OWNER_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        STACK_TRACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        SUSPENDED,
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   167
        IN_NATIVE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   170
    private static final String[] V6_ATTRIBUTES = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        LOCK_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        LOCKED_MONITORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        LOCKED_SYNCS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   176
    private static final String[] V9_ATTRIBUTES = {
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   177
        DAEMON,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   178
        PRIORITY,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   179
    };
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   180
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public long threadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return getLong(cdata, THREAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public String threadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // The ThreadName item cannot be null so we check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // it is present with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        String name = getString(cdata, THREAD_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new IllegalArgumentException("Invalid composite data: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                "Attribute " + THREAD_NAME + " has null value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public Thread.State threadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return Thread.State.valueOf(getString(cdata, THREAD_STATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public long blockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return getLong(cdata, BLOCKED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public long blockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return getLong(cdata, BLOCKED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public long waitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return getLong(cdata, WAITED_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public long waitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return getLong(cdata, WAITED_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public String lockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // The LockName and LockOwnerName can legitimately be null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // we don't bother to check the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return getString(cdata, LOCK_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public long lockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return getLong(cdata, LOCK_OWNER_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public String lockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return getString(cdata, LOCK_OWNER_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public boolean suspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return getBoolean(cdata, SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public boolean inNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return getBoolean(cdata, IN_NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   238
    /*
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   239
     * if daemon attribute is not present, default to false.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   240
     */
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   241
    public boolean isDaemon() {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   242
        return cdata.containsKey(DAEMON) ? getBoolean(cdata, DAEMON) : false;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   243
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   244
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   245
    /*
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   246
     * if priority attribute is not present, default to norm priority.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   247
     */
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   248
    public int getPriority(){
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   249
        return cdata.containsKey(PRIORITY) ? getInt(cdata, PRIORITY) : Thread.NORM_PRIORITY;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   250
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   251
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public StackTraceElement[] stackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        CompositeData[] stackTraceData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            (CompositeData[]) cdata.get(STACK_TRACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // The StackTrace item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        StackTraceElement[] stackTrace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            new StackTraceElement[stackTraceData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        for (int i = 0; i < stackTraceData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            CompositeData cdi = stackTraceData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            stackTrace[i] = StackTraceElementCompositeData.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   267
    /*
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   268
     * lockInfo is a new attribute added in JDK 6 ThreadInfo
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   269
     * If cd is a 5.0 version, construct the LockInfo object
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   270
     * from the lockName value.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   271
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public LockInfo lockInfo() {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   273
        if (cdata.containsKey(LOCK_INFO)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   274
            CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   275
            return LockInfo.from(lockInfoData);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   276
        } else {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   277
            String lockName = lockName();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   278
            LockInfo lock = null;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   279
            if (lockName != null) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   280
                String result[] = lockName.split("@");
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   281
                if (result.length == 2) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   282
                    int identityHashCode = Integer.parseInt(result[1], 16);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   283
                    lock = new LockInfo(result[0], identityHashCode);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   284
                }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   285
            }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   286
            return lock;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   287
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   290
    /**
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   291
     * Returns an empty array if locked_monitors attribute is not present.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   292
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public MonitorInfo[] lockedMonitors() {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   294
        if (!cdata.containsKey(LOCKED_MONITORS)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   295
            return new MonitorInfo[0];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   296
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   297
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        CompositeData[] lockedMonitorsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            (CompositeData[]) cdata.get(LOCKED_MONITORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // The LockedMonitors item cannot be null, but if it is we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        // a NullPointerException when we ask for its length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        MonitorInfo[] monitors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            new MonitorInfo[lockedMonitorsData.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        for (int i = 0; i < lockedMonitorsData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            CompositeData cdi = lockedMonitorsData[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            monitors[i] = MonitorInfo.from(cdi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   312
    /**
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   313
     * Returns an empty array if locked_monitors attribute is not present.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   314
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public LockInfo[] lockedSynchronizers() {
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   316
        if (!cdata.containsKey(LOCKED_SYNCS)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   317
            return new LockInfo[0];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   318
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        CompositeData[] lockedSyncsData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            (CompositeData[]) cdata.get(LOCKED_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // The LockedSynchronizers item cannot be null, but if it is we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // 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
   325
        LockInfo[] locks = new LockInfo[lockedSyncsData.length];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   326
        for (int i = 0; i < lockedSyncsData.length; i++) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   327
            CompositeData cdi = lockedSyncsData[i];
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   328
            locks[i] = LockInfo.from(cdi);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   329
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 11530
diff changeset
   330
        return locks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   333
    /**
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   334
     * Validate if the input CompositeData has the expected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * CompositeType (i.e. contain all attributes with expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * names and types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public static void validateCompositeData(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throw new NullPointerException("Null CompositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        CompositeType type = cd.getCompositeType();
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   344
        int version;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   345
        if (Arrays.stream(V9_ATTRIBUTES).anyMatch(type::containsKey)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   346
            version = Runtime.version().feature();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   347
        } else if (Arrays.stream(V6_ATTRIBUTES).anyMatch(type::containsKey)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   348
            version = 6;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   349
        } else {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   350
            version = 5;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   351
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   352
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   353
        if (!isTypeMatched(ThreadInfoCompositeTypes.ofVersion(version), type)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   354
            throw new IllegalArgumentException(
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   355
                "Unexpected composite type for ThreadInfo of version " + version);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   356
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   357
    }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   358
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   359
    static final int RUNTIME_VERSION =  Runtime.version().feature();
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   360
    static class ThreadInfoCompositeTypes {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   361
        static final Map<Integer, CompositeType> compositeTypes = initCompositeTypes();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   362
        /*
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   363
         * Returns CompositeType of the given runtime version
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   364
         */
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   365
        static CompositeType ofVersion(int version) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   366
            return compositeTypes.get(version);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   367
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   368
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   369
        static Map<Integer, CompositeType> initCompositeTypes() {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   370
            Map<Integer, CompositeType> types = new HashMap<>();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   371
            CompositeType ctype = initCompositeType();
52288
2b29df6dfa68 8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents: 49077
diff changeset
   372
            types.put(RUNTIME_VERSION, ctype);
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   373
            types.put(5, initV5CompositeType(ctype));
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   374
            types.put(6, initV6CompositeType(ctype));
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   375
            return types;
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   376
        }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   377
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   378
        static CompositeType initCompositeType() {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   379
            try {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   380
                return (CompositeType)MappedMXBeanType.toOpenType(ThreadInfo.class);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   381
            } catch (OpenDataException e) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   382
                // Should never reach here
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   383
                throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   387
        static CompositeType initV5CompositeType(CompositeType threadInfoCompositeType) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   388
            try {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   389
                OpenType<?>[] v5Types = new OpenType<?>[V5_ATTRIBUTES.length];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   390
                for (int i = 0; i < v5Types.length; i++) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   391
                    String name = V5_ATTRIBUTES[i];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   392
                    v5Types[i] = name.equals(STACK_TRACE)
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   393
                        ? new ArrayType<>(1, StackTraceElementCompositeData.v5CompositeType())
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   394
                        : threadInfoCompositeType.getType(name);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   395
                }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   396
                return new CompositeType("ThreadInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   397
                                         "JDK 5 ThreadInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   398
                                         V5_ATTRIBUTES,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   399
                                         V5_ATTRIBUTES,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   400
                                         v5Types);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   401
            } catch (OpenDataException e) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   402
                // Should never reach here
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   403
                throw new AssertionError(e);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   404
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   407
        static CompositeType initV6CompositeType(CompositeType threadInfoCompositeType) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   408
            try {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   409
                String[] v6Names = Stream.of(V5_ATTRIBUTES, V6_ATTRIBUTES)
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   410
                    .flatMap(Arrays::stream).toArray(String[]::new);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   411
                OpenType<?>[] v6Types = new OpenType<?>[v6Names.length];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   412
                for (int i = 0; i < v6Names.length; i++) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   413
                    String name = v6Names[i];
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   414
                    OpenType<?> ot = threadInfoCompositeType.getType(name);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   415
                    if (name.equals(STACK_TRACE)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   416
                        ot = new ArrayType<>(1, StackTraceElementCompositeData.v5CompositeType());
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   417
                    } else if (name.equals(LOCKED_MONITORS)) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   418
                        ot = new ArrayType<>(1, MonitorInfoCompositeData.v6CompositeType());
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   419
                    }
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   420
                    v6Types[i] = ot;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                }
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   422
                return new CompositeType("ThreadInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   423
                                         "JDK 6 ThreadInfo",
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   424
                                         v6Names,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   425
                                         v6Names,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   426
                                         v6Types);
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   427
            } catch (OpenDataException e) {
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   428
                // Should never reach here
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   429
                throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 715
diff changeset
   433
    private static final long serialVersionUID = 2464378539119753175L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
}