Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java
41149 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2019, Red Hat Inc. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
import java.util.Arrays;
26
import java.util.List;
27
import java.util.stream.Collectors;
28
29
import jdk.test.lib.JDKToolLauncher;
30
import jdk.test.lib.SA.SATestUtils;
31
import jdk.test.lib.Utils;
32
import jdk.test.lib.apps.LingeredApp;
33
import jdk.test.lib.process.OutputAnalyzer;
34
35
/**
36
* @test
37
* @bug 8196969
38
* @requires vm.hasSA
39
* @requires vm.opt.DeoptimizeALot != true
40
* @library /test/lib
41
* @run main/othervm ClhsdbJstackXcompStress
42
*/
43
public class ClhsdbJstackXcompStress {
44
45
private static final int MAX_ITERATIONS = 20;
46
private static final boolean DEBUG = false;
47
48
private static boolean isMatchCompiledFrame(List<String> output) {
49
List<String> filtered = output.stream().filter( s -> s.contains("Compiled frame"))
50
.collect(Collectors.toList());
51
System.out.println("DEBUG: " + filtered);
52
return !filtered.isEmpty() &&
53
filtered.stream().anyMatch( s -> s.contains("LingeredAppWithRecComputation") );
54
}
55
56
private static void runJstackInLoop(LingeredApp app) throws Exception {
57
boolean anyMatchedCompiledFrame = false;
58
for (int i = 0; i < MAX_ITERATIONS; i++) {
59
JDKToolLauncher launcher = JDKToolLauncher
60
.createUsingTestJDK("jhsdb");
61
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion", "-Xcomp"));
62
launcher.addToolArg("jstack");
63
launcher.addToolArg("--pid");
64
launcher.addToolArg(Long.toString(app.getPid()));
65
66
ProcessBuilder pb = SATestUtils.createProcessBuilder(launcher);
67
Process jhsdb = pb.start();
68
OutputAnalyzer out = new OutputAnalyzer(jhsdb);
69
70
jhsdb.waitFor();
71
72
if (DEBUG) {
73
System.out.println(out.getStdout());
74
System.err.println(out.getStderr());
75
}
76
77
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
78
out.stdoutShouldNotContain("Error occurred during stack walking:");
79
out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);
80
List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));
81
anyMatchedCompiledFrame = anyMatchedCompiledFrame || isMatchCompiledFrame(stdoutList);
82
}
83
if (!anyMatchedCompiledFrame) {
84
throw new RuntimeException("Expected jstack output to contain 'Compiled frame'");
85
}
86
System.out.println("DEBUG: jhsdb jstack did not throw NPE, as expected.");
87
}
88
89
public static void main(String... args) throws Exception {
90
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
91
LingeredApp app = null;
92
try {
93
app = new LingeredAppWithRecComputation();
94
LingeredApp.startApp(app,
95
"-Xcomp",
96
"-XX:CompileCommand=dontinline,LingeredAppWithRecComputation.factorial",
97
"-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.testLoop",
98
"-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.factorial");
99
System.out.println("Started LingeredAppWithRecComputation with pid " + app.getPid());
100
runJstackInLoop(app);
101
System.out.println("Test Completed");
102
} catch (Throwable e) {
103
e.printStackTrace();
104
throw e;
105
} finally {
106
LingeredApp.stopApp(app);
107
}
108
}
109
}
110
111