Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/management/ThreadMXBean/ThreadInfoArray.java
38821 views
1
/*
2
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 5058327 8074368
27
* @summary Tests the correct behaviour of getThreadInfo(long[]) for non-existent
28
* thread IDs and the empty thread id array.
29
*
30
* @author Mandy Chung
31
* @author Jaroslav Bachorik
32
*
33
* @build ThreadInfoArray
34
* @run main ThreadInfoArray
35
*/
36
37
import java.lang.management.*;
38
import javax.management.*;
39
import static java.lang.management.ManagementFactory.*;
40
41
public class ThreadInfoArray {
42
public static void main(String[] argv) throws Exception {
43
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
44
ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
45
46
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
47
ThreadMXBean proxy = newPlatformMXBeanProxy(mbs,
48
on.toString(),
49
ThreadMXBean.class);
50
51
checkNullElement(mbean, proxy, mbs, on);
52
checkEmptyArray(mbean, proxy, mbs, on);
53
System.out.println("Test passed");
54
}
55
56
private static void checkNullElement(ThreadMXBean mbean, ThreadMXBean proxy,
57
MBeanServer mbs, ObjectName on)
58
throws Exception {
59
System.out.println("--- Check null element");
60
// ID for a new thread
61
long [] ids = {new Thread().getId()};
62
// direct call
63
ThreadInfo[] tinfos = mbean.getThreadInfo(ids);
64
65
if (tinfos[0] != null) {
66
throw new RuntimeException("TEST FAILED: " +
67
"Expected to have a null element");
68
}
69
70
// call getThreadInfo through MBeanServer
71
Object[] params = {ids};
72
String[] sigs = {"[J"};
73
Object[] result = (Object[]) mbs.invoke(on, "getThreadInfo", params, sigs);
74
75
if (result[0] != null) {
76
throw new RuntimeException("TEST FAILED: " +
77
"Expected to have a null element via MBeanServer");
78
}
79
80
// call getThreadInfo through proxy
81
tinfos = proxy.getThreadInfo(ids);
82
if (tinfos[0] != null) {
83
throw new RuntimeException("TEST FAILED: " +
84
"Expected to have a null element");
85
}
86
System.out.println("--- PASSED");
87
}
88
89
private static void checkEmptyArray(ThreadMXBean mbean, ThreadMXBean proxy,
90
MBeanServer mbs, ObjectName on)
91
throws Exception {
92
System.out.println("--- Check empty TID array");
93
94
long[] ids = new long[0];
95
// direct call
96
assertEmptyArray(mbean.getThreadInfo(ids), "Expected empty ThreadInfo array");
97
assertEmptyArray(mbean.getThreadInfo(ids, 1), "Expected empty ThreadInfo array");
98
assertEmptyArray(mbean.getThreadInfo(ids, true, true), "Expected empty ThreadInfo array");
99
100
// call getThreadInfo through MBeanServer
101
assertEmptyArray(
102
(Object[]) mbs.invoke(
103
on, "getThreadInfo", new Object[]{ids}, new String[]{"[J"}
104
),
105
"Expected empty ThreadInfo array via MBeanServer"
106
);
107
assertEmptyArray(
108
(Object[]) mbs.invoke(
109
on, "getThreadInfo", new Object[]{ids, 1},
110
new String[]{"[J", "int"}
111
),
112
"Expected empty ThreadInfo array via MBeanServer"
113
);
114
assertEmptyArray(
115
(Object[]) mbs.invoke(
116
on, "getThreadInfo", new Object[]{ids, true, true},
117
new String[]{"[J", "boolean", "boolean"}
118
),
119
"Expected empty ThreadInfo array via MBeanServer"
120
);
121
122
// call getThreadInfo through proxy
123
assertEmptyArray(proxy.getThreadInfo(ids), "Expected empty ThreadInfo array");
124
assertEmptyArray(proxy.getThreadInfo(ids, 1), "Expected empty ThreadInfo array");
125
assertEmptyArray(proxy.getThreadInfo(ids, true, true), "Expected empty ThreadInfo array");
126
System.out.println("--- PASSED");
127
}
128
129
private static void assertEmptyArray(Object[] arr, String message) throws Exception {
130
if (arr.length > 0) {
131
throw new RuntimeException("TEST FAILED: " + message);
132
}
133
}
134
}
135
136