Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbFindPC.java
41149 views
1
/*
2
* Copyright (c) 2017, 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.util.ArrayList;
28
29
import jdk.test.lib.apps.LingeredApp;
30
import jdk.test.lib.Platform;
31
import jdk.test.lib.util.CoreUtils;
32
import jtreg.SkippedException;
33
34
/**
35
* @test
36
* @bug 8193124
37
* @summary Test the clhsdb 'findpc' command with Xcomp on live process
38
* @requires vm.hasSA
39
* @requires vm.compiler1.enabled
40
* @requires vm.opt.DeoptimizeALot != true
41
* @library /test/lib
42
* @run main/othervm/timeout=480 ClhsdbFindPC true false
43
*/
44
45
/**
46
* @test
47
* @bug 8193124
48
* @summary Test the clhsdb 'findpc' command with Xcomp on core file
49
* @requires vm.compMode != "Xcomp"
50
* @requires vm.hasSA
51
* @requires vm.compiler1.enabled
52
* @library /test/lib
53
* @run main/othervm/timeout=480 ClhsdbFindPC true true
54
*/
55
56
/**
57
* @test
58
* @bug 8193124
59
* @summary Test the clhsdb 'findpc' command w/o Xcomp on live process
60
* @requires vm.hasSA
61
* @requires vm.compiler1.enabled
62
* @requires vm.opt.DeoptimizeALot != true
63
* @library /test/lib
64
* @run main/othervm/timeout=480 ClhsdbFindPC false false
65
*/
66
67
/**
68
* @test
69
* @bug 8193124
70
* @summary Test the clhsdb 'findpc' command w/o Xcomp on core file
71
* @requires vm.compMode != "Xcomp"
72
* @requires vm.hasSA
73
* @requires vm.compiler1.enabled
74
* @library /test/lib
75
* @run main/othervm/timeout=480 ClhsdbFindPC false true
76
*/
77
78
public class ClhsdbFindPC {
79
static LingeredApp theApp = null;
80
static String coreFileName = null;
81
static ClhsdbLauncher test = null;
82
83
private static void testFindPC(boolean withXcomp, boolean withCore) throws Exception {
84
try {
85
String linesep = System.getProperty("line.separator");
86
String segvAddress = null;
87
List<String> cmds = null;
88
String cmdStr = null;
89
Map<String, List<String>> expStrMap = null;
90
91
test = new ClhsdbLauncher();
92
93
theApp = new LingeredApp();
94
theApp.setForceCrash(withCore);
95
if (withXcomp) {
96
LingeredApp.startApp(theApp, "-Xcomp");
97
} else {
98
LingeredApp.startApp(theApp, "-Xint");
99
}
100
System.out.print("Started LingeredApp ");
101
if (withXcomp) {
102
System.out.print("(-Xcomp) ");
103
} else {
104
System.out.print("(-Xint) ");
105
}
106
System.out.println("with pid " + theApp.getPid());
107
108
if (withCore) {
109
String crashOutput = theApp.getOutput().getStdout();
110
// Get the core file name if we are debugging a core instead of live process
111
coreFileName = CoreUtils.getCoreFileLocation(crashOutput, theApp.getPid());
112
// Get the SEGV Address from the following line:
113
// # SIGSEGV (0xb) at pc=0x00007f20a897f7f4, pid=8561, tid=8562
114
String[] parts = crashOutput.split(" pc=");
115
String[] tokens = parts[1].split(",");
116
segvAddress = tokens[0];
117
118
// Test the 'findpc' command passing in the SEGV address
119
cmds = new ArrayList<String>();
120
cmdStr = "findpc " + segvAddress;
121
cmds.add(cmdStr);
122
expStrMap = new HashMap<>();
123
if (Platform.isOSX()) {
124
// OSX will only find addresses in JVM libraries, not user or system libraries
125
expStrMap.put(cmdStr, List.of("In unknown location"));
126
} else { // symbol lookups not supported with OSX live process
127
expStrMap.put(cmdStr, List.of("Java_jdk_test_lib_apps_LingeredApp_crash"));
128
}
129
runTest(withCore, cmds, expStrMap);
130
}
131
132
// Run 'jstack -v' command to get the pc and other useful values
133
cmds = List.of("jstack -v");
134
String jStackOutput = runTest(withCore, cmds, null);
135
136
// Extract pc address from the following line:
137
// - LingeredApp.steadyState(java.lang.Object) @bci=1, line=33, pc=0x00007ff18ff519f0, ...
138
String pcAddress = null;
139
String[] parts = jStackOutput.split("LingeredApp.steadyState");
140
String[] tokens = parts[1].split(" ");
141
for (String token : tokens) {
142
if (token.contains("pc")) {
143
String[] addresses = token.split("=");
144
// addresses[1] represents the address of the Method
145
pcAddress = addresses[1].replace(",","");
146
break;
147
}
148
}
149
if (pcAddress == null) {
150
throw new RuntimeException("Cannot find LingeredApp.steadyState pc in output");
151
}
152
153
// Test the 'findpc' command passing in the pc obtained from jstack above
154
cmds = new ArrayList<String>();
155
cmdStr = "findpc " + pcAddress;
156
cmds.add(cmdStr);
157
expStrMap = new HashMap<>();
158
if (withXcomp) {
159
expStrMap.put(cmdStr, List.of(
160
"In code in NMethod for jdk/test/lib/apps/LingeredApp.steadyState",
161
"content:",
162
"oops:",
163
"frame size:"));
164
} else {
165
expStrMap.put(cmdStr, List.of(
166
"In interpreter codelet"));
167
}
168
runTest(withCore, cmds, expStrMap);
169
170
// Run findpc on a Method*. We can find one in the jstack output. For example:
171
// - LingeredApp.steadyState(java.lang.Object) @bci=1, line=33, pc=..., Method*=0x0000008041000208 ...
172
// This is testing the PointerFinder support for C++ MetaData types.
173
parts = jStackOutput.split("LingeredApp.steadyState");
174
parts = parts[1].split("Method\\*=");
175
parts = parts[1].split(" ");
176
String methodAddr = parts[0];
177
cmdStr = "findpc " + methodAddr;
178
cmds = List.of(cmdStr);
179
expStrMap = new HashMap<>();
180
expStrMap.put(cmdStr, List.of("Method ",
181
"LingeredApp.steadyState",
182
methodAddr));
183
runTest(withCore, cmds, expStrMap);
184
185
// Run findpc on a JavaThread*. We can find one in the jstack output.
186
// The tid for a thread is it's JavaThread*. For example:
187
// "main" #1 prio=5 tid=0x00000080263398f0 nid=0x277e0 ...
188
// This is testing the PointerFinder support for all C++ types other than MetaData types.
189
parts = jStackOutput.split("tid=");
190
parts = parts[1].split(" ");
191
String tid = parts[0]; // address of the JavaThread
192
cmdStr = "findpc " + tid;
193
cmds = List.of(cmdStr);
194
expStrMap = new HashMap<>();
195
expStrMap.put(cmdStr, List.of("Is of type JavaThread"));
196
runTest(withCore, cmds, expStrMap);
197
198
// Run findpc on a java stack address. We can find one in the jstack output.
199
// "main" #1 prio=5 tid=... nid=0x277e0 waiting on condition [0x0000008025aef000]
200
// The stack address is the last word between the brackets.
201
// This is testing the PointerFinder support for thread stack addresses.
202
parts = jStackOutput.split("tid=");
203
parts = parts[1].split(" \\[");
204
parts = parts[1].split("\\]");
205
String stackAddress = parts[0]; // address of the thread's stack
206
if (Long.decode(stackAddress) == 0L) {
207
System.out.println("Stack address is " + stackAddress + ". Skipping test.");
208
} else {
209
cmdStr = "findpc " + stackAddress;
210
cmds = List.of(cmdStr);
211
expStrMap = new HashMap<>();
212
expStrMap.put(cmdStr, List.of("In java stack"));
213
runTest(withCore, cmds, expStrMap);
214
}
215
216
// Run 'examine <addr>' using a thread's tid as the address. The
217
// examine output will be the of the form:
218
// <tid>: <value>
219
// Where <value> is the word stored at <tid>. <value> also happens to
220
// be the vtable address. We then run findpc on this vtable address.
221
// This tests PointerFinder support for native C++ symbols.
222
cmds = List.of("examine " + tid);
223
String examineOutput = runTest(withCore, cmds, null);
224
// Extract <value>.
225
parts = examineOutput.split(tid + ": ");
226
String value = parts[1].split(linesep)[0];
227
// Use findpc on <value>. The output should look something like:
228
// Address 0x00007fed86f610b8: vtable for JavaThread + 0x10
229
cmdStr = "findpc " + value;
230
cmds = List.of(cmdStr);
231
expStrMap = new HashMap<>();
232
if (Platform.isWindows()) {
233
expStrMap.put(cmdStr, List.of("jvm.+JavaThread"));
234
} else if (Platform.isOSX()) {
235
if (withCore) {
236
expStrMap.put(cmdStr, List.of("__ZTV10JavaThread"));
237
} else { // address -> symbol lookups not supported with OSX live process
238
expStrMap.put(cmdStr, List.of("In unknown location"));
239
}
240
} else {
241
expStrMap.put(cmdStr, List.of("vtable for JavaThread"));
242
}
243
String findpcOutput = runTest(withCore, cmds, expStrMap);
244
245
// Determine if we have symbol support. Currently we assume yes except on windows.
246
boolean hasSymbols = true;
247
if (Platform.isWindows()) {
248
if (findpcOutput.indexOf("jvm!JavaThread::`vftable'") == -1) {
249
hasSymbols = false;
250
}
251
}
252
253
// Run "findsym MaxJNILocalCapacity". The output should look something like:
254
// 0x00007eff8e1a0da0: <jdk-dir>/lib/server/libjvm.so + 0x1d81da0
255
String symbol = "MaxJNILocalCapacity";
256
cmds = List.of("findsym " + symbol);
257
expStrMap = new HashMap<>();
258
if (!hasSymbols) {
259
expStrMap.put(cmdStr, List.of("Symbol not found"));
260
}
261
String findsymOutput = runTest(withCore, cmds, expStrMap);
262
// Run findpc on the result of "findsym MaxJNILocalCapacity". The output
263
// should look something like:
264
// Address 0x00007eff8e1a0da0: MaxJNILocalCapacity
265
if (hasSymbols) {
266
parts = findsymOutput.split("findsym " + symbol + linesep);
267
parts = parts[1].split(":");
268
String findsymAddress = parts[0].split(linesep)[0];
269
cmdStr = "findpc " + findsymAddress;
270
cmds = List.of(cmdStr);
271
expStrMap = new HashMap<>();
272
if (Platform.isOSX() && !withCore) {
273
// address -> symbol lookups not supported with OSX live process
274
expStrMap.put(cmdStr, List.of("Address " + findsymAddress + ": In unknown location"));
275
} else {
276
expStrMap.put(cmdStr, List.of("Address " + findsymAddress + ": .*" + symbol));
277
}
278
runTest(withCore, cmds, expStrMap);
279
}
280
} catch (SkippedException se) {
281
throw se;
282
} catch (Exception ex) {
283
throw new RuntimeException("Test ERROR " + ex, ex);
284
} finally {
285
if (!withCore) {
286
LingeredApp.stopApp(theApp);
287
}
288
}
289
}
290
291
private static String runTest(boolean withCore, List<String> cmds, Map<String, List<String>> expStrMap)
292
throws Exception
293
{
294
if (withCore) {
295
return test.runOnCore(coreFileName, cmds, expStrMap, null);
296
} else {
297
return test.run(theApp.getPid(), cmds, expStrMap, null);
298
}
299
}
300
301
public static void main(String[] args) throws Exception {
302
boolean withXcomp = Boolean.parseBoolean(args[0]);
303
boolean withCore = Boolean.parseBoolean(args[1]);
304
System.out.println("Starting the ClhsdbFindPC test");
305
testFindPC(withXcomp, withCore);
306
System.out.println("Test PASSED");
307
}
308
}
309
310