Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/management/ThreadMXBean/MaxDepthForThreadInfoTest.java
38855 views
1
/*
2
* Copyright (c) 2017, 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 8185003
27
* @library /java/lang/management/ThreadMXBean
28
* @build ThreadDump
29
* @run main MaxDepthForThreadInfoTest
30
* @summary verifies the functionality of ThreadMXBean.dumpAllThreads
31
* and ThreadMXBean.getThreadInfo with maxDepth argument
32
*/
33
34
import java.lang.management.ManagementFactory;
35
import java.lang.management.ThreadInfo;
36
import java.lang.management.ThreadMXBean;
37
38
39
40
public class MaxDepthForThreadInfoTest {
41
42
43
public static void main(String[] Args) {
44
45
com.sun.management.ThreadMXBean tmxb =
46
(com.sun.management.ThreadMXBean)ManagementFactory.getThreadMXBean();
47
48
long[] threadIds = tmxb.getAllThreadIds();
49
50
ThreadInfo[] tinfos = tmxb.getThreadInfo(threadIds, true, true, 0);
51
for (ThreadInfo ti : tinfos) {
52
if (ti.getStackTrace().length > 0) {
53
ThreadDump.printThreadInfo(ti);
54
throw new RuntimeException("more than requested " +
55
"number of frames dumped");
56
}
57
}
58
59
tinfos = tmxb.getThreadInfo(threadIds, true, true, 3);
60
for (ThreadInfo ti : tinfos) {
61
if (ti.getStackTrace().length > 3) {
62
ThreadDump.printThreadInfo(ti);
63
throw new RuntimeException("more than requested " +
64
"number of frames dumped");
65
}
66
}
67
68
try {
69
tmxb.getThreadInfo(threadIds, true, true, -1);
70
throw new RuntimeException("Didn't throw IllegalArgumentException " +
71
"for negative maxdepth value");
72
} catch (IllegalArgumentException e) {
73
System.out.println("Throwed IllegalArgumentException as expected");
74
}
75
76
tinfos = tmxb.dumpAllThreads(true, true, 0);
77
for (ThreadInfo ti : tinfos) {
78
if (ti.getStackTrace().length > 0) {
79
ThreadDump.printThreadInfo(ti);
80
throw new RuntimeException("more than requested " +
81
"number of frames dumped");
82
}
83
}
84
tinfos = tmxb.dumpAllThreads(true, true, 2);
85
for (ThreadInfo ti : tinfos) {
86
if (ti.getStackTrace().length > 2) {
87
ThreadDump.printThreadInfo(ti);
88
throw new RuntimeException("more than requested " +
89
"number of frames dumped");
90
}
91
}
92
93
try {
94
tmxb.dumpAllThreads(true, true, -1);
95
throw new RuntimeException("Didn't throw IllegalArgumentException " +
96
"for negative maxdepth value");
97
} catch (IllegalArgumentException e) {
98
System.out.println("Throwed IllegalArgumentException as expected");
99
}
100
101
System.out.println("Test passed");
102
}
103
}
104
105