Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume005.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.EventSet.resume;
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
* EventSet. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventSet.resume()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* Test cases include all three possible suspensions, NONE, <BR>
46
* EVENT_THREAD, and ALL, for ExceptionEvent sets. <BR>
47
* <BR>
48
* To check up on the method, a debugger, <BR>
49
* upon getting new set for the EventSet, <BR>
50
* suspends VM with the method VirtualMachine.suspend(), <BR>
51
* gets the List of debuggee's threads calling VM.allThreads(), <BR>
52
* invokes the method EventSet.resume(), and <BR>
53
* gets another List of debuggee's threads. <BR>
54
* The debugger then compares values of <BR>
55
* each thread's suspendCount from first and second Lists. <BR>
56
* <BR>
57
* The test has three phases and works as follows. <BR>
58
* <BR>
59
* In first phase, <BR>
60
* upon launching debuggee's VM which will be suspended, <BR>
61
* a debugger waits for the VMStartEvent within a predefined <BR>
62
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
63
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
64
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
65
* and waits for the event within the predefined time interval. <BR>
66
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
67
* Upon getting the ClassPrepareEvent, <BR>
68
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
69
* within debuggee's special methodForCommunication(). <BR>
70
* <BR>
71
* In second phase to check the above, <BR>
72
* the debugger and the debuggee perform the following loop. <BR>
73
* - The debugger sets up a ExceptionRequest, resumes <BR>
74
* the debuggee, and waits for the ExceptionEvent. <BR>
75
* - The debuggee invokes the special method which makes access to <BR>
76
* a predefined variable to be resulting in the event. <BR>
77
* - Upon getting new event, the debugger <BR>
78
* performs the check corresponding to the event. <BR>
79
* <BR>
80
* Note. To inform each other of needed actions, the debugger and <BR>
81
* and the debuggee use debuggee's variable "instruction". <BR>
82
* In third phase, at the end, <BR>
83
* the debuggee changes the value of the "instruction" <BR>
84
* to inform the debugger of checks finished, and both end. <BR>
85
* <BR>
86
*/
87
88
public class resume005 extends JDIBase {
89
90
public static void main (String argv[]) {
91
92
int result = run(argv, System.out);
93
94
System.exit(result + PASS_BASE);
95
}
96
97
public static int run (String argv[], PrintStream out) {
98
99
int exitCode = new resume005().runThis(argv, out);
100
101
if (exitCode != PASSED) {
102
System.out.println("TEST FAILED");
103
}
104
return testExitCode;
105
}
106
107
// ************************************************ test parameters
108
109
private String debuggeeName =
110
"nsk.jdi.EventSet.resume.resume005a";
111
112
private String testedClassName =
113
"nsk.jdi.EventSet.resume.resume005aTestClass";
114
115
//====================================================== test program
116
117
private int runThis (String argv[], PrintStream out) {
118
119
argsHandler = new ArgumentHandler(argv);
120
logHandler = new Log(out, argsHandler);
121
Binder binder = new Binder(argsHandler, logHandler);
122
123
waitTime = argsHandler.getWaitTime() * 60000;
124
125
try {
126
log2("launching a debuggee :");
127
log2(" " + debuggeeName);
128
if (argsHandler.verbose()) {
129
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
130
} else {
131
debuggee = binder.bindToDebugee(debuggeeName);
132
}
133
if (debuggee == null) {
134
log3("ERROR: no debuggee launched");
135
return FAILED;
136
}
137
log2("debuggee launched");
138
} catch ( Exception e ) {
139
log3("ERROR: Exception : " + e);
140
log2(" test cancelled");
141
return FAILED;
142
}
143
144
debuggee.redirectOutput(logHandler);
145
146
vm = debuggee.VM();
147
148
eventQueue = vm.eventQueue();
149
if (eventQueue == null) {
150
log3("ERROR: eventQueue == null : TEST ABORTED");
151
vm.exit(PASS_BASE);
152
return FAILED;
153
}
154
155
log2("invocation of the method runTest()");
156
switch (runTest()) {
157
158
case 0 : log2("test phase has finished normally");
159
log2(" waiting for the debuggee to finish ...");
160
debuggee.waitFor();
161
162
log2("......getting the debuggee's exit status");
163
int status = debuggee.getStatus();
164
if (status != PASS_BASE) {
165
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
166
status + " != PASS_BASE");
167
testExitCode = FAILED;
168
} else {
169
log2("......debuggee returned expected exit status: " +
170
status + " == PASS_BASE");
171
}
172
break;
173
174
default : log3("ERROR: runTest() returned unexpected value");
175
176
case 1 : log3("test phase has not finished normally: debuggee is still alive");
177
log2("......forcing: vm.exit();");
178
testExitCode = FAILED;
179
try {
180
vm.exit(PASS_BASE);
181
} catch ( Exception e ) {
182
log3("ERROR: Exception : e");
183
}
184
break;
185
186
case 2 : log3("test cancelled due to VMDisconnectedException");
187
log2("......trying: vm.process().destroy();");
188
testExitCode = FAILED;
189
try {
190
Process vmProcess = vm.process();
191
if (vmProcess != null) {
192
vmProcess.destroy();
193
}
194
} catch ( Exception e ) {
195
log3("ERROR: Exception : e");
196
}
197
break;
198
}
199
200
return testExitCode;
201
}
202
203
204
/*
205
* Return value: 0 - normal end of the test
206
* 1 - ubnormal end of the test
207
* 2 - VMDisconnectedException while test phase
208
*/
209
210
private int runTest() {
211
212
try {
213
testRun();
214
215
log2("waiting for VMDeathEvent");
216
getEventSet();
217
if (eventIterator.nextEvent() instanceof VMDeathEvent)
218
return 0;
219
220
log3("ERROR: last event is not the VMDeathEvent");
221
return 1;
222
} catch ( VMDisconnectedException e ) {
223
log3("ERROR: VMDisconnectedException : " + e);
224
return 2;
225
} catch ( Exception e ) {
226
log3("ERROR: Exception : " + e);
227
return 1;
228
}
229
230
}
231
232
private void testRun()
233
throws JDITestRuntimeException, Exception {
234
235
eventRManager = vm.eventRequestManager();
236
237
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
238
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
239
cpRequest.addClassFilter(debuggeeName);
240
241
cpRequest.enable();
242
vm.resume();
243
getEventSet();
244
cpRequest.disable();
245
246
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
247
debuggeeClass = event.referenceType();
248
249
if (!debuggeeClass.name().equals(debuggeeName))
250
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
251
252
log2(" received: ClassPrepareEvent for debuggeeClass");
253
254
String bPointMethod = "methodForCommunication";
255
String lineForComm = "lineForComm";
256
BreakpointRequest bpRequest;
257
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
258
bpRequest = settingBreakpoint(mainThread,
259
debuggeeClass,
260
bPointMethod, lineForComm, "zero");
261
bpRequest.enable();
262
263
vm.resume();
264
265
//------------------------------------------------------ testing section
266
267
log1(" TESTING BEGINS");
268
269
EventRequest eventRequest1 = null;
270
EventRequest eventRequest2 = null;
271
EventRequest eventRequest3 = null;
272
273
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
274
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
275
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
276
277
String methodName = "method";
278
String bpLineName = "breakpointLine";
279
280
ReferenceType testClassReference = null;
281
282
283
for (int i = 0; ; i++) {
284
285
breakpointForCommunication();
286
287
int instruction = ((IntegerValue)
288
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
289
290
if (instruction == 0) {
291
vm.resume();
292
break;
293
}
294
295
log1(":::::: case: # " + i);
296
297
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
298
299
switch (i) {
300
301
case 0:
302
testClassReference =
303
(ReferenceType) vm.classesByName(testedClassName).get(0);
304
305
eventRequest1 = settingExceptionRequest (mainThread,
306
debuggeeClass, // testClassReference,
307
SUSPEND_NONE, "ExceptionRequest1");
308
eventRequest1.enable();
309
break;
310
311
case 1:
312
eventRequest2 = settingExceptionRequest (mainThread,
313
debuggeeClass, // testClassReference,
314
SUSPEND_THREAD, "ExceptionRequest2");
315
eventRequest2.enable();
316
break;
317
318
case 2:
319
eventRequest3 = settingExceptionRequest (mainThread,
320
debuggeeClass, // testClassReference,
321
SUSPEND_ALL, "ExceptionRequest3");
322
eventRequest3.enable();
323
break;
324
325
326
default:
327
throw new JDITestRuntimeException("** default case 2 **");
328
}
329
330
log2("......waiting for new ExceptionEvent : " + i);
331
mainThread.resume();
332
getEventSet();
333
334
Event newEvent = eventIterator.nextEvent();
335
if ( !(newEvent instanceof ExceptionEvent)) {
336
log3("ERROR: new event is not ExceptionEvent");
337
testExitCode = FAILED;
338
} else {
339
340
String property = (String) newEvent.request().getProperty("number");
341
log2(" got new ExceptionEvent with propety 'number' == " + property);
342
343
log2("......checking up on EventSet.resume()");
344
log2("......--> vm.suspend();");
345
vm.suspend();
346
347
log2(" getting : Map<String, Integer> suspendsCounts1");
348
349
Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();
350
for (ThreadReference threadReference : vm.allThreads()) {
351
suspendsCounts1.put(threadReference.name(), threadReference.suspendCount());
352
}
353
354
log2(" eventSet.resume;");
355
eventSet.resume();
356
357
log2(" getting : Map<String, Integer> suspendsCounts2");
358
Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();
359
for (ThreadReference threadReference : vm.allThreads()) {
360
suspendsCounts2.put(threadReference.name(), threadReference.suspendCount());
361
}
362
363
log2(suspendsCounts1.toString());
364
log2(suspendsCounts2.toString());
365
366
log2(" getting : int policy = eventSet.suspendPolicy();");
367
int policy = eventSet.suspendPolicy();
368
369
switch (policy) {
370
371
case SUSPEND_NONE :
372
log2(" case SUSPEND_NONE");
373
for (String threadName : suspendsCounts1.keySet()) {
374
log2(" checking " + threadName);
375
if (!suspendsCounts2.containsKey(threadName)) {
376
log3("ERROR: couldn't get ThreadReference for " + threadName);
377
testExitCode = FAILED;
378
break;
379
}
380
int count1 = suspendsCounts1.get(threadName);
381
int count2 = suspendsCounts2.get(threadName);
382
if (count1 != count2) {
383
log3("ERROR: suspendCounts don't match for : " + threadName);
384
log3("before resuming : " + count1);
385
log3("after resuming : " + count2);
386
testExitCode = FAILED;
387
break;
388
}
389
}
390
eventRequest1.disable();
391
break;
392
393
case SUSPEND_THREAD :
394
log2(" case SUSPEND_THREAD");
395
for (String threadName : suspendsCounts1.keySet()) {
396
log2("checking " + threadName);
397
if (!suspendsCounts2.containsKey(threadName)) {
398
log3("ERROR: couldn't get ThreadReference for " + threadName);
399
testExitCode = FAILED;
400
break;
401
}
402
int count1 = suspendsCounts1.get(threadName);
403
int count2 = suspendsCounts2.get(threadName);
404
String eventThreadName = ((ExceptionEvent)newEvent).thread().name();
405
int expectedValue = count2 + (eventThreadName.equals(threadName) ? 1 : 0);
406
if (count1 != expectedValue) {
407
log3("ERROR: suspendCounts don't match for : " + threadName);
408
log3("before resuming : " + count1);
409
log3("after resuming : " + count2);
410
testExitCode = FAILED;
411
break;
412
}
413
}
414
eventRequest2.disable();
415
break;
416
417
case SUSPEND_ALL :
418
419
log2(" case SUSPEND_ALL");
420
for (String threadName : suspendsCounts1.keySet()) {
421
log2("checking " + threadName);
422
if (!event.request().equals(eventRequest3))
423
break;
424
if (!suspendsCounts2.containsKey(threadName)) {
425
log3("ERROR: couldn't get ThreadReference for " + threadName);
426
testExitCode = FAILED;
427
break;
428
}
429
int count1 = suspendsCounts1.get(threadName);
430
int count2 = suspendsCounts2.get(threadName);
431
if (count1 != count2 + 1) {
432
log3("ERROR: suspendCounts don't match for : " + threadName);
433
log3("before resuming : " + count1);
434
log3("after resuming : " + count2);
435
testExitCode = FAILED;
436
break;
437
}
438
}
439
eventRequest3.disable();
440
break;
441
442
default: throw new JDITestRuntimeException("** default case 1 **");
443
}
444
informDebuggeeTestCase(i);
445
}
446
447
log2("......--> vm.resume()");
448
vm.resume();
449
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450
}
451
log1(" TESTING ENDS");
452
return;
453
}
454
455
// ============================== test's additional methods
456
457
private ExceptionRequest settingExceptionRequest ( ThreadReference thread,
458
ReferenceType testedClass,
459
int suspendPolicy,
460
String property )
461
throws JDITestRuntimeException {
462
try {
463
log2("......setting up ExceptionRequest:");
464
log2(" thread: " + thread + "; class: " + testedClass + "; property: " + property);
465
466
ExceptionRequest
467
excr = eventRManager.createExceptionRequest(null, true, true);
468
excr.putProperty("number", property);
469
excr.addThreadFilter(thread);
470
excr.addClassFilter(testedClass);
471
excr.setSuspendPolicy(suspendPolicy);
472
473
log2(" ExceptionRequest has been set up");
474
return excr;
475
} catch ( Exception e ) {
476
log3("ERROR: ATTENTION: Exception within settingExceptionRequest() : " + e);
477
log3(" ExceptionRequest HAS NOT BEEN SET UP");
478
throw new JDITestRuntimeException("** FAILURE to set up ExceptionRequest **");
479
}
480
}
481
/**
482
* Inform debuggee which thread test the debugger has completed.
483
* Used for synchronization, so the debuggee does not move too quickly.
484
* @param testCase index of just completed test
485
*/
486
void informDebuggeeTestCase(int testCase) {
487
try {
488
((ClassType)debuggeeClass)
489
.setValue(debuggeeClass.fieldByName("testCase"),
490
vm.mirrorOf(testCase));
491
} catch (InvalidTypeException ite) {
492
throw new Failure("** FAILURE setting testCase **");
493
} catch (ClassNotLoadedException cnle) {
494
throw new Failure("** FAILURE notifying debuggee **");
495
} catch (VMDisconnectedException e) {
496
throw new Failure("** FAILURE debuggee connection **");
497
}
498
}
499
}
500
501