Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jhsdb/JStackStressTest.java
41149 views
1
/*
2
* Copyright (c) 2021, 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 8262271
27
* @requires vm.hasSA
28
* @library /test/lib
29
* @run main/timeout=240 JStackStressTest
30
*/
31
32
import java.io.IOException;
33
import java.io.OutputStream;
34
35
import jdk.test.lib.JDKToolLauncher;
36
import jdk.test.lib.JDKToolFinder;
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.process.ProcessTools;
39
import jdk.test.lib.SA.SATestUtils;
40
import jdk.test.lib.Utils;
41
42
public class JStackStressTest {
43
44
static Process jShellProcess;
45
46
public static void testjstack() throws IOException {
47
launchJshell();
48
long jShellPID = jShellProcess.pid();
49
OutputAnalyzer jshellOutput = new OutputAnalyzer(jShellProcess);
50
51
try {
52
// Do 4 jstacks on the jshell process as it starts up
53
for (int i = 1; i <= 4; i++) {
54
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
55
launcher.addVMArgs(Utils.getTestJavaOpts());
56
launcher.addToolArg("jstack");
57
launcher.addToolArg("--pid=" + Long.toString(jShellPID));
58
59
System.out.println("###### Starting jstack iteration " + i + " against " + jShellPID);
60
long startTime = System.currentTimeMillis();
61
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
62
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
63
System.out.println("jhsdb jstack stdout:");
64
System.out.println(output.getStdout());
65
System.out.println("jhsdb jstack stderr:");
66
System.out.println(output.getStderr());
67
long elapsedTime = System.currentTimeMillis() - startTime;
68
System.out.println("###### End of all output for iteration " + i +
69
" which took " + elapsedTime + "ms");
70
output.shouldHaveExitValue(0);
71
// This will detect most SA failures, including during the attach.
72
output.shouldNotMatch("^sun.jvm.hotspot.debugger.DebuggerException:.*$");
73
// This will detect unexpected exceptions, like NPEs and asserts, that are caught
74
// by sun.jvm.hotspot.tools.Tool.execute().
75
output.shouldNotMatch("^Error: .*$");
76
}
77
} catch (Exception ex) {
78
throw new RuntimeException("Test ERROR " + ex, ex);
79
} finally {
80
try (OutputStream out = jShellProcess.getOutputStream()) {
81
out.write("/exit\n".getBytes());
82
out.flush();
83
}
84
try {
85
jShellProcess.waitFor(); // jshell should exit quickly
86
} catch (InterruptedException e) {
87
}
88
System.out.println("jshell Output: " + jshellOutput.getOutput());
89
}
90
}
91
92
public static void launchJshell() throws IOException {
93
System.out.println("Starting Jshell");
94
long startTime = System.currentTimeMillis();
95
try {
96
ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jshell"));
97
jShellProcess = ProcessTools.startProcess("JShell", pb);
98
} catch (Exception ex) {
99
throw new RuntimeException("Test ERROR " + ex, ex);
100
}
101
}
102
103
public static void main(String[] args) throws Exception {
104
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
105
testjstack();
106
107
// The test throws RuntimeException on error.
108
// IOException is thrown if Jshell can't start because of some bad
109
// environment condition
110
System.out.println("Test PASSED");
111
}
112
}
113
114