Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/TestCpoolForInvokeDynamic.java
41152 views
1
/*
2
* Copyright (c) 2016, 2020, 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.ArrayList;
25
import java.util.List;
26
27
import sun.jvm.hotspot.HotSpotAgent;
28
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
29
import sun.jvm.hotspot.oops.InstanceKlass;
30
import sun.jvm.hotspot.debugger.*;
31
import sun.jvm.hotspot.oops.Method;
32
import sun.jvm.hotspot.utilities.MethodArray;
33
import sun.jvm.hotspot.ui.classbrowser.HTMLGenerator;
34
35
import jdk.test.lib.apps.LingeredApp;
36
import jdk.test.lib.Asserts;
37
import jdk.test.lib.JDKToolLauncher;
38
import jdk.test.lib.JDKToolFinder;
39
import jdk.test.lib.Platform;
40
import jdk.test.lib.process.ProcessTools;
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.SA.SATestUtils;
43
import jdk.test.lib.Utils;
44
45
/**
46
* @test
47
* @library /test/lib
48
* @requires vm.hasSA
49
* @modules java.base/jdk.internal.misc
50
* jdk.hotspot.agent/sun.jvm.hotspot
51
* jdk.hotspot.agent/sun.jvm.hotspot.utilities
52
* jdk.hotspot.agent/sun.jvm.hotspot.oops
53
* jdk.hotspot.agent/sun.jvm.hotspot.debugger
54
* jdk.hotspot.agent/sun.jvm.hotspot.ui.classbrowser
55
* @run main TestCpoolForInvokeDynamic
56
*/
57
58
public class TestCpoolForInvokeDynamic {
59
60
private static LingeredAppWithInvokeDynamic theApp = null;
61
62
private static void printBytecodes(String pid,
63
String[] instanceKlassNames) {
64
HotSpotAgent agent = new HotSpotAgent();
65
try {
66
agent.attach(Integer.parseInt(pid));
67
}
68
catch (DebuggerException e) {
69
System.out.println(e.getMessage());
70
System.err.println("Unable to connect to process ID: " + pid);
71
72
agent.detach();
73
e.printStackTrace();
74
}
75
76
for (String instanceKlassName : instanceKlassNames) {
77
InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass(instanceKlassName);
78
MethodArray methods = iKlass.getMethods();
79
for (int i = 0; i < methods.length(); i++) {
80
Method m = methods.at(i);
81
System.out.println("Method: " + m.getName().asString() +
82
" in instance klass: " + instanceKlassName);
83
HTMLGenerator gen = new HTMLGenerator(false);
84
System.out.println(gen.genHTML(m));
85
}
86
}
87
agent.detach();
88
}
89
90
private static void createAnotherToAttach(
91
String[] instanceKlassNames,
92
long lingeredAppPid) throws Exception {
93
// Start a new process to attach to the lingered app
94
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
95
"--add-modules=jdk.hotspot.agent",
96
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
97
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
98
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
99
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
100
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.ui.classbrowser=ALL-UNNAMED",
101
"TestCpoolForInvokeDynamic",
102
Long.toString(lingeredAppPid));
103
SATestUtils.addPrivilegesIfNeeded(processBuilder);
104
OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
105
SAOutput.shouldHaveExitValue(0);
106
System.out.println(SAOutput.getOutput());
107
108
SAOutput.shouldContain("invokedynamic");
109
SAOutput.shouldContain("Name and Type");
110
SAOutput.shouldContain("run:()Ljava.lang.Runnable");
111
SAOutput.shouldContain("compare:()LTestComparator");
112
SAOutput.shouldNotContain("Corrupted constant pool");
113
}
114
115
public static void main (String... args) throws Exception {
116
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
117
118
String[] instanceKlassNames = new String[] {
119
"LingeredAppWithInvokeDynamic"
120
};
121
122
if (args == null || args.length == 0) {
123
try {
124
theApp = new LingeredAppWithInvokeDynamic();
125
LingeredApp.startApp(theApp, "-XX:+UsePerfData");
126
createAnotherToAttach(instanceKlassNames,
127
theApp.getPid());
128
} finally {
129
LingeredApp.stopApp(theApp);
130
}
131
} else {
132
printBytecodes(args[0], instanceKlassNames);
133
}
134
}
135
}
136
137