Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jhsdb/HeapDumpTest.java
41152 views
1
/*
2
* Copyright (c) 2016, 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 8163346
27
* @summary Test hashing of extended characters in Serviceability Agent.
28
* @requires vm.hasSA
29
* @library /test/lib
30
* @compile -encoding utf8 HeapDumpTest.java
31
* @run main/timeout=240 HeapDumpTest
32
*/
33
34
import static jdk.test.lib.Asserts.assertTrue;
35
36
import java.io.IOException;
37
import java.io.File;
38
import java.util.List;
39
import java.util.Arrays;
40
41
import jdk.test.lib.Utils;
42
import jdk.test.lib.apps.LingeredApp;
43
import jdk.test.lib.hprof.parser.HprofReader;
44
import jdk.test.lib.JDKToolLauncher;
45
import jdk.test.lib.process.OutputAnalyzer;
46
import jdk.test.lib.process.ProcessTools;
47
import jdk.test.lib.SA.SATestUtils;
48
49
public class HeapDumpTest {
50
51
private static LingeredAppWithExtendedChars theApp = null;
52
private static final String SUCCESS_STRING = "heap written to";
53
/**
54
*
55
* @param vmArgs - tool arguments to launch jhsdb
56
* @return exit code of tool
57
*/
58
public static void launch(int expectedExitValue, List<String> toolArgs)
59
throws IOException {
60
61
System.out.println("Starting LingeredApp");
62
try {
63
theApp = new LingeredAppWithExtendedChars();
64
LingeredApp.startApp(theApp, "-Xmx256m");
65
66
System.out.println(theApp.\u00CB);
67
System.out.println("Starting " + toolArgs.get(0) + " against " + theApp.getPid());
68
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
69
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
70
71
for (String cmd : toolArgs) {
72
launcher.addToolArg(cmd);
73
}
74
75
launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
76
77
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
78
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
79
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
80
System.out.println("stdout:");
81
System.out.println(output.getStdout());
82
System.out.println("stderr:");
83
System.out.println(output.getStderr());
84
output.shouldHaveExitValue(expectedExitValue);
85
if (expectedExitValue == 0) {
86
output.shouldContain(SUCCESS_STRING);
87
} else {
88
output.stdoutShouldNotContain(SUCCESS_STRING);
89
}
90
} catch (Exception ex) {
91
throw new RuntimeException("Test ERROR " + ex, ex);
92
} finally {
93
LingeredApp.stopApp(theApp);
94
}
95
}
96
97
public static void launch(int expectedExitValue, String... toolArgs)
98
throws IOException {
99
launch(expectedExitValue, Arrays.asList(toolArgs));
100
}
101
102
public static void printStackTraces(String file) throws IOException {
103
try {
104
String output = HprofReader.getStack(file, 0);
105
if (!output.contains("LingeredApp.steadyState")) {
106
throw new RuntimeException("'LingeredApp.steadyState' missing from stdout/stderr");
107
}
108
} catch (Exception ex) {
109
throw new RuntimeException("Test ERROR " + ex, ex);
110
}
111
}
112
113
public static void testHeapDump(SubTest subtest) throws IOException {
114
String gzOption = subtest.getGzOption();
115
boolean checkSuccess = subtest.needCheckSuccess();
116
int expectedExitValue = checkSuccess ? 0 : 1;
117
118
File dump = new File("jhsdb.jmap.heap." +
119
System.currentTimeMillis() + ".hprof");
120
if (dump.exists()) {
121
dump.delete();
122
}
123
if (gzOption == null || gzOption.length() == 0) {
124
launch(expectedExitValue, "jmap",
125
"--binaryheap", "--dumpfile=" + dump.getAbsolutePath());
126
} else {
127
launch(expectedExitValue, "jmap",
128
"--binaryheap", gzOption, "--dumpfile=" + dump.getAbsolutePath());
129
}
130
131
if (checkSuccess) {
132
assertTrue(dump.exists() && dump.isFile(),
133
"Could not create dump file " + dump.getAbsolutePath());
134
135
printStackTraces(dump.getAbsolutePath());
136
dump.delete();
137
} else {
138
assertTrue(!dump.exists(), "Unexpected file created: " + dump.getAbsolutePath());
139
}
140
}
141
142
public static void main(String[] args) throws Exception {
143
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
144
SubTest[] subtests = new SubTest[] {
145
new SubTest("", true/*checkSuccess*/),
146
new SubTest("--gz=1", true),
147
new SubTest("--gz=9", true),
148
new SubTest("--gz=0", false),
149
new SubTest("--gz=100", false),
150
new SubTest("--gz=", false),
151
new SubTest("--gz", false),
152
};
153
// Run subtests
154
for (int i = 0; i < subtests.length;i++) {
155
testHeapDump(subtests[i]);
156
}
157
// The test throws RuntimeException on error.
158
// IOException is thrown if LingeredApp can't start because of some bad
159
// environment condition
160
System.out.println("Test PASSED");
161
}
162
163
private static class SubTest {
164
private String gzOption;
165
boolean needCheckSuccess;
166
167
public SubTest(String gzOpt, boolean checkSuccess) {
168
gzOption = gzOpt;
169
needCheckSuccess = checkSuccess;
170
}
171
172
public String getGzOption() { return gzOption; }
173
public boolean needCheckSuccess() { return needCheckSuccess; }
174
}
175
}
176
177