Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbSymbol.java
41152 views
1
/*
2
* Copyright (c) 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 jdk.test.lib.apps.LingeredApp;
25
import jtreg.SkippedException;
26
27
import java.util.HashMap;
28
import java.util.List;
29
import java.util.Map;
30
31
/**
32
* @test
33
* @bug 8261095
34
* @summary Test the clhsdb 'symbol' command on live process
35
* @requires vm.hasSA
36
* @library /test/lib
37
* @run main/othervm ClhsdbSymbol
38
*/
39
40
public class ClhsdbSymbol {
41
42
public static void main(String[] args) throws Exception {
43
System.out.println("Starting the ClhsdbSymbol test");
44
LingeredApp theApp = null;
45
46
try {
47
List<String> cmds = null;
48
String cmdStr = null;
49
Map<String, List<String>> expStrMap = null;
50
ClhsdbLauncher test = new ClhsdbLauncher();
51
theApp = LingeredApp.startApp();
52
System.out.println("Started LingeredApp with pid " + theApp.getPid());
53
54
// Use command "class java.lang.Thread" to get the address of the InstanceKlass for java.lang.Thread
55
cmdStr = "class java.lang.Thread";
56
cmds = List.of(cmdStr);
57
expStrMap = new HashMap<>();
58
expStrMap.put(cmdStr, List.of("java/lang/Thread"));
59
String classOutput = test.run(theApp.getPid(), cmds, expStrMap, null);
60
61
// Extract the thread InstanceKlass address from the output, which looks similar to the following:
62
// java/lang/Thread @0x000000080001d940
63
String threadAddress = classOutput.lines()
64
.filter(part -> part.startsWith("java/lang/Thread"))
65
.map(part -> part.split(" @"))
66
.findFirst()
67
.map(addresses -> addresses[1])
68
.orElseThrow(() -> new RuntimeException(
69
"Cannot find address of the InstanceKlass for java.lang.Thread in output"));
70
71
72
// Use "inspect" on the thread address we extracted in the previous step
73
cmdStr = "inspect " + threadAddress;
74
cmds = List.of(cmdStr);
75
expStrMap = new HashMap<>();
76
expStrMap.put(cmdStr, List.of("Symbol"));
77
String inspectOutput = test.run(theApp.getPid(), cmds, expStrMap, null);
78
79
// The inspect command output will have one line of output that looks like the following.
80
// Symbol* Klass::_name: Symbol @ 0x0000000800471120
81
// Extract the Symbol address from it.
82
String symbolAddress = inspectOutput.lines()
83
.filter(part -> part.startsWith("Symbol"))
84
.map(part -> part.split("@ "))
85
.findFirst().map(symbolParts -> symbolParts[1])
86
.orElseThrow(() -> new RuntimeException("Cannot find address with Symbol instance"));
87
88
// Run "symbol" command on the Symbol instance address extracted in the previous step.
89
// It should produce the symbol for java/lang/Thread.
90
cmdStr = "symbol " + symbolAddress;
91
cmds = List.of(cmdStr);
92
expStrMap = new HashMap<>();
93
expStrMap.put(cmdStr, List.of("#java/lang/Thread"));
94
test.run(theApp.getPid(), cmds, expStrMap, null);
95
} catch (SkippedException se) {
96
throw se;
97
} catch (Exception ex) {
98
throw new RuntimeException("Test ERROR " + ex, ex);
99
} finally {
100
LingeredApp.stopApp(theApp);
101
}
102
System.out.println("Test PASSED");
103
}
104
}
105
106