Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/HiddenClass/events/DebuggerBase.java
41161 views
1
/*
2
* Copyright (c) 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
package nsk.jdi.HiddenClass.events;
25
26
import com.sun.jdi.ClassType;
27
import com.sun.jdi.ClassObjectReference;
28
import com.sun.jdi.Field;
29
import com.sun.jdi.Method;
30
import com.sun.jdi.ReferenceType;
31
import com.sun.jdi.ThreadReference;
32
import com.sun.jdi.Value;
33
import com.sun.jdi.VirtualMachine;
34
35
import com.sun.jdi.event.EventSet;
36
import com.sun.jdi.request.EventRequest;
37
import com.sun.jdi.request.EventRequestManager;
38
import com.sun.jdi.request.BreakpointRequest;
39
import com.sun.jdi.request.ClassPrepareRequest;
40
import com.sun.jdi.request.ClassUnloadRequest;
41
import com.sun.jdi.request.ModificationWatchpointRequest;
42
43
import java.io.PrintStream;
44
import java.util.ArrayList;
45
import java.util.List;
46
import jdk.test.lib.Asserts;
47
48
import nsk.share.Log;
49
import nsk.share.jdi.ArgumentHandler;
50
import nsk.share.jdi.Binder;
51
import nsk.share.jdi.Debugee;
52
import nsk.share.jpda.IOPipe;
53
54
// This class is the test debugger base class
55
public class DebuggerBase {
56
public static final int PASSED = 0;
57
public static final int FAILED = 2;
58
public static final int JCK_STATUS_BASE = 95;
59
60
public static final String COMMAND_READY = "ready";
61
public static final String COMMAND_RUN = "run";
62
public static final String COMMAND_DONE = "done";
63
public static final String COMMAND_ERROR = "error";
64
public static final String COMMAND_QUIT = "quit";
65
66
public final Log log;
67
68
private VirtualMachine vm;
69
private Debugee debuggee = null;
70
private IOPipe pipe = null;
71
private EventRequestManager erManager = null;
72
73
protected DebuggerBase(ArgumentHandler argHandler) {
74
log = new Log(System.out, argHandler);
75
}
76
77
VirtualMachine vm() {
78
return vm;
79
}
80
81
// Find a ReferenceType by a given type name.
82
ReferenceType getReferenceType(String typeName) {
83
List<ReferenceType> list = vm.classesByName(typeName);
84
85
Asserts.assertFalse(list.size() == 0, "FAIL: type not found: " + typeName);
86
Asserts.assertFalse(list.size() > 1, "FAIL: multiple types found: " + typeName);
87
log.display(" Found type: " + typeName);
88
return list.get(0);
89
}
90
91
// Find a Field by a given ReferenceType and a field name.
92
Field findField(ReferenceType refType, String fieldName) {
93
Field field = refType.fieldByName(fieldName);
94
String fullName = refType.name() + "::" + fieldName;
95
96
Asserts.assertNotNull(field, "FAIL: field not found: " + fullName);
97
log.display(" Found field: " + fullName);
98
return field;
99
}
100
101
// Find a Method by a given ReferenceType and a method name.
102
Method findMethod(ReferenceType refType, String methodName) {
103
List<Method> list = refType.methodsByName(methodName);
104
String fullName = refType.name() + "::" + methodName;
105
106
Asserts.assertFalse(list.size() == 0, "FAIL: method not found: " + fullName);
107
Asserts.assertFalse(list.size() > 1, "FAIL: multiple methods found: " + fullName);
108
109
log.display(" Found method: " + fullName);
110
return list.get(0);
111
}
112
113
// Invoke a given static method in debuggee VM at an eventpoint.
114
boolean invokeStaticMethod(ThreadReference thread, Method methodToInvoke) {
115
boolean failedStatus = false;
116
List<? extends Value> args = new ArrayList<>();
117
int flags = (ClassObjectReference.INVOKE_NONVIRTUAL |
118
ClassObjectReference.INVOKE_SINGLE_THREADED);
119
try {
120
log.display(" invoking method: " + methodToInvoke);
121
ClassType type = (ClassType)methodToInvoke.declaringType();
122
Value val = type.invokeMethod(thread, methodToInvoke, args, flags);
123
log.display(" method getHCField returned result: " + val);
124
} catch (Exception ex) {
125
log.complain("Exception in HC::getHCField method invocation: " + ex);
126
failedStatus = true;
127
}
128
return failedStatus;
129
}
130
131
protected void launchDebuggee(ArgumentHandler argHandler, String debuggeeName) {
132
Binder binder = new Binder(argHandler, log);
133
log.display("\n# Connecting to debuggee");
134
135
debuggee = binder.bindToDebugee(debuggeeName);
136
debuggee.redirectStderr(log, "debuggee >");
137
138
pipe = debuggee.createIOPipe();
139
vm = debuggee.VM();
140
erManager = vm.eventRequestManager();
141
142
log.display("# Resuming debuggee");
143
debuggee.resume();
144
}
145
146
protected boolean shutdownDebuggee() {
147
boolean debuggeeFailed = false;
148
log.display("\n# Shutting down debuggee");
149
150
// wait for debuggee exits and analize its exit code
151
log.display("# Waiting for debuggee terminating");
152
int debuggeeStatus = debuggee.endDebugee();
153
if (debuggeeStatus == PASSED + JCK_STATUS_BASE) {
154
log.display("# Debuggee PASSED with exit code: " + debuggeeStatus);
155
} else {
156
log.complain("# Debuggee FAILED with exit code: " + debuggeeStatus);
157
debuggeeFailed = true;
158
}
159
return debuggeeFailed;
160
}
161
162
protected EventRequest enableBreakpointRequest(Method method) {
163
log.display("\n# Creating BreakpointRequest");
164
BreakpointRequest request = erManager.createBreakpointRequest(method.location());
165
Asserts.assertNotNull(request, "FAIL: unable to create BreakpointRequest");
166
167
// enable event request
168
request.enable();
169
log.display(" Enabled BreakpointRequest");
170
return request;
171
}
172
173
protected EventRequest enableClassPrepareRequest(String classFilter) {
174
log.display("\n# Creating ClassPrepareRequest");
175
ClassPrepareRequest request = erManager.createClassPrepareRequest();
176
Asserts.assertNotNull(request, "FAIL: unable to create ClassPrepareRequest");
177
178
if (classFilter != null) {
179
log.display(" Adding filter to ClassPrepareRequest: " + classFilter);
180
request.addClassFilter(classFilter);
181
}
182
// enable event request
183
request.enable();
184
log.display(" Enabled ClassPrepareRequest");
185
return request;
186
}
187
188
protected EventRequest enableClassUnloadRequest(String classFilter) {
189
log.display("\n# Creating request for ClassUnloadEvent");
190
ClassUnloadRequest request = erManager.createClassUnloadRequest();
191
Asserts.assertNotNull(request, "FAIL: unable to create ClassUnloadRequest");
192
193
if (classFilter != null) {
194
log.display(" Adding filter to ClassUnloadRequest: " + classFilter);
195
request.addClassFilter(classFilter);
196
}
197
// enable event request
198
request.enable();
199
log.display(" Enabled ClassUnloadRequest");
200
return request;
201
}
202
203
protected EventRequest enableModificationWatchpointRequest(Field field, String classFilter) {
204
log.display("\n# Creating request for ModificationWatchpointRequest");
205
206
ModificationWatchpointRequest request = erManager.createModificationWatchpointRequest(field);
207
Asserts.assertNotNull(request, "FAIL: unable to create ModificationWatchpointRequest");
208
209
if (classFilter != null) {
210
log.display(" Adding filter to ModificationWatchpointRequest: " + classFilter);
211
request.addClassFilter(classFilter);
212
}
213
// enable event request
214
request.enable();
215
log.display(" Enabled ModificationWatchpointRequest");
216
return request;
217
}
218
219
protected void disableRequest(EventRequest eq, String reqestName) {
220
// disable event requests to prevent appearance of further events
221
if (eq != null && eq.isEnabled()) {
222
log.display(" Disabling " + reqestName);
223
eq.disable();
224
}
225
}
226
227
// sync on the COMMAND_READY
228
protected void readyCmdSync() {
229
// wait for READY signal from debugee
230
log.display("\n# Waiting for command: " + COMMAND_READY);
231
String command = pipe.readln();
232
Asserts.assertFalse(command == null || !command.equals(COMMAND_READY),
233
"FAIL: unexpected debuggee's command: " + command);
234
log.display("\n# Got command: " + COMMAND_READY);
235
}
236
237
// sync on the COMMAND_RUN
238
protected void runCmdSync() {
239
// activate debugee
240
log.display("\n# Sending command: " + COMMAND_RUN);
241
pipe.println(COMMAND_RUN);
242
}
243
244
// sync on the COMMAND_DONE
245
protected void doneCmdSync() {
246
// wait for DONE signal from debugee
247
log.display("\n# Waiting for command: " + COMMAND_DONE);
248
String command = pipe.readln();
249
Asserts.assertFalse(command == null || !command.equals(COMMAND_DONE),
250
"FAIL: unexpected debuggee's command: " + command);
251
log.display("\n# Got command: " + COMMAND_DONE);
252
}
253
254
// sync on the COMMAND_QUIT
255
protected void quitCmdSync() {
256
// force debugee to exit
257
log.display("\n# Sending command: " + COMMAND_QUIT);
258
pipe.println(COMMAND_QUIT);
259
}
260
}
261
262