src/java.management/share/classes/java/lang/management/ThreadInfo.java
author mgronlun
Mon, 28 Oct 2019 18:43:04 +0100
branchJEP-349-branch
changeset 58823 6a21dba79b81
parent 55120 b0513c833960
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 49077
diff changeset
     2
 * Copyright (c) 2003, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 java.lang.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
    28
import javax.management.openmbean.ArrayType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.openmbean.CompositeData;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    30
import sun.management.ManagementFactoryHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.management.ThreadInfoCompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import static java.lang.Thread.State.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    35
 * Thread information. {@code ThreadInfo} contains the information
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * about a thread including:
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 49077
diff changeset
    37
 * <h2>General thread information</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   <li>Thread ID.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *   <li>Name of the thread.</li>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    41
 *   <li>Whether a thread is a daemon thread</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 49077
diff changeset
    44
 * <h2>Execution information</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   <li>Thread state.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   <li>The object upon which the thread is blocked due to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *       <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *       <li>waiting to enter a synchronization block/method, or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       <li>waiting to be notified in a {@link Object#wait Object.wait} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *           or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *       <li>parking due to a {@link java.util.concurrent.locks.LockSupport#park
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *           LockSupport.park} call.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *       </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <li>The ID of the thread that owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *       that the thread is blocked.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   <li>Stack trace of the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   <li>List of object monitors locked by the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <li>List of <a href="LockInfo.html#OwnableSynchronizer">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *       ownable synchronizers</a> locked by the thread.</li>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    62
 *   <li>Thread priority</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 49077
diff changeset
    65
 * <h3><a id="SyncStats">Synchronization Statistics</a></h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <li>The number of times that the thread has blocked for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *       synchronization or waited for notification.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   <li>The accumulated elapsed time that the thread has blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *       for synchronization or waited for notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *       since {@link ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *       thread contention monitoring}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *       was enabled. Some Java virtual machine implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *       may not support this.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *       {@link ThreadMXBean#isThreadContentionMonitoringSupported()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *       method can be used to determine if a Java virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *       supports this.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>This thread information class is designed for use in monitoring of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * the system, not for synchronization control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 49077
diff changeset
    83
 * <h3>MXBean Mapping</h3>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
    84
 * {@code ThreadInfo} is mapped to a {@link CompositeData CompositeData}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * with attributes as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * the {@link #from from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @see ThreadMXBean#getThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see ThreadMXBean#dumpAllThreads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
public class ThreadInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private String       threadName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private long         threadId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private long         blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private long         blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private long         waitedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private long         waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private LockInfo     lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String       lockName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private long         lockOwnerId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private String       lockOwnerName;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   106
    private boolean      daemon;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private boolean      inNative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private boolean      suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private Thread.State threadState;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   110
    private int          priority;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private StackTraceElement[] stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private MonitorInfo[]       lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private LockInfo[]          lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static MonitorInfo[] EMPTY_MONITORS = new MonitorInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static LockInfo[] EMPTY_SYNCS = new LockInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Constructor of ThreadInfo created by the JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param stackTrace    Thread stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                       long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                       long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                       StackTraceElement[] stackTrace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        initialize(t, state, lockObj, lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                   blockedCount, blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                   waitedCount, waitedTime, stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                   EMPTY_MONITORS, EMPTY_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Constructor of ThreadInfo created by the JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * for {@link ThreadMXBean#getThreadInfo(long[],boolean,boolean)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * and {@link ThreadMXBean#dumpAllThreads}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param stackTrace    Thread stack trace
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   154
     * @param monitors      List of locked monitors
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   155
     * @param stackDepths   List of stack depths
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   156
     * @param synchronizers List of locked synchronizers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                       long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                       long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                       StackTraceElement[] stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                       Object[] monitors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                       int[] stackDepths,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                       Object[] synchronizers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int numMonitors = (monitors == null ? 0 : monitors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        MonitorInfo[] lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (numMonitors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            lockedMonitors = EMPTY_MONITORS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            lockedMonitors = new MonitorInfo[numMonitors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            for (int i = 0; i < numMonitors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                Object lock = monitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                String className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                int identityHashCode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                int depth = stackDepths[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                StackTraceElement ste = (depth >= 0 ? stackTrace[depth]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                                    : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                lockedMonitors[i] = new MonitorInfo(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                                    identityHashCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                                    depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                                    ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        int numSyncs = (synchronizers == null ? 0 : synchronizers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        LockInfo[] lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (numSyncs == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            lockedSynchronizers = EMPTY_SYNCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            lockedSynchronizers = new LockInfo[numSyncs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            for (int i = 0; i < numSyncs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                Object lock = synchronizers[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                String className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                int identityHashCode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                lockedSynchronizers[i] = new LockInfo(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                                      identityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        initialize(t, state, lockObj, lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                   blockedCount, blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                   waitedCount, waitedTime, stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                   lockedMonitors, lockedSynchronizers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Initialize ThreadInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param stackTrace    Thread stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param lockedMonitors List of locked monitors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param lockedSynchronizers List of locked synchronizers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    private void initialize(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                            StackTraceElement[] stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                            MonitorInfo[] lockedMonitors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                            LockInfo[] lockedSynchronizers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        this.threadId = t.getId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        this.threadName = t.getName();
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   229
        this.threadState = ManagementFactoryHelper.toThreadState(state);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   230
        this.suspended = ManagementFactoryHelper.isThreadSuspended(state);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   231
        this.inNative = ManagementFactoryHelper.isThreadRunningNative(state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this.blockedCount = blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        this.blockedTime = blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        this.waitedCount = waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        this.waitedTime = waitedTime;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   236
        this.daemon = t.isDaemon();
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   237
        this.priority = t.getPriority();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (lockObj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            this.lock = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            this.lockName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            this.lock = new LockInfo(lockObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            this.lockName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                lock.getClassName() + '@' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    Integer.toHexString(lock.getIdentityHashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (lockOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            this.lockOwnerId = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            this.lockOwnerName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            this.lockOwnerId = lockOwner.getId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            this.lockOwnerName = lockOwner.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (stackTrace == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            this.stackTrace = NO_STACK_TRACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            this.stackTrace = stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        this.lockedMonitors = lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        this.lockedSynchronizers = lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /*
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   265
     * Constructs a {@code ThreadInfo} object from a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * {@link CompositeData CompositeData}.
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
     * @throws IllegalArgumentException if the given CompositeData does not
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   269
     * contain all of the attributes defined for ThreadInfo of version <= N.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   270
     *
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   271
     * @see ThreadInfo#from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private ThreadInfo(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        ThreadInfoCompositeData ticd = ThreadInfoCompositeData.getInstance(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        threadId = ticd.threadId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        threadName = ticd.threadName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        blockedTime = ticd.blockedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        blockedCount = ticd.blockedCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        waitedTime = ticd.waitedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        waitedCount = ticd.waitedCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        lockName = ticd.lockName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        lockOwnerId = ticd.lockOwnerId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        lockOwnerName = ticd.lockOwnerName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        threadState = ticd.threadState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        suspended = ticd.suspended();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        inNative = ticd.inNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        stackTrace = ticd.stackTrace();
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   289
        lock = ticd.lockInfo();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   290
        lockedMonitors = ticd.lockedMonitors();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   291
        lockedSynchronizers = ticd.lockedSynchronizers();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   292
        daemon = ticd.isDaemon();
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   293
        priority = ticd.getPriority();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   297
     * Returns the ID of the thread associated with this {@code ThreadInfo}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return the ID of the associated thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public long getThreadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return threadId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   306
     * Returns the name of the thread associated with this {@code ThreadInfo}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return the name of the associated thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public String getThreadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return threadName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   315
     * Returns the state of the thread associated with this {@code ThreadInfo}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   317
     * @return {@code Thread.State} of the associated thread.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public Thread.State getThreadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         return threadState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Returns the approximate accumulated elapsed time (in milliseconds)
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   325
     * that the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * has blocked to enter or reenter a monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * since thread contention monitoring is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * I.e. the total accumulated time the thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * {@link java.lang.Thread.State#BLOCKED BLOCKED} state since thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * contention monitoring was last enabled.
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   331
     * This method returns {@code -1} if thread contention monitoring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <p>The Java virtual machine may measure the time with a high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * resolution timer.  This statistic is reset when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * the thread contention monitoring is reenabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return the approximate accumulated elapsed time in milliseconds
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   339
     * that a thread entered the {@code BLOCKED} state;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   340
     * {@code -1} if thread contention monitoring is disabled.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @throws java.lang.UnsupportedOperationException if the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * virtual machine does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see ThreadMXBean#isThreadContentionMonitoringSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public long getBlockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Returns the total number of times that
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   354
     * the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * blocked to enter or reenter a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * I.e. the number of times a thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * {@link java.lang.Thread.State#BLOCKED BLOCKED} state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return the total number of times that the thread
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   360
     * entered the {@code BLOCKED} state.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public long getBlockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Returns the approximate accumulated elapsed time (in milliseconds)
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   368
     * that the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * has waited for notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * since thread contention monitoring is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * I.e. the total accumulated time the thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * since thread contention monitoring is enabled.
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   375
     * This method returns {@code -1} if thread contention monitoring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <p>The Java virtual machine may measure the time with a high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * resolution timer.  This statistic is reset when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * the thread contention monitoring is reenabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return the approximate accumulated elapsed time in milliseconds
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   383
     * that a thread has been in the {@code WAITING} or
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   384
     * {@code TIMED_WAITING} state;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   385
     * {@code -1} if thread contention monitoring is disabled.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @throws java.lang.UnsupportedOperationException if the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * virtual machine does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see ThreadMXBean#isThreadContentionMonitoringSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public long getWaitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return waitedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Returns the total number of times that
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   399
     * the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * waited for notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * I.e. the number of times that a thread has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return the total number of times that the thread
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   406
     * was in the {@code WAITING} or {@code TIMED_WAITING} state.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public long getWaitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   413
     * Returns the {@code LockInfo} of an object for which
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   414
     * the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * is blocked waiting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * A thread can be blocked waiting for one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <li>an object monitor to be acquired for entering or reentering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *     a synchronization block/method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *     <br>The thread is in the {@link java.lang.Thread.State#BLOCKED BLOCKED}
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   421
     *     state waiting to enter the {@code synchronized} statement
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *     or method.
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 21278
diff changeset
   423
     *     </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <li>an object monitor to be notified by another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *     <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *     or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *     due to a call to the {@link Object#wait Object.wait} method.
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 21278
diff changeset
   428
     *     </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <li>a synchronization object responsible for the thread parking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *     <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *     or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *     due to a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *     {@link java.util.concurrent.locks.LockSupport#park(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *     LockSupport.park} method.  The synchronization object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *     is the object returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *     {@link java.util.concurrent.locks.LockSupport#getBlocker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *     LockSupport.getBlocker} method. Typically it is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *     <a href="LockInfo.html#OwnableSynchronizer"> ownable synchronizer</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *     or a {@link java.util.concurrent.locks.Condition Condition}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   442
     * <p>This method returns {@code null} if the thread is not in any of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * the above conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   445
     * @return {@code LockInfo} of an object for which the thread
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   446
     *         is blocked waiting if any; {@code null} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public LockInfo getLockInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Returns the {@link LockInfo#toString string representation}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * of an object for which the thread associated with this
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   456
     * {@code ThreadInfo} is blocked waiting.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * getLockInfo().toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   463
     * <p>This method will return {@code null} if this thread is not blocked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @return the string representation of the object on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * the thread is blocked if any;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   468
     * {@code null} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public String getLockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return lockName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Returns the ID of the thread which owns the object
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   478
     * for which the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * is blocked waiting.
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   480
     * This method will return {@code -1} if this thread is not blocked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return the thread ID of the owner thread of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * this thread is blocked on;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   485
     * {@code -1} if this thread is not blocked
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18799
diff changeset
   486
     * or if the object is not owned by any thread.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public long getLockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return lockOwnerId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Returns the name of the thread which owns the object
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   496
     * for which the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * is blocked waiting.
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   498
     * This method will return {@code null} if this thread is not blocked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @return the name of the thread that owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * this thread is blocked on;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   503
     * {@code null} if this thread is not blocked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    public String getLockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return lockOwnerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Returns the stack trace of the thread
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   514
     * associated with this {@code ThreadInfo}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * If no stack trace was requested for this thread info, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * If the returned array is of non-zero length then the first element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * the array represents the top of the stack, which is the most recent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * method invocation in the sequence.  The last element of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * represents the bottom of the stack, which is the least recent method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * invocation in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <p>Some Java virtual machines may, under some circumstances, omit one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * or more stack frames from the stack trace.  In the extreme case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * a virtual machine that has no stack trace information concerning
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   526
     * the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * is permitted to return a zero-length array from this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   529
     * @return an array of {@code StackTraceElement} objects of the thread.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public StackTraceElement[] getStackTrace() {
42106
90fc3dc00723 8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents: 40184
diff changeset
   532
        return stackTrace.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   536
     * Tests if the thread associated with this {@code ThreadInfo}
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   537
     * is suspended.  This method returns {@code true} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * {@link Thread#suspend} has been called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   540
     * @return {@code true} if the thread is suspended;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   541
     *         {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public boolean isSuspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         return suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   548
     * Tests if the thread associated with this {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * is executing native code via the Java Native Interface (JNI).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * The JNI native code does not include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * the virtual machine support code or the compiled native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * code generated by the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   554
     * @return {@code true} if the thread is executing native code;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   555
     *         {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public boolean isInNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         return inNative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   562
     * Tests if the thread associated with this {@code ThreadInfo} is
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   563
     * a {@linkplain Thread#isDaemon daemon thread}.
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   564
     *
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   565
     * @return {@code true} if the thread is a daemon thread,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   566
     *         {@code false} otherwise.
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   567
     * @see Thread#isDaemon
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29101
diff changeset
   568
     * @since 9
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   569
     */
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   570
    public boolean isDaemon() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   571
         return daemon;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   572
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   573
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   574
    /**
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   575
     * Returns the {@linkplain Thread#getPriority() thread priority} of the
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   576
     * thread associated with this {@code ThreadInfo}.
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   577
     *
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   578
     * @return The priority of the thread associated with this
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   579
     *         {@code ThreadInfo}.
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29101
diff changeset
   580
     * @since 9
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   581
     */
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   582
    public int getPriority() {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   583
         return priority;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   584
    }
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   585
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   586
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Returns a string representation of this thread info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * The format of this string depends on the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * The returned string will typically include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * the {@linkplain #getThreadName thread name},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the {@linkplain #getThreadId thread ID},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * its {@linkplain #getThreadState state},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * and a {@linkplain #getStackTrace stack trace} if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @return a string representation of this thread info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" +
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   599
                                             (daemon ? " daemon" : "") +
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   600
                                             " prio=" + priority +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                             " Id=" + getThreadId() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                                             getThreadState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (getLockName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            sb.append(" on " + getLockName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (getLockOwnerName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            sb.append(" owned by \"" + getLockOwnerName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                      "\" Id=" + getLockOwnerId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (isSuspended()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            sb.append(" (suspended)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (isInNative()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            sb.append(" (in native)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            sb.append("\tat " + ste.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            if (i == 0 && getLockInfo() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                Thread.State ts = getThreadState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                switch (ts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    case BLOCKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                        sb.append("\t-  blocked on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    case WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                        sb.append("\t-  waiting on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    case TIMED_WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                        sb.append("\t-  waiting on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            for (MonitorInfo mi : lockedMonitors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                if (mi.getLockedStackDepth() == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    sb.append("\t-  locked " + mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
       if (i < stackTrace.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
           sb.append("\t...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
           sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
       LockInfo[] locks = getLockedSynchronizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
       if (locks.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
           sb.append("\n\tNumber of locked synchronizers = " + locks.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
           sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
           for (LockInfo li : locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
               sb.append("\t- " + li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
               sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
       sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
       return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    private static final int MAX_FRAMES = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   668
     * Returns a {@code ThreadInfo} object represented by the
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   669
     * given {@code CompositeData}.
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   670
     *
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   671
     * <a id="attributes"></a>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   672
     * A {@code CompositeData} representing a {@code ThreadInfo} of
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   673
     * version <em>N</em> must contain all of the attributes defined
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   674
     * in version &le; <em>N</em> unless specified otherwise.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   675
     * The same rule applies the composite type of the given
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   676
     * {@code CompositeData} and transitively to attributes whose
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   677
     * {@linkplain CompositeData#getCompositeType() type} or
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   678
     * {@linkplain ArrayType#getElementOpenType() component type} is
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   679
     * {@code CompositeType}.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   680
     * <p>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   681
     * A {@code CompositeData} representing {@code ThreadInfo} of
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   682
     * version <em>N</em> contains {@code "stackTrace"} attribute and
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   683
     * {@code "lockedMonitors"} attribute representing
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   684
     * an array of {@code StackTraceElement} and
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   685
     * an array of {@link MonitorInfo} respectively
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   686
     * and their types are of version <em>N</em>.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   687
     * The {@code "lockedStackFrame"} attribute in
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   688
     * {@link MonitorInfo#from(CompositeData) MonitorInfo}'s composite type
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   689
     * must represent {@code StackTraceElement} of the same version <em>N</em>.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   690
     * Otherwise, this method will throw {@code IllegalArgumentException}.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   691
     *
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   692
     * <table class="striped" style="margin-left:2em">
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   693
     * <caption style="display:none">The attributes and their types for ThreadInfo's composite data</caption>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   694
     * <thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   696
     *   <th scope="col">Attribute Name</th>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   697
     *   <th scope="col">Type</th>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   698
     *   <th scope="col">Since</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * </tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   700
     * </thead>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   701
     * <tbody style="text-align:left">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   703
     *   <th scope="row">threadId</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   704
     *   <td>{@code java.lang.Long}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   705
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   708
     *   <th scope="row">threadName</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   709
     *   <td>{@code java.lang.String}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   710
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   713
     *   <th scope="row">threadState</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   714
     *   <td>{@code java.lang.String}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   715
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   718
     *   <th scope="row">suspended</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   719
     *   <td>{@code java.lang.Boolean}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   720
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   723
     *   <th scope="row">inNative</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   724
     *   <td>{@code java.lang.Boolean}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   725
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   728
     *   <th scope="row">blockedCount</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   729
     *   <td>{@code java.lang.Long}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   730
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   733
     *   <th scope="row">blockedTime</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   734
     *   <td>{@code java.lang.Long}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   735
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   738
     *   <th scope="row">waitedCount</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   739
     *   <td>{@code java.lang.Long}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   740
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   743
     *   <th scope="row">waitedTime</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   744
     *   <td>{@code java.lang.Long}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   745
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   746
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   747
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   748
     *   <th scope="row">lockName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   749
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   750
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   751
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   752
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   753
     *   <th scope="row">lockOwnerId</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   754
     *   <td>{@code java.lang.Long}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   755
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   756
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   757
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   758
     *   <th scope="row">lockOwnerName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   759
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   760
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   761
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   762
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   763
     *   <th scope="row"><a id="StackTrace">stackTrace</a></th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   764
     *   <td>{@code javax.management.openmbean.CompositeData[]}, each element
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   765
     *       is a {@code CompositeData} representing {@code StackTraceElement}
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   766
     *       as specified <a href="#stackTraceElement">below</a>.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   767
     *   </td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   768
     *   <td>5</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   771
     *   <th scope="row">lockInfo</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   772
     *   <td>{@code javax.management.openmbean.CompositeData}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *       - the mapped type for {@link LockInfo} as specified in the
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   774
     *         {@link LockInfo#from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *       <p>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   776
     *       If the given {@code CompositeData} does not contain this attribute,
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   777
     *       the {@code LockInfo} object will be constructed from
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   778
     *       the value of the {@code lockName} attribute.</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   779
     *    <td>6</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   782
     *   <th scope="row">lockedMonitors</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   783
     *   <td>{@code javax.management.openmbean.CompositeData[]}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *       whose element type is the mapped type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *       {@link MonitorInfo} as specified in the
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   786
     *       {@link MonitorInfo#from MonitorInfo.from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *       <p>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   788
     *       If the given {@code CompositeData} does not contain this attribute,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   789
     *       this attribute will be set to an empty array.</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   790
     *    <td>6</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   793
     *   <th scope="row">lockedSynchronizers</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   794
     *   <td>{@code javax.management.openmbean.CompositeData[]}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *       whose element type is the mapped type for
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   796
     *       {@link LockInfo} as specified in the {@link LockInfo#from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *       <p>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   798
     *       If the given {@code CompositeData} does not contain this attribute,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   799
     *       this attribute will be set to an empty array.</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   800
     *    <td>6</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * </tr>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   802
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   803
     *   <th scope="row">daemon</th>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   804
     *   <td>{@code java.lang.Boolean}
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   805
     *       <p>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   806
     *       If the given {@code CompositeData} does not contain this attribute,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   807
     *       this attribute will be set to {@code false}.</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   808
     *    <td>9</td>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   809
     * </tr>
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   810
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   811
     *   <th scope="row">priority</th>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   812
     *   <td>{@code java.lang.Integer}
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   813
     *       <p>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   814
     *       If the given {@code CompositeData} does not contain this attribute,
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   815
     *       This attribute will be set to {@link Thread#NORM_PRIORITY}.</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   816
     *    <td>9</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   817
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   818
     * </tbody>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   819
     * </table>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   820
     *
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   821
     * <a id="stackTraceElement">A {@code CompositeData} representing
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   822
     * {@code StackTraceElement}</a> of version <em>N</em> must contain
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   823
     * all of the attributes defined in version &le; <em>N</em>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   824
     * unless specified otherwise.
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   825
     *
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   826
     * <table class="striped" style="margin-left:2em">
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   827
     * <caption style="display:none">The attributes and their types for StackTraceElement's composite data</caption>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   828
     * <thead style="text-align:center">
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   829
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   830
     *   <th scope="col">Attribute Name</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   831
     *   <th scope="col">Type</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   832
     *   <th scope="col">Since</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   833
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   834
     * </thead>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   835
     * <tbody style="text-align:left">
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   836
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   837
     *   <th scope="row">classLoaderName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   838
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   839
     *   <td>9</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   840
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   841
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   842
     *   <th scope="row">moduleName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   843
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   844
     *   <td>9</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   845
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   846
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   847
     *   <th scope="row">moduleVersion</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   848
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   849
     *   <td>9</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   850
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   851
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   852
     *   <th scope="row">className</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   853
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   854
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   855
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   856
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   857
     *   <th scope="row">methodName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   858
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   859
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   860
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   861
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   862
     *   <th scope="row">fileName</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   863
     *   <td>{@code java.lang.String}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   864
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   865
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   866
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   867
     *   <th scope="row">lineNumber</th>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   868
     *   <td>{@code java.lang.Integer}</td>
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   869
     *   <td>5</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   870
     * </tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   871
     * <tr>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   872
     *   <th scope="row">nativeMethod</th>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   873
     *   <td>{@code java.lang.Boolean}</td>
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   874
     *   <td>5</td>
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   875
     * </tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   876
     * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   879
     * @param cd {@code CompositeData} representing a {@code ThreadInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
49077
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   881
     * @throws IllegalArgumentException if the given {@code cd} and
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   882
     *         its composite type does not contain all of
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   883
     *         <a href="#attributes">the attributes</a> defined for a
b1c42b3cd19b 8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents: 47216
diff changeset
   884
     *         {@code ThreadInfo} of a specific runtime version.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   886
     * @return a {@code ThreadInfo} object represented
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   887
     *         by {@code cd} if {@code cd} is not {@code null};
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   888
     *         {@code null} otherwise.
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 42106
diff changeset
   889
     *
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 42106
diff changeset
   890
     * @revised 9
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 42106
diff changeset
   891
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public static ThreadInfo from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if (cd instanceof ThreadInfoCompositeData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            return ((ThreadInfoCompositeData) cd).getThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            return new ThreadInfo(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * Returns an array of {@link MonitorInfo} objects, each of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * represents an object monitor currently locked by the thread
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   908
     * associated with this {@code ThreadInfo}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * If no locked monitor was requested for this thread info or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * no monitor is locked by the thread, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   913
     * @return an array of {@code MonitorInfo} objects representing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *         the object monitors locked by the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    public MonitorInfo[] getLockedMonitors() {
42106
90fc3dc00723 8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents: 40184
diff changeset
   919
        return lockedMonitors.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Returns an array of {@link LockInfo} objects, each of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * represents an <a href="LockInfo.html#OwnableSynchronizer">ownable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * synchronizer</a> currently locked by the thread associated with
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   926
     * this {@code ThreadInfo}.  If no locked synchronizer was
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * requested for this thread info or no synchronizer is locked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * the thread, this method will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 25859
diff changeset
   930
     * @return an array of {@code LockInfo} objects representing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *         the ownable synchronizers locked by the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    public LockInfo[] getLockedSynchronizers() {
42106
90fc3dc00723 8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents: 40184
diff changeset
   936
        return lockedSynchronizers.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    private static final StackTraceElement[] NO_STACK_TRACE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        new StackTraceElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
}