Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/deleteEventRequests/delevtreqs002.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.EventRequestManager.deleteEventRequests;
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
* EventRequestManager. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequestManager.deleteEventRequests()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* After invoking the tested method, <BR>
47
* the methods returning Lists of requests, <BR>
48
* such as EventRequestManager.accessWatchpointRequests(), <BR>
49
* return a List containing no eventRequests <BR>
50
* deleted by the tested method. <BR>
51
* Testcases include all subclasses of EventRequest. <BR>
52
* <BR>
53
* The test has three phases and works as follows. <BR>
54
* <BR>
55
* In first phase, <BR>
56
* upon launching debuggee's VM which will be suspended, <BR>
57
* a debugger waits for the VMStartEvent within a predefined <BR>
58
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
59
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
60
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
61
* and waits for the event within the predefined time interval. <BR>
62
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
63
* Upon getting the ClassPrepareEvent, <BR>
64
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
65
* within debuggee's special methodForCommunication(). <BR>
66
* <BR>
67
* In second phase to check the assertion, <BR>
68
* the debugger and the debuggee perform the following. <BR>
69
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
70
* - The debuggee prepares testcases and invokes <BR>
71
* the methodForCommunication to be suspended and <BR>
72
* to inform the debugger with the event. <BR>
73
* - Upon getting the BreakpointEvent, <BR>
74
* the debugger performs the checks required. <BR>
75
* <BR>
76
* In third phase, at the end of the test, the debuggee changes <BR>
77
* the value of the "instruction" which the debugger and debuggee <BR>
78
* use to inform each other of needed actions, and both end. <BR>
79
* <BR>
80
*/
81
82
public class delevtreqs002 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 delevtreqs002().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.EventRequestManager.deleteEventRequests.delevtreqs002a";
105
106
//====================================================== test program
107
108
private int runThis (String argv[], PrintStream out) {
109
110
argsHandler = new ArgumentHandler(argv);
111
logHandler = new Log(out, argsHandler);
112
Binder binder = new Binder(argsHandler, logHandler);
113
114
waitTime = argsHandler.getWaitTime() * 60000;
115
116
try {
117
log2("launching a debuggee :");
118
log2(" " + debuggeeName);
119
if (argsHandler.verbose()) {
120
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
121
} else {
122
debuggee = binder.bindToDebugee(debuggeeName);
123
}
124
if (debuggee == null) {
125
log3("ERROR: no debuggee launched");
126
return FAILED;
127
}
128
log2("debuggee launched");
129
} catch ( Exception e ) {
130
log3("ERROR: Exception : " + e);
131
log2(" test cancelled");
132
return FAILED;
133
}
134
135
debuggee.redirectOutput(logHandler);
136
137
vm = debuggee.VM();
138
139
eventQueue = vm.eventQueue();
140
if (eventQueue == null) {
141
log3("ERROR: eventQueue == null : TEST ABORTED");
142
vm.exit(PASS_BASE);
143
return FAILED;
144
}
145
146
log2("invocation of the method runTest()");
147
switch (runTest()) {
148
149
case 0 : log2("test phase has finished normally");
150
log2(" waiting for the debuggee to finish ...");
151
debuggee.waitFor();
152
153
log2("......getting the debuggee's exit status");
154
int status = debuggee.getStatus();
155
if (status != PASS_BASE) {
156
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
157
status + " != PASS_BASE");
158
testExitCode = FAILED;
159
} else {
160
log2("......debuggee returned expected exit status: " +
161
status + " == PASS_BASE");
162
}
163
break;
164
165
default : log3("ERROR: runTest() returned unexpected value");
166
167
case 1 : log3("test phase has not finished normally: debuggee is still alive");
168
log2("......forcing: vm.exit();");
169
testExitCode = FAILED;
170
try {
171
vm.exit(PASS_BASE);
172
} catch ( Exception e ) {
173
log3("ERROR: Exception : " + e);
174
}
175
break;
176
177
case 2 : log3("test cancelled due to VMDisconnectedException");
178
log2("......trying: vm.process().destroy();");
179
testExitCode = FAILED;
180
try {
181
Process vmProcess = vm.process();
182
if (vmProcess != null) {
183
vmProcess.destroy();
184
}
185
} catch ( Exception e ) {
186
log3("ERROR: Exception : " + e);
187
}
188
break;
189
}
190
191
return testExitCode;
192
}
193
194
195
/*
196
* Return value: 0 - normal end of the test
197
* 1 - ubnormal end of the test
198
* 2 - VMDisconnectedException while test phase
199
*/
200
201
private int runTest() {
202
203
try {
204
testRun();
205
206
log2("waiting for VMDeathEvent");
207
getEventSet();
208
if (eventIterator.nextEvent() instanceof VMDeathEvent)
209
return 0;
210
211
log3("ERROR: last event is not the VMDeathEvent");
212
return 1;
213
} catch ( VMDisconnectedException e ) {
214
log3("ERROR: VMDisconnectedException : " + e);
215
return 2;
216
} catch ( Exception e ) {
217
log3("ERROR: Exception : " + e);
218
return 1;
219
}
220
221
}
222
223
private void testRun()
224
throws JDITestRuntimeException, Exception {
225
226
eventRManager = vm.eventRequestManager();
227
228
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
229
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
230
cpRequest.addClassFilter(debuggeeName);
231
232
cpRequest.enable();
233
vm.resume();
234
getEventSet();
235
cpRequest.disable();
236
237
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
238
debuggeeClass = event.referenceType();
239
240
if (!debuggeeClass.name().equals(debuggeeName))
241
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
242
243
log2(" received: ClassPrepareEvent for debuggeeClass");
244
245
String bPointMethod = "methodForCommunication";
246
String lineForComm = "lineForComm";
247
248
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
249
250
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
251
debuggeeClass,
252
bPointMethod, lineForComm, "zero");
253
bpRequest.enable();
254
255
//------------------------------------------------------ testing section
256
257
final int length1 = 10;
258
final int length2 = 12;
259
EventRequest requestArray[][] = new EventRequest[length1][length2];
260
261
String fieldName1 = "testField1";
262
String fieldName2 = "testField2";
263
String fieldName3 = "testField3";
264
265
List<EventRequest> requests = null;
266
ListIterator li = null;
267
268
log1(" TESTING BEGINS");
269
270
for (int i = 0; ; i++) {
271
272
vm.resume();
273
breakpointForCommunication();
274
275
int instruction = ((IntegerValue)
276
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
277
278
if (instruction == 0) {
279
vm.resume();
280
break;
281
}
282
283
log1(":::::: case: # " + i);
284
285
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
286
287
288
Field field1 = debuggeeClass.fieldByName(fieldName1);
289
290
ReferenceType refType = (ReferenceType)
291
debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2)).type();
292
293
294
log2("......creating EventRequests");
295
for (int i1 = 0; i1 < length1; i1++) {
296
297
ThreadReference threadRef = (ThreadReference)
298
( (ArrayReference) debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName3))
299
).getValue(i1);
300
301
requestArray[i1][0] = eventRManager.createAccessWatchpointRequest(field1);
302
requestArray[i1][1] = eventRManager.createModificationWatchpointRequest(field1);
303
requestArray[i1][2] = eventRManager.createBreakpointRequest(breakpLocation);
304
requestArray[i1][3] = eventRManager.createClassPrepareRequest();
305
requestArray[i1][4] = eventRManager.createClassUnloadRequest();
306
requestArray[i1][5] = eventRManager.createExceptionRequest(refType, false, false);
307
requestArray[i1][6] = eventRManager.createMethodEntryRequest();
308
requestArray[i1][7] = eventRManager.createMethodExitRequest();
309
requestArray[i1][8] = eventRManager.createStepRequest(threadRef, StepRequest.STEP_MIN, StepRequest.STEP_OUT);
310
requestArray[i1][9] = eventRManager.createThreadDeathRequest();
311
requestArray[i1][10] = eventRManager.createThreadStartRequest();
312
requestArray[i1][11] = eventRManager.createVMDeathRequest();
313
}
314
for ( int ii1 = 0; ii1 < length1; ii1++) {
315
for ( int ii2 = 0; ii2 < length2; ii2++) {
316
requestArray[ii1][ii2].putProperty("number", "request " + ii1 + " " + ii2);
317
}
318
}
319
320
321
log2("......deleting Requests and checking up on Lists");
322
for (int i2 = 0; i2 < length1; i2++) {
323
324
EventRequest awRequest = requestArray[i2][0];
325
EventRequest mwRequest = requestArray[i2][1];
326
EventRequest bp1Request = requestArray[i2][2];
327
EventRequest cp1Request = requestArray[i2][3];
328
EventRequest cuRequest = requestArray[i2][4];
329
EventRequest exRequest = requestArray[i2][5];
330
EventRequest menRequest = requestArray[i2][6];
331
EventRequest mexRequest = requestArray[i2][7];
332
EventRequest stRequest = requestArray[i2][8];
333
EventRequest tdRequest = requestArray[i2][9];
334
EventRequest tsRequest = requestArray[i2][10];
335
EventRequest vmdRequest = requestArray[i2][11];
336
337
requests = new LinkedList<EventRequest>();
338
339
try {
340
requests.add(awRequest);
341
requests.add(mwRequest);
342
requests.add(bp1Request);
343
requests.add(cp1Request);
344
requests.add(cuRequest);
345
requests.add(exRequest);
346
requests.add(menRequest);
347
requests.add(mexRequest);
348
requests.add(stRequest);
349
requests.add(tdRequest);
350
requests.add(tsRequest);
351
requests.add(vmdRequest);
352
} catch ( UnsupportedOperationException e ) {
353
testExitCode = FAILED;
354
log3("ERROR: unexpected UnsupportedOperationException");
355
break;
356
}
357
358
eventRManager.deleteEventRequests(requests);
359
360
for (EventRequest er : eventRManager.accessWatchpointRequests()) {
361
if ( er.equals(awRequest) ) {
362
testExitCode = FAILED;
363
log3("ERROR: deleted AccessWatchpointRequest is in the List :: " + er.getProperty("number") );
364
}
365
}
366
367
for (EventRequest er : eventRManager.modificationWatchpointRequests()) {
368
if ( er.equals(mwRequest) ) {
369
testExitCode = FAILED;
370
log3("ERROR: deleted ModificationWatchpointRequest is in the List :: " + er.getProperty("number") );
371
}
372
}
373
374
for (EventRequest er : eventRManager.breakpointRequests()) {
375
if ( er.equals(bp1Request) ) {
376
testExitCode = FAILED;
377
log3("ERROR: deleted BreakpointRequest is in the List :: " + er.getProperty("number") );
378
}
379
}
380
381
for (EventRequest er : eventRManager.classPrepareRequests()) {
382
if ( er.equals(cp1Request) ) {
383
testExitCode = FAILED;
384
log3("ERROR: deleted ClassPrepareRequest is in the List :: " + er.getProperty("number") );
385
}
386
}
387
388
for (EventRequest er : eventRManager.classUnloadRequests()) {
389
if ( er.equals(cuRequest) ) {
390
testExitCode = FAILED;
391
log3("ERROR: deleted ClassUnloadRequest is in the List :: " + er.getProperty("number") );
392
}
393
}
394
395
for (EventRequest er : eventRManager.exceptionRequests()) {
396
if ( er.equals(exRequest) ) {
397
testExitCode = FAILED;
398
log3("ERROR: deleted ExceptionRequest is in the List :: " + er.getProperty("number") );
399
}
400
}
401
402
for (EventRequest er : eventRManager.methodEntryRequests()) {
403
if ( er.equals(menRequest) ) {
404
testExitCode = FAILED;
405
log3("ERROR: deleted MethodEntryRequest is in the List :: " + er.getProperty("number") );
406
}
407
}
408
409
for (EventRequest er : eventRManager.methodExitRequests()) {
410
if ( er.equals(mexRequest) ) {
411
testExitCode = FAILED;
412
log3("ERROR: deleted MethodExitRequest is in the List :: " + er.getProperty("number") );
413
}
414
}
415
416
for (EventRequest er : eventRManager.stepRequests()) {
417
if ( er.equals(stRequest) ) {
418
testExitCode = FAILED;
419
log3("ERROR: deleted StepRequest is in the List :: " + er.getProperty("number") );
420
}
421
}
422
423
for (EventRequest er : eventRManager.threadDeathRequests()) {
424
if ( er.equals(tdRequest) ) {
425
testExitCode = FAILED;
426
log3("ERROR: deleted ThreadDeathRequest is in the List :: " + er.getProperty("number") );
427
}
428
}
429
430
for (EventRequest er : eventRManager.threadStartRequests()) {
431
if ( er.equals(tsRequest) ) {
432
testExitCode = FAILED;
433
log3("ERROR: deleted ThreadStartRequest is in the List :: " + er.getProperty("number") );
434
}
435
}
436
437
for (EventRequest er : eventRManager.vmDeathRequests()) {
438
if ( er.equals(vmdRequest) ) {
439
testExitCode = FAILED;
440
log3("ERROR: deleted VMDeathRequest is in the List :: " + er.getProperty("number") );
441
}
442
}
443
}
444
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
445
}
446
log1(" TESTING ENDS");
447
return;
448
}
449
450
}
451
452