Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbFindPC.java
64478 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
// Note, sometimes a stack address points to a hotspot type, thus allow for "Is of type".
213
expStrMap.put(cmdStr, List.of("(In java stack)|(Is of type)"));
214
runTest(withCore, cmds, expStrMap);
215
}
216
217
// Run 'examine <addr>' using a thread's tid as the address. The
218
// examine output will be the of the form:
219
// <tid>: <value>
220
// Where <value> is the word stored at <tid>. <value> also happens to
221
// be the vtable address. We then run findpc on this vtable address.
222
// This tests PointerFinder support for native C++ symbols.
223
cmds = List.of("examine " + tid);
224
String examineOutput = runTest(withCore, cmds, null);
225
// Extract <value>.
226
parts = examineOutput.split(tid + ": ");
227
String value = parts[1].split(linesep)[0];
228
// Use findpc on <value>. The output should look something like:
229
// Address 0x00007fed86f610b8: vtable for JavaThread + 0x10
230
cmdStr = "findpc " + value;
231
cmds = List.of(cmdStr);
232
expStrMap = new HashMap<>();
233
if (Platform.isWindows()) {
234
expStrMap.put(cmdStr, List.of("jvm.+JavaThread"));
235
} else if (Platform.isOSX()) {
236
if (withCore) {
237
expStrMap.put(cmdStr, List.of("__ZTV10JavaThread"));
238
} else { // address -> symbol lookups not supported with OSX live process
239
expStrMap.put(cmdStr, List.of("In unknown location"));
240
}
241
} else {
242
expStrMap.put(cmdStr, List.of("vtable for JavaThread"));
243
}
244
String findpcOutput = runTest(withCore, cmds, expStrMap);
245
246
// Determine if we have symbol support. Currently we assume yes except on windows.
247
boolean hasSymbols = true;
248
if (Platform.isWindows()) {
249
if (findpcOutput.indexOf("jvm!JavaThread::`vftable'") == -1) {
250
hasSymbols = false;
251
}
252
}
253
254
// Run "findsym MaxJNILocalCapacity". The output should look something like:
255
// 0x00007eff8e1a0da0: <jdk-dir>/lib/server/libjvm.so + 0x1d81da0
256
String symbol = "MaxJNILocalCapacity";
257
cmds = List.of("findsym " + symbol);
258
expStrMap = new HashMap<>();
259
if (!hasSymbols) {
260
expStrMap.put(cmdStr, List.of("Symbol not found"));
261
}
262
String findsymOutput = runTest(withCore, cmds, expStrMap);
263
// Run findpc on the result of "findsym MaxJNILocalCapacity". The output
264
// should look something like:
265
// Address 0x00007eff8e1a0da0: MaxJNILocalCapacity
266
if (hasSymbols) {
267
parts = findsymOutput.split("findsym " + symbol + linesep);
268
parts = parts[1].split(":");
269
String findsymAddress = parts[0].split(linesep)[0];
270
cmdStr = "findpc " + findsymAddress;
271
cmds = List.of(cmdStr);
272
expStrMap = new HashMap<>();
273
if (Platform.isOSX() && !withCore) {
274
// address -> symbol lookups not supported with OSX live process
275
expStrMap.put(cmdStr, List.of("Address " + findsymAddress + ": In unknown location"));
276
} else {
277
expStrMap.put(cmdStr, List.of("Address " + findsymAddress + ": .*" + symbol));
278
}
279
runTest(withCore, cmds, expStrMap);
280
}
281
} catch (SkippedException se) {
282
throw se;
283
} catch (Exception ex) {
284
throw new RuntimeException("Test ERROR " + ex, ex);
285
} finally {
286
if (!withCore) {
287
LingeredApp.stopApp(theApp);
288
}
289
}
290
}
291
292
private static String runTest(boolean withCore, List<String> cmds, Map<String, List<String>> expStrMap)
293
throws Exception
294
{
295
if (withCore) {
296
return test.runOnCore(coreFileName, cmds, expStrMap, null);
297
} else {
298
return test.run(theApp.getPid(), cmds, expStrMap, null);
299
}
300
}
301
302
public static void main(String[] args) throws Exception {
303
boolean withXcomp = Boolean.parseBoolean(args[0]);
304
boolean withCore = Boolean.parseBoolean(args[1]);
305
System.out.println("Starting the ClhsdbFindPC test");
306
testFindPC(withXcomp, withCore);
307
System.out.println("Test PASSED");
308
}
309
}
310
311