Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpheap.java
41152 views
1
/*
2
* Copyright (c) 2020, 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
import java.util.HashMap;
25
import java.util.List;
26
import java.util.Map;
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileOutputStream;
30
31
import static jdk.test.lib.Asserts.assertTrue;
32
import static jdk.test.lib.Asserts.assertFalse;
33
import jdk.test.lib.hprof.HprofParser;
34
import jdk.test.lib.apps.LingeredApp;
35
import jdk.test.lib.hprof.parser.HprofReader;
36
import jtreg.SkippedException;
37
38
/**
39
* @test
40
* @bug 8240989
41
* @summary Test clhsdb dumpheap command
42
* @requires vm.hasSA
43
* @library /test/lib
44
* @run main/othervm/timeout=240 ClhsdbDumpheap
45
*/
46
47
public class ClhsdbDumpheap {
48
// The default heap dump file name defined in JDK.
49
private static final String HEAP_DUMP_FILENAME_DEFAULT = "heap.bin";
50
private static final String HEAP_DUMP_GZIPED_FILENAME_DEFAULT = "heap.bin.gz";
51
52
public static void printStackTraces(String file) {
53
try {
54
System.out.println("HprofReader.getStack() output:");
55
String output = HprofReader.getStack(file, 0);
56
if (!output.contains("LingeredApp.steadyState")) {
57
throw new RuntimeException("'LingeredApp.steadyState' missing from stdout/stderr");
58
}
59
} catch (Exception ex) {
60
throw new RuntimeException("Test ERROR " + ex, ex);
61
}
62
}
63
64
private static void verifyDumpFile(File dump) throws Exception {
65
assertTrue(dump.exists() && dump.isFile(), "Could not create dump file " + dump.getAbsolutePath());
66
printStackTraces(dump.getAbsolutePath());
67
}
68
69
private static class SubTest {
70
private String cmd;
71
private String fileName;
72
private String expectedOutput;
73
boolean compression;
74
boolean needVerify;
75
76
public SubTest(String comm, String fName, boolean isComp, boolean verify, String expected) {
77
cmd = comm;
78
fileName = fName;
79
expectedOutput = expected;
80
compression = isComp;
81
needVerify = verify;
82
}
83
84
public String getCmd() { return cmd; }
85
public String getFileName() { return fileName; }
86
public String getExpectedOutput() { return expectedOutput; }
87
public boolean isCompression() { return compression; }
88
public boolean needVerify() { return needVerify; }
89
}
90
91
private static void runTest(long appPid, SubTest subtest) throws Exception {
92
ClhsdbLauncher test = new ClhsdbLauncher();
93
String fileName = subtest.getFileName();
94
String cmd = subtest.getCmd();
95
String expectedOutput = subtest.getExpectedOutput();
96
boolean compression = subtest.isCompression();
97
/* The expected generated file, used to distinguish with fileName in case fileName is blank or null */
98
String expectedFileName = fileName;
99
if (fileName == null || fileName.length() == 0) {
100
if (!compression) {
101
expectedFileName = HEAP_DUMP_FILENAME_DEFAULT;
102
} else {
103
expectedFileName = HEAP_DUMP_GZIPED_FILENAME_DEFAULT;
104
}
105
}
106
assertTrue (expectedFileName != null && expectedFileName.length() > 0,
107
"Expected generated file name must have value");
108
File file = new File(expectedFileName);
109
if (file.exists()) {
110
file.delete();
111
}
112
String command = cmd + fileName;
113
List<String> cmds = List.of(command);
114
Map<String, List<String>> expStrMap = new HashMap<>();
115
expStrMap.put(command, List.of(expectedOutput));
116
test.run(appPid, cmds, expStrMap, null);
117
if (subtest.needVerify()) {
118
verifyDumpFile(file);
119
}
120
file.delete();
121
}
122
123
public static void main(String[] args) throws Exception {
124
System.out.println("Starting ClhsdbDumpheap test");
125
126
LingeredApp theApp = null;
127
try {
128
// Use file name different with JDK's default value "heap.bin".
129
String heapDumpFileName = "heapdump.bin";
130
String heapDumpFileNameGz = "heapdump.bin.gz";
131
132
theApp = new LingeredApp();
133
LingeredApp.startApp(theApp);
134
System.out.println("Started LingeredApp with pid " + theApp.getPid());
135
136
SubTest[] subtests = new SubTest[] {
137
new SubTest("dumpheap ", heapDumpFileName, false/*compression*/, true,/*verify*/
138
"heap written to " + heapDumpFileName),
139
new SubTest("dumpheap gz=1 ", heapDumpFileNameGz, true, true,
140
"heap written to " + heapDumpFileNameGz),
141
new SubTest("dumpheap gz=9 ", heapDumpFileNameGz, true, true,
142
"heap written to " + heapDumpFileNameGz),
143
new SubTest("dumpheap gz=0 ", heapDumpFileNameGz, true, false,
144
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
145
new SubTest("dumpheap gz=100 ", heapDumpFileNameGz, true, false,
146
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
147
new SubTest("dumpheap gz= ", heapDumpFileNameGz, true, false,
148
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
149
new SubTest("dumpheap gz ", heapDumpFileNameGz, true, false,
150
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
151
new SubTest("dumpheap", "", false, true,
152
"heap written to " + HEAP_DUMP_FILENAME_DEFAULT),
153
new SubTest("dumpheap gz=1", "", true, true,
154
"heap written to " + HEAP_DUMP_GZIPED_FILENAME_DEFAULT),
155
new SubTest("dumpheap gz=9", "", true, true,
156
"heap written to " + HEAP_DUMP_GZIPED_FILENAME_DEFAULT),
157
new SubTest("dumpheap gz=0", "", true, false,
158
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
159
new SubTest("dumpheap gz=100", "", true, false,
160
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
161
// Command "dumpheap gz=".
162
new SubTest("dumpheap ", "gz=", true, false,
163
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]"),
164
// Command "dumpheap gz".
165
new SubTest("dumpheap ", "gz", false, true, "heap written to gz"),
166
// Command "dump heap gz=1 gz=2".
167
new SubTest("dumpheap gz=1", "gz=2", true, false,
168
"Usage: dumpheap \\[gz=<1-9>\\] \\[filename\\]")
169
};
170
// Run subtests
171
for (int i = 0; i < subtests.length;i++) {
172
runTest(theApp.getPid(), subtests[i]);
173
}
174
} catch (SkippedException se) {
175
throw se;
176
} catch (Exception ex) {
177
throw new RuntimeException("Test ERROR " + ex, ex);
178
} finally {
179
LingeredApp.stopApp(theApp);
180
}
181
System.out.println("Test PASSED");
182
}
183
}
184
185