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