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