jdk/test/java/lang/management/CompositeData/ThreadInfoCompositeData.java
author jmanson
Tue, 24 Feb 2015 09:46:29 +0100
changeset 29101 55f7a91aaa32
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
6588467: Add isDaemon() and getPriority() to ThreadInfo Reviewed-by: mchung, sla, dholmes, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
     2
 * Copyright (c) 2004, 2005, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     4982289
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test ThreadInfo.from to return a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          ThreadInfo object. Or throw exception if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          the input CompositeData is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
4347
ab0a9f495844 6907177: Update jdk tests to remove unncessary -source and -target options
darcy
parents: 2
diff changeset
    32
 * @compile OpenTypeConverter.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @build ThreadInfoCompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main ThreadInfoCompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.management.LockInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.management.MonitorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.management.ThreadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class ThreadInfoCompositeData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static StackTraceElement[] ste = new StackTraceElement[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static CompositeData[] steCD = new CompositeData[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static String lockClassName = "myClass";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static int lockIdentityHashCode = 123456;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static String lockName = lockClassName + '@' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        Integer.toHexString(lockIdentityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static LockInfo lockInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        new LockInfo(lockClassName, lockIdentityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static void main(String[] argv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        // A valid CompositeData is passed to ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        createGoodCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        // A valid CompositeData for JDK 5.0 ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // is passed to ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        createV5ThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // An invalid CompositeData is passed to ThreadInfo.from()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        badNameCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        badTypeCompositeData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static void createGoodCompositeData() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        CompositeType ct =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            new CompositeType("MyCompositeType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                              "CompositeType for ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                              validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                              validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                              validItemTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            new CompositeDataSupport(ct,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                     validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                     values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        ThreadInfo info = ThreadInfo.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        checkThreadInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static void createV5ThreadInfo() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        String[] v5ItemNames = new String[NUM_V5_ATTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        OpenType[] v5ItemTypes = new OpenType[NUM_V5_ATTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        Object[] v5ItemValues = new Object[NUM_V5_ATTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        for (int i = 0; i < NUM_V5_ATTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            v5ItemNames[i] = validItemNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            v5ItemTypes[i] = validItemTypes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            v5ItemValues[i] = values[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        CompositeType ct =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            new CompositeType("MyCompositeType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                              "CompositeType for JDK 5.0 ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                              v5ItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                              v5ItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                              v5ItemTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            new CompositeDataSupport(ct,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                     v5ItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                     v5ItemValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        ThreadInfo info = ThreadInfo.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        checkThreadInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   static void checkThreadInfo(ThreadInfo info) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new RuntimeException("Thread Id = " + info.getThreadId() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
               " expected = " + values[THREAD_ID]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (!info.getThreadName().equals(values[THREAD_NAME])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new RuntimeException("Thread Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
               info.getThreadName() + " expected = " + values[THREAD_NAME]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (info.getThreadState() != Thread.State.RUNNABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new RuntimeException("Thread Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
               info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new RuntimeException("blocked time = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
               info.getBlockedTime() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
               " expected = " + values[BLOCKED_TIME]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new RuntimeException("blocked count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
               info.getBlockedCount() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
               " expected = " + values[BLOCKED_COUNT]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            throw new RuntimeException("waited time = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
               info.getWaitedTime() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
               " expected = " + values[WAITED_TIME]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            throw new RuntimeException("waited count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
               info.getWaitedCount() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
               " expected = " + values[WAITED_COUNT]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (!info.getLockName().equals(values[LOCK_NAME])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new RuntimeException("Lock Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
               info.getLockName() + " expected = " + values[LOCK_NAME]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (info.getLockOwnerId() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                ((Long) values[LOCK_OWNER_ID]).longValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
               "LockOwner Id = " + info.getLockOwnerId() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
               " expected = " + values[LOCK_OWNER_ID]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new RuntimeException("LockOwner Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
               info.getLockOwnerName() + " expected = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
               values[LOCK_OWNER_NAME]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   150
        if (!values[DAEMON].equals(info.isDaemon())) {
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   151
            throw new RuntimeException("Daemon = " +
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   152
               info.isDaemon() + " expected = " +
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   153
               values[DAEMON]);
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   154
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        checkStackTrace(info.getStackTrace());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        checkLockInfo(info.getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static void checkStackTrace(StackTraceElement[] s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (ste.length != s.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new RuntimeException("Stack Trace length = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                s.length + " expected = " + ste.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        StackTraceElement s1 = ste[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        StackTraceElement s2 = s[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (!s1.getClassName().equals(s2.getClassName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new RuntimeException("Class name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                s2.getClassName() + " expected = " + s1.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (!s1.getMethodName().equals(s2.getMethodName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new RuntimeException("Method name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                s2.getMethodName() + " expected = " + s1.getMethodName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (!s1.getFileName().equals(s2.getFileName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new RuntimeException("File name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                s2.getFileName() + " expected = " + s1.getFileName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (s1.getLineNumber() != s2.getLineNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new RuntimeException("Line number = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                s2.getLineNumber() + " expected = " + s1.getLineNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private static void checkLockInfo(LockInfo li)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (!li.getClassName().equals(lockInfo.getClassName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new RuntimeException("Class Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                li.getClassName() + " expected = " + lockInfo.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (li.getIdentityHashCode() != lockInfo.getIdentityHashCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            throw new RuntimeException("Class Name = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                li.getIdentityHashCode() + " expected = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                lockInfo.getIdentityHashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static void badNameCompositeData() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        CompositeType ct =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            new CompositeType("MyCompositeType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                              "CompositeType for ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                              badItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                              badItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                              validItemTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            new CompositeDataSupport(ct,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                     badItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                     values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            ThreadInfo info = ThreadInfo.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println("Expected exception: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            "IllegalArgumentException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static void badTypeCompositeData() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        CompositeType ct =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            new CompositeType("MyCompositeType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                              "CompositeType for ThreadInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                              validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                              validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                              badItemTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // patch values[STACK_TRACE] to Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        values[STACK_TRACE] = new Long(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        values[LOCK_INFO] = new Long(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            new CompositeDataSupport(ct,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                     validItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                     values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            ThreadInfo info = ThreadInfo.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            System.out.println("Expected exception: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            "IllegalArgumentException not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static final int THREAD_ID       = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private static final int THREAD_NAME     = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private static final int THREAD_STATE    = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private static final int BLOCKED_TIME    = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private static final int BLOCKED_COUNT   = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private static final int WAITED_TIME     = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static final int WAITED_COUNT    = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private static final int LOCK_NAME       = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private static final int LOCK_OWNER_ID   = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static final int LOCK_OWNER_NAME = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private static final int STACK_TRACE     = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private static final int SUSPENDED       = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static final int IN_NATIVE       = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static final int NUM_V5_ATTS     = 13;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   266
    // JDK 6.0 ThreadInfo attributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static final int LOCK_INFO       = 13;
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   268
    // JDK 9.0 ThreadInfo attributes
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   269
    private static final int DAEMON          = 14;
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   270
    private static final int PRIORITY        = 15;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static final String[] validItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        "threadId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        "threadName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        "threadState",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        "blockedTime",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        "blockedCount",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        "waitedTime",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        "waitedCount",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        "lockName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        "lockOwnerId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        "lockOwnerName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        "stackTrace",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        "suspended",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        "inNative",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        "lockInfo",
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   287
        "daemon",
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   288
        "priority",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static OpenType[] validItemTypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        null,  // ArrayType for StackTraceElement[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        SimpleType.BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        SimpleType.BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        null,  // CompositeType for LockInfo
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   306
        SimpleType.BOOLEAN,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   307
        SimpleType.INTEGER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private static Object[] values = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        new Long(100),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        "FooThread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        "RUNNABLE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        new Long(200),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        new Long(10),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        new Long(300),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        new Long(20),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        lockName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        new Long(99),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        "BarThread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        steCD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        new Boolean(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        new Boolean(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        null, // To be initialized to lockInfoCD
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   325
        new Boolean(false),
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   326
        Thread.NORM_PRIORITY,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static final String[] steItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        "className",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        "methodName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        "fileName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        "lineNumber",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        "nativeMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    private static final String[] lockInfoItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        "className",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        "identityHashCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // create stack trace element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        ste[0] = new StackTraceElement("FooClass", "getFoo", "Foo.java", 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // initialize the ste[0] and values and validItemTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            CompositeType steCType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                OpenTypeConverter.toOpenType(StackTraceElement.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            validItemTypes[STACK_TRACE] = new ArrayType(1, steCType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            final Object[] steValue = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                ste[0].getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                ste[0].getMethodName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                ste[0].getFileName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                new Integer(ste[0].getLineNumber()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                new Boolean(ste[0].isNativeMethod()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            steCD[0] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                new CompositeDataSupport(steCType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                         steItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                         steValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            CompositeType lockInfoCType = (CompositeType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                OpenTypeConverter.toOpenType(LockInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            validItemTypes[LOCK_INFO] = lockInfoCType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            final Object[] lockInfoValue = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                lockInfo.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                lockInfo.getIdentityHashCode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            values[LOCK_INFO] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                new CompositeDataSupport(lockInfoCType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                         lockInfoItemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                         lockInfoValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private static final String[] badItemNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        "threadId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        "threadName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        "threadState",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        "blockedTime",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        "blockedCount",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        "waitedTime",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        "waitedCount",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        "lockName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        "lockOwnerId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        "lockOwnerName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        "BadStackTrace", // bad item name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        "suspended",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        "inNative",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        "lockInfo",
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   398
        "daemon",
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   399
        "priority",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private static final OpenType[] badItemTypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        SimpleType.LONG,  // bad type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        SimpleType.BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        SimpleType.BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        SimpleType.LONG,  // bad type
29101
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   416
        SimpleType.BOOLEAN,
55f7a91aaa32 6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents: 5506
diff changeset
   417
        SimpleType.INTEGER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}