Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java
41152 views
1
/*
2
* Copyright (c) 2018, 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 8174994 8200613
27
* @summary Test the clhsdb commands 'printmdo', 'printall', 'jstack' on a CDS enabled corefile.
28
* @requires vm.cds
29
* @requires vm.hasSA
30
* @requires vm.flavor == "server"
31
* @library /test/lib
32
* @modules java.base/jdk.internal.misc
33
* @run driver/timeout=2400 ClhsdbCDSCore
34
*/
35
36
import java.io.File;
37
import java.io.IOException;
38
import java.nio.file.Files;
39
import java.nio.file.Paths;
40
import java.util.ArrayList;
41
import java.util.Arrays;
42
import java.util.HashMap;
43
import java.util.List;
44
import java.util.Map;
45
46
import jdk.internal.misc.Unsafe;
47
48
import jdk.test.lib.Asserts;
49
import jdk.test.lib.Platform;
50
import jdk.test.lib.cds.CDSOptions;
51
import jdk.test.lib.cds.CDSTestUtils;
52
import jdk.test.lib.process.OutputAnalyzer;
53
import jdk.test.lib.process.ProcessTools;
54
import jdk.test.lib.util.CoreUtils;
55
import jdk.test.lib.Utils;
56
57
import jtreg.SkippedException;
58
59
class CrashApp {
60
public static void main(String[] args) {
61
Unsafe.getUnsafe().putInt(0L, 0);
62
}
63
}
64
65
public class ClhsdbCDSCore {
66
private static final String SHARED_ARCHIVE_NAME = "ArchiveForClhsdbCDSCore.jsa";
67
private static String coreFileName;
68
69
public static void main(String[] args) throws Exception {
70
System.out.println("Starting ClhsdbCDSCore test");
71
cleanup();
72
73
try {
74
CDSOptions opts = (new CDSOptions()).setArchiveName(SHARED_ARCHIVE_NAME);
75
CDSTestUtils.createArchiveAndCheck(opts);
76
77
String[] jArgs = {
78
"-Xmx512m",
79
"-XX:+UnlockDiagnosticVMOptions",
80
"-XX:SharedArchiveFile=" + SHARED_ARCHIVE_NAME,
81
"-XX:+CreateCoredumpOnCrash",
82
"-Xshare:auto",
83
"-XX:+ProfileInterpreter",
84
"--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
85
CrashApp.class.getName()
86
};
87
88
OutputAnalyzer crashOutput;
89
try {
90
List<String> options = new ArrayList<>();
91
options.addAll(Arrays.asList(jArgs));
92
ProcessBuilder pb = ProcessTools.createTestJvm(options);
93
// Add "ulimit -c unlimited" if we can since we are generating a core file.
94
pb = CoreUtils.addCoreUlimitCommand(pb);
95
crashOutput = ProcessTools.executeProcess(pb);
96
} catch (Throwable t) {
97
throw new Error("Can't execute the java cds process.", t);
98
}
99
100
try {
101
coreFileName = CoreUtils.getCoreFileLocation(crashOutput.getStdout(), crashOutput.pid());
102
} catch (Exception e) {
103
cleanup();
104
throw e;
105
}
106
107
ClhsdbLauncher test = new ClhsdbLauncher();
108
109
// Ensure that UseSharedSpaces is turned on.
110
List<String> cmds = List.of("flags UseSharedSpaces");
111
112
String useSharedSpacesOutput = test.runOnCore(coreFileName, cmds, null, null);
113
114
if (useSharedSpacesOutput == null) {
115
// Output could be null due to attach permission issues.
116
cleanup();
117
throw new SkippedException("Could not determine the UseSharedSpaces value");
118
}
119
120
if (useSharedSpacesOutput.contains("UseSharedSpaces = false")) {
121
// CDS archive is not mapped. Skip the rest of the test.
122
cleanup();
123
throw new SkippedException("The CDS archive is not mapped");
124
}
125
126
List testJavaOpts = Arrays.asList(Utils.getTestJavaOpts());
127
128
if (testJavaOpts.contains("-Xcomp") && testJavaOpts.contains("-XX:TieredStopAtLevel=1")) {
129
// No MDOs are allocated in -XX:TieredStopAtLevel=1 + -Xcomp mode
130
// The reason is methods being compiled aren't hot enough
131
// Let's not call printmdo in such scenario
132
cmds = List.of("printall", "jstack -v");
133
} else {
134
cmds = List.of("printmdo -a", "printall", "jstack -v");
135
}
136
137
Map<String, List<String>> expStrMap = new HashMap<>();
138
Map<String, List<String>> unExpStrMap = new HashMap<>();
139
expStrMap.put("printmdo -a", List.of(
140
"CounterData",
141
"BranchData"));
142
unExpStrMap.put("printmdo -a", List.of(
143
"No suitable match for type of address"));
144
expStrMap.put("printall", List.of(
145
"aload_0",
146
"_nofast_aload_0",
147
"_nofast_getfield",
148
"_nofast_putfield",
149
"Constant Pool of",
150
"public static void main\\(java.lang.String\\[\\]\\)",
151
"Bytecode",
152
"invokevirtual",
153
"checkcast",
154
"Exception Table",
155
"invokedynamic"));
156
unExpStrMap.put("printall", List.of(
157
"sun.jvm.hotspot.types.WrongTypeException",
158
"illegal code",
159
"Failure occurred at bci",
160
"No suitable match for type of address"));
161
expStrMap.put("jstack -v", List.of(
162
"Common-Cleaner",
163
"Method*"));
164
unExpStrMap.put("jstack -v", List.of(
165
"sun.jvm.hotspot.debugger.UnmappedAddressException"));
166
test.runOnCore(coreFileName, cmds, expStrMap, unExpStrMap);
167
} catch (SkippedException e) {
168
throw e;
169
} catch (Exception ex) {
170
throw new RuntimeException("Test ERROR " + ex, ex);
171
}
172
cleanup();
173
System.out.println("Test PASSED");
174
}
175
176
private static void cleanup() {
177
remove(SHARED_ARCHIVE_NAME);
178
}
179
180
private static void remove(String item) {
181
File toDelete = new File(item);
182
toDelete.delete();
183
}
184
}
185
186