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