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/resume010.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 StepEvent 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 StepRequest, resumes <BR>
74
* the debuggee, and waits for the StepEvent. <BR>
75
* - The debuggee invokes the special method <BR>
76
* 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 resume010 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 resume010().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.resume010a";
111
112
private String testedClassName =
113
"nsk.jdi.EventSet.resume.resume010aTestClass";
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
ReferenceType testClassReference = null;
278
279
for (int i = 0; ; i++) {
280
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
eventRequest1 = settingStepRequest (mainThread,
299
SUSPEND_NONE, "StepRequest1");
300
eventRequest1.enable();
301
break;
302
303
case 1:
304
eventRequest2 = settingStepRequest (mainThread,
305
SUSPEND_THREAD, "StepRequest2");
306
eventRequest2.enable();
307
break;
308
309
case 2:
310
eventRequest3 = settingStepRequest (mainThread,
311
312
SUSPEND_ALL, "StepRequest3");
313
eventRequest3.enable();
314
break;
315
316
317
default:
318
throw new JDITestRuntimeException("** default case 2 **");
319
}
320
321
log2("......waiting for new StepEvent : " + i);
322
mainThread.resume();
323
getEventSet();
324
325
Event newEvent = eventIterator.nextEvent();
326
if ( !(newEvent instanceof StepEvent)) {
327
log3("ERROR: new event is not StepEvent");
328
testExitCode = FAILED;
329
} else {
330
331
String property = (String) newEvent.request().getProperty("number");
332
log2(" got new StepEvent with propety 'number' == " + property);
333
334
log2("......checking up on EventSet.resume()");
335
log2("......--> vm.suspend();");
336
vm.suspend();
337
338
log2(" getting : Map<String, Integer> suspendsCounts1");
339
340
Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();
341
for (ThreadReference threadReference : vm.allThreads()) {
342
suspendsCounts1.put(threadReference.name(), threadReference.suspendCount());
343
}
344
345
log2(" eventSet.resume;");
346
eventSet.resume();
347
348
log2(" getting : Map<String, Integer> suspendsCounts2");
349
350
Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();
351
for (ThreadReference threadReference : vm.allThreads()) {
352
suspendsCounts2.put(threadReference.name(), threadReference.suspendCount());
353
}
354
355
log2(suspendsCounts1.toString());
356
log2(suspendsCounts2.toString());
357
358
log2(" getting : int policy = eventSet.suspendPolicy();");
359
int policy = eventSet.suspendPolicy();
360
361
switch (policy) {
362
363
case SUSPEND_NONE:
364
365
log2(" case SUSPEND_NONE");
366
for (String threadName : suspendsCounts1.keySet()) {
367
log2(" checking " + threadName);
368
if (!suspendsCounts2.containsKey(threadName)) {
369
log3("ERROR: couldn't get ThreadReference for " + threadName);
370
testExitCode = FAILED;
371
break;
372
}
373
int count1 = suspendsCounts1.get(threadName);
374
int count2 = suspendsCounts2.get(threadName);
375
if (count1 != count2) {
376
log3("ERROR: suspendCounts don't match for : " + threadName);
377
log3("before resuming : " + count1);
378
log3("after resuming : " + count2);
379
testExitCode = FAILED;
380
break;
381
}
382
}
383
eventRequest1.disable();
384
break;
385
386
case SUSPEND_THREAD:
387
388
log2(" case SUSPEND_THREAD");
389
for (String threadName : suspendsCounts1.keySet()) {
390
log2("checking " + threadName);
391
if (!suspendsCounts2.containsKey(threadName)) {
392
log3("ERROR: couldn't get ThreadReference for " + threadName);
393
testExitCode = FAILED;
394
break;
395
}
396
int count1 = suspendsCounts1.get(threadName);
397
int count2 = suspendsCounts2.get(threadName);
398
String eventThreadName = ((StepEvent) newEvent).thread().name();
399
int expectedValue = count2 + (eventThreadName.equals(threadName) ? 1 : 0);
400
if (count1 != expectedValue) {
401
log3("ERROR: suspendCounts don't match for : " + threadName);
402
log3("before resuming : " + count1);
403
log3("after resuming : " + count2);
404
testExitCode = FAILED;
405
break;
406
}
407
}
408
eventRequest2.disable();
409
break;
410
411
case SUSPEND_ALL:
412
413
log2(" case SUSPEND_ALL");
414
for (String threadName : suspendsCounts1.keySet()) {
415
log2("checking " + threadName);
416
if (!event.request().equals(eventRequest3))
417
break;
418
if (!suspendsCounts2.containsKey(threadName)) {
419
log3("ERROR: couldn't get ThreadReference for " + threadName);
420
testExitCode = FAILED;
421
break;
422
}
423
int count1 = suspendsCounts1.get(threadName);
424
int count2 = suspendsCounts2.get(threadName);
425
if (count1 != count2 + 1) {
426
log3("ERROR: suspendCounts don't match for : " + threadName);
427
log3("before resuming : " + count1);
428
log3("after resuming : " + count2);
429
testExitCode = FAILED;
430
break;
431
}
432
}
433
eventRequest3.disable();
434
break;
435
436
default:
437
throw new JDITestRuntimeException("** default case 1 **");
438
}
439
informDebuggeeTestCase(i);
440
}
441
442
log2("......--> vm.resume()");
443
vm.resume();
444
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
445
}
446
log1(" TESTING ENDS");
447
return;
448
}
449
450
// ============================== test's additional methods
451
452
private StepRequest settingStepRequest ( ThreadReference thread,
453
int suspendPolicy,
454
String property )
455
throws JDITestRuntimeException {
456
try {
457
log2("......setting up StepRequest:");
458
log2(" thread: " + thread + "; property: " + property);
459
460
StepRequest
461
str = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
462
str.putProperty("number", property);
463
str.addCountFilter(1);
464
str.setSuspendPolicy(suspendPolicy);
465
466
log2(" StepRequest has been set up");
467
return str;
468
} catch ( Exception e ) {
469
log3("ERROR: ATTENTION: Exception within settingStepRequest() : " + e);
470
log3(" StepRequest HAS NOT BEEN SET UP");
471
throw new JDITestRuntimeException("** FAILURE to set up StepRequest **");
472
}
473
}
474
/**
475
* Inform debuggee which thread test the debugger has completed.
476
* Used for synchronization, so the debuggee does not move too quickly.
477
* @param testCase index of just completed test
478
*/
479
void informDebuggeeTestCase(int testCase) {
480
try {
481
((ClassType)debuggeeClass)
482
.setValue(debuggeeClass.fieldByName("testCase"),
483
vm.mirrorOf(testCase));
484
} catch (InvalidTypeException ite) {
485
throw new Failure("** FAILURE setting testCase **");
486
} catch (ClassNotLoadedException cnle) {
487
throw new Failure("** FAILURE notifying debuggee **");
488
} catch (VMDisconnectedException e) {
489
throw new Failure("** FAILURE debuggee connection **");
490
}
491
}
492
}
493
494