Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 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
* @summary Test deadlock detection
27
* @requires vm.hasSA
28
* @library /test/lib
29
* @modules java.base/jdk.internal.misc
30
* @modules java.management
31
* @run main DeadlockDetectionTest
32
*/
33
34
import java.util.stream.Collectors;
35
36
import jdk.test.lib.apps.LingeredApp;
37
import jdk.test.lib.apps.LingeredAppWithDeadlock;
38
import jdk.test.lib.JDKToolLauncher;
39
import jdk.test.lib.process.OutputAnalyzer;
40
import jdk.test.lib.process.ProcessTools;
41
import jdk.test.lib.SA.SATestUtils;
42
import jdk.test.lib.Utils;
43
44
import jtreg.SkippedException;
45
46
public class DeadlockDetectionTest {
47
48
private static LingeredAppWithDeadlock theApp = null;
49
50
private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
51
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
52
launcher.addVMArgs(Utils.getTestJavaOpts());
53
launcher.addToolArg("jstack");
54
if (toolArgs != null) {
55
for (String toolArg : toolArgs) {
56
launcher.addToolArg(toolArg);
57
}
58
}
59
60
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
61
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" ")));
62
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
63
System.out.println(output.getOutput());
64
65
return output;
66
}
67
68
public static void main(String[] args) throws Exception {
69
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
70
System.out.println("Starting DeadlockDetectionTest");
71
72
if (!LingeredApp.isLastModifiedWorking()) {
73
// Exact behaviour of the test depends on operating system and the test nature,
74
// so just print the warning and continue
75
System.err.println("Warning! Last modified time doesn't work.");
76
}
77
78
try {
79
theApp = new LingeredAppWithDeadlock();
80
LingeredApp.startApp(theApp, "-XX:+UsePerfData");
81
OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid()));
82
System.out.println(output.getOutput());
83
84
if (output.getExitValue() == 3) {
85
throw new SkippedException("Test can't run for some reason");
86
} else {
87
output.shouldHaveExitValue(0);
88
output.shouldContain("Found a total of 1 deadlock.");
89
}
90
} finally {
91
LingeredApp.stopApp(theApp);
92
}
93
}
94
}
95
96