Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BreakpointRequest/location/location001.java
41161 views
1
/*
2
* Copyright (c) 2001, 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.BreakpointRequest.location;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* The test for the implementation of an object of the type <BR>
39
* BreakpointRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.BreakpointRequest.location()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks if a Location object, an argument of the method <BR>
46
* EventRequestManager.createBreakpointRequest(Location), <BR>
47
* is equal to one returned by the method BreakpointRequest.location() <BR>
48
* <BR>
49
* The test has three phases and works as follows. <BR>
50
* <BR>
51
* In first phase, <BR>
52
* upon launching debuggee's VM which will be suspended, <BR>
53
* a debugger waits for the VMStartEvent within a predefined <BR>
54
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
55
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
56
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
57
* and waits for the event within the predefined time interval. <BR>
58
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
59
* Upon getting the ClassPrepareEvent, <BR>
60
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
61
* within debuggee's special methodForCommunication(). <BR>
62
* <BR>
63
* In second phase to check the assertion, <BR>
64
* the debugger and the debuggee perform the following. <BR>
65
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
66
* - The debuggee creates new threads, thread1, and invokes <BR>
67
* the methodForCommunication to be suspended and <BR>
68
* to inform the debugger with the event. <BR>
69
* - Upon getting the BreakpointEvent, the debugger <BR>
70
* - creates a BreakpointRequest and gets Location object location1, <BR>
71
* - gets Location object location2 with the method <BR>
72
* BreakpointRequest.location(), <BR>
73
* - compares the Location objects. <BR>
74
* <BR>
75
* In third phase, at the end of the test, <BR>
76
* the debuggee changes the value of the "instruction" which <BR>
77
* the debugger and debuggee use to inform each other of needed actions,<BR>
78
* and both end.
79
* <BR>
80
*/
81
82
public class location001 extends JDIBase {
83
84
public static void main (String argv[]) {
85
86
int result = run(argv, System.out);
87
88
System.exit(result + PASS_BASE);
89
}
90
91
public static int run (String argv[], PrintStream out) {
92
93
int exitCode = new location001().runThis(argv, out);
94
95
if (exitCode != PASSED) {
96
System.out.println("TEST FAILED");
97
}
98
return testExitCode;
99
}
100
101
// ************************************************ test parameters
102
103
private String debuggeeName =
104
"nsk.jdi.BreakpointRequest.location.location001a";
105
106
private String testedClassName =
107
"nsk.jdi.BreakpointRequest.location.TestClass";
108
109
Location location1 = null;
110
Location location2 = null;
111
112
//====================================================== test program
113
114
private int runThis (String argv[], PrintStream out) {
115
116
argsHandler = new ArgumentHandler(argv);
117
logHandler = new Log(out, argsHandler);
118
Binder binder = new Binder(argsHandler, logHandler);
119
120
waitTime = argsHandler.getWaitTime() * 60000;
121
122
try {
123
log2("launching a debuggee :");
124
log2(" " + debuggeeName);
125
if (argsHandler.verbose()) {
126
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
127
} else {
128
debuggee = binder.bindToDebugee(debuggeeName);
129
}
130
if (debuggee == null) {
131
log3("ERROR: no debuggee launched");
132
return FAILED;
133
}
134
log2("debuggee launched");
135
} catch ( Exception e ) {
136
log3("ERROR: Exception : " + e);
137
log2(" test cancelled");
138
return FAILED;
139
}
140
141
debuggee.redirectOutput(logHandler);
142
143
vm = debuggee.VM();
144
145
eventQueue = vm.eventQueue();
146
if (eventQueue == null) {
147
log3("ERROR: eventQueue == null : TEST ABORTED");
148
vm.exit(PASS_BASE);
149
return FAILED;
150
}
151
152
log2("invocation of the method runTest()");
153
switch (runTest()) {
154
155
case 0 : log2("test phase has finished normally");
156
log2(" waiting for the debuggee to finish ...");
157
debuggee.waitFor();
158
159
log2("......getting the debuggee's exit status");
160
int status = debuggee.getStatus();
161
if (status != PASS_BASE) {
162
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
163
status + " != PASS_BASE");
164
testExitCode = FAILED;
165
} else {
166
log2("......debuggee returned expected exit status: " +
167
status + " == PASS_BASE");
168
}
169
break;
170
171
default : log3("ERROR: runTest() returned unexpected value");
172
173
case 1 : log3("test phase has not finished normally: debuggee is still alive");
174
log2("......forcing: vm.exit();");
175
testExitCode = FAILED;
176
try {
177
vm.exit(PASS_BASE);
178
} catch ( Exception e ) {
179
log3("ERROR: Exception : " + e);
180
}
181
break;
182
183
case 2 : log3("test cancelled due to VMDisconnectedException");
184
log2("......trying: vm.process().destroy();");
185
testExitCode = FAILED;
186
try {
187
Process vmProcess = vm.process();
188
if (vmProcess != null) {
189
vmProcess.destroy();
190
}
191
} catch ( Exception e ) {
192
log3("ERROR: Exception : " + e);
193
}
194
break;
195
}
196
197
return testExitCode;
198
}
199
200
201
/*
202
* Return value: 0 - normal end of the test
203
* 1 - ubnormal end of the test
204
* 2 - VMDisconnectedException while test phase
205
*/
206
207
private int runTest() {
208
209
try {
210
testRun();
211
212
log2("waiting for VMDeathEvent");
213
getEventSet();
214
if (eventIterator.nextEvent() instanceof VMDeathEvent)
215
return 0;
216
217
log3("ERROR: last event is not the VMDeathEvent");
218
return 1;
219
} catch ( VMDisconnectedException e ) {
220
log3("ERROR: VMDisconnectedException : " + e);
221
return 2;
222
} catch ( Exception e ) {
223
log3("ERROR: Exception : " + e);
224
return 1;
225
}
226
227
}
228
229
private void testRun()
230
throws JDITestRuntimeException, Exception {
231
232
eventRManager = vm.eventRequestManager();
233
234
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
235
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
236
cpRequest.addClassFilter(debuggeeName);
237
238
cpRequest.enable();
239
vm.resume();
240
getEventSet();
241
cpRequest.disable();
242
243
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
244
debuggeeClass = event.referenceType();
245
246
if (!debuggeeClass.name().equals(debuggeeName))
247
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
248
249
log2(" received: ClassPrepareEvent for debuggeeClass");
250
251
String bPointMethod = "methodForCommunication";
252
String lineForComm = "lineForComm";
253
254
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
255
256
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
257
258
debuggeeClass,
259
bPointMethod, lineForComm, "zero");
260
bpRequest.enable();
261
262
//------------------------------------------------------ testing section
263
264
log1(" TESTING BEGINS");
265
266
EventRequest eventRequest1 = null;
267
268
ThreadReference thread1 = null;
269
String thread1Name = "thread1";
270
271
String property1 = "BreakpointRequest1";
272
273
String methodName = "method";
274
String bpLineName = "breakpointLine";
275
276
ReferenceType testClassReference = null;
277
278
for (int i = 0; ; i++) {
279
280
vm.resume();
281
breakpointForCommunication();
282
283
int instruction = ((IntegerValue)
284
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
285
286
if (instruction == 0) {
287
vm.resume();
288
break;
289
}
290
291
log1(":::::: case: # " + i);
292
293
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
294
295
switch (i) {
296
297
case 0:
298
testClassReference =
299
(ReferenceType) vm.classesByName(testedClassName).get(0);
300
301
thread1 = (ThreadReference) debuggeeClass.getValue(
302
debuggeeClass.fieldByName(thread1Name));
303
304
log2(".....setting up BreakpointRequest and getting Location object location1");
305
eventRequest1 = setting2BreakpointRequest (null,
306
testClassReference, methodName, bpLineName,
307
EventRequest.SUSPEND_NONE, property1);
308
309
log2("......getting: location2 = ((BreakpointRequest) eventRequest1).location();");
310
location2 = ((BreakpointRequest) eventRequest1).location();
311
312
log2(" checking up on equality of location1 and location2");
313
if ( !location1.equals(location2) ) {
314
testExitCode = FAILED;
315
log3("ERROR: Location objects are not equal");
316
}
317
318
break;
319
320
default:
321
throw new JDITestRuntimeException("** default case 2 **");
322
}
323
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
324
}
325
log1(" TESTING ENDS");
326
return;
327
}
328
329
// ============================== test's additional methods
330
331
private BreakpointRequest setting2BreakpointRequest ( ThreadReference thread,
332
ReferenceType testedClass,
333
String methodName,
334
String bpLine,
335
int suspendPolicy,
336
String property )
337
throws JDITestRuntimeException {
338
try {
339
log2("......setting up a breakpoint:");
340
log2(" thread: " + thread + "; class: " + testedClass + "; method: " + methodName + "; line: " + bpLine);
341
342
int n = ( (IntegerValue) testedClass.getValue(testedClass.fieldByName(bpLine) ) ).value();
343
Location loc = (Location) ((Method) testedClass.methodsByName(methodName).get(0)).allLineLocations().get(n);
344
345
location1 = loc;
346
347
BreakpointRequest
348
bpr = eventRManager.createBreakpointRequest(loc);
349
bpr.putProperty("number", property);
350
if (thread != null)
351
bpr.addThreadFilter(thread);
352
bpr.setSuspendPolicy(suspendPolicy);
353
354
log2(" a breakpoint has been set up");
355
return bpr;
356
} catch ( Exception e ) {
357
log3("ERROR: ATTENTION: Exception within settingBreakpointRequest() : " + e);
358
log3(" BreakpointRequest HAS NOT BEEN SET UP");
359
throw new JDITestRuntimeException("** FAILURE to set up BreakpointRequest **");
360
}
361
}
362
363
}
364
365