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/resume003.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 ModificationWatchpointEvent 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 ModificationWatchpointRequest, resumes <BR>
74
* the debuggee, and waits for the ModificationWatchpointEvent. <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 resume003 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 resume003().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.resume003a";
111
112
private String testedClassName =
113
"nsk.jdi.EventSet.resume.resume003aTestClass";
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
if ( !vm.canWatchFieldModification() ) {
236
log2("......vm.canWatchFieldModification == false :: test cancelled");
237
vm.exit(PASS_BASE);
238
return;
239
}
240
241
242
eventRManager = vm.eventRequestManager();
243
244
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
245
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
246
cpRequest.addClassFilter(debuggeeName);
247
248
cpRequest.enable();
249
vm.resume();
250
getEventSet();
251
cpRequest.disable();
252
253
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
254
debuggeeClass = event.referenceType();
255
256
if (!debuggeeClass.name().equals(debuggeeName))
257
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
258
259
log2(" received: ClassPrepareEvent for debuggeeClass");
260
261
String bPointMethod = "methodForCommunication";
262
String lineForComm = "lineForComm";
263
BreakpointRequest bpRequest;
264
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
265
bpRequest = settingBreakpoint(mainThread,
266
debuggeeClass,
267
bPointMethod, lineForComm, "zero");
268
bpRequest.enable();
269
270
vm.resume();
271
272
//------------------------------------------------------ testing section
273
274
log1(" TESTING BEGINS");
275
276
EventRequest eventRequest1 = null;
277
EventRequest eventRequest2 = null;
278
EventRequest eventRequest3 = null;
279
280
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
281
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
282
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
283
284
String fieldName = "var1";
285
286
ReferenceType testClassReference = null;
287
288
289
for (int i = 0; ; i++) {
290
291
breakpointForCommunication();
292
293
int instruction = ((IntegerValue)
294
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
295
296
if (instruction == 0) {
297
vm.resume();
298
break;
299
}
300
301
log1(":::::: case: # " + i);
302
303
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
304
305
switch (i) {
306
307
case 0:
308
testClassReference =
309
(ReferenceType) vm.classesByName(testedClassName).get(0);
310
311
eventRequest1 = settingModificationWatchpointRequest (mainThread,
312
testClassReference, fieldName,
313
SUSPEND_NONE, "ModificationWatchpointRequest1");
314
eventRequest1.enable();
315
break;
316
317
case 1:
318
eventRequest2 = settingModificationWatchpointRequest (mainThread,
319
testClassReference, fieldName,
320
SUSPEND_THREAD, "ModificationWatchpointRequest2");
321
eventRequest2.enable();
322
break;
323
324
case 2:
325
eventRequest3 = settingModificationWatchpointRequest (mainThread,
326
testClassReference, fieldName,
327
SUSPEND_ALL, "ModificationWatchpointRequest3");
328
eventRequest3.enable();
329
break;
330
331
332
default:
333
throw new JDITestRuntimeException("** default case 2 **");
334
}
335
336
log2("......waiting for new ModificationWatchpointEvent : " + i);
337
mainThread.resume();
338
getEventSet();
339
340
Event newEvent = eventIterator.nextEvent();
341
if ( !(newEvent instanceof ModificationWatchpointEvent)) {
342
log3("ERROR: new event is not ModificationWatchpointEvent");
343
testExitCode = FAILED;
344
} else {
345
346
String property = (String) newEvent.request().getProperty("number");
347
log2(" got new ModificationWatchpointEvent with propety 'number' == " + property);
348
349
log2("......checking up on EventSet.resume()");
350
log2("......--> vm.suspend();");
351
vm.suspend();
352
353
log2(" getting : Map<String, Integer> suspendsCounts1");
354
355
Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();
356
for (ThreadReference threadReference : vm.allThreads()) {
357
suspendsCounts1.put(threadReference.name(), threadReference.suspendCount());
358
}
359
360
log2(" eventSet.resume;");
361
eventSet.resume();
362
363
log2(" getting : Map<String, Integer> suspendsCounts2");
364
Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();
365
for (ThreadReference threadReference : vm.allThreads()) {
366
suspendsCounts2.put(threadReference.name(), threadReference.suspendCount());
367
}
368
369
log2(suspendsCounts1.toString());
370
log2(suspendsCounts2.toString());
371
372
log2(" getting : int policy = eventSet.suspendPolicy();");
373
int policy = eventSet.suspendPolicy();
374
375
switch (policy) {
376
377
case SUSPEND_NONE :
378
log2(" case SUSPEND_NONE");
379
for (String threadName : suspendsCounts1.keySet()) {
380
log2(" checking " + threadName);
381
if (!suspendsCounts2.containsKey(threadName)) {
382
log3("ERROR: couldn't get ThreadReference for " + threadName);
383
testExitCode = FAILED;
384
break;
385
}
386
int count1 = suspendsCounts1.get(threadName);
387
int count2 = suspendsCounts2.get(threadName);
388
if (count1 != count2) {
389
log3("ERROR: suspendCounts don't match for : " + threadName);
390
log3("before resuming : " + count1);
391
log3("after resuming : " + count2);
392
testExitCode = FAILED;
393
break;
394
}
395
}
396
eventRequest1.disable();
397
break;
398
399
case SUSPEND_THREAD :
400
log2(" case SUSPEND_THREAD");
401
for (String threadName : suspendsCounts1.keySet()) {
402
log2("checking " + threadName);
403
if (!suspendsCounts2.containsKey(threadName)) {
404
log3("ERROR: couldn't get ThreadReference for " + threadName);
405
testExitCode = FAILED;
406
break;
407
}
408
int count1 = suspendsCounts1.get(threadName);
409
int count2 = suspendsCounts2.get(threadName);
410
String eventThreadName = ((ModificationWatchpointEvent)newEvent).thread().name();
411
int expectedValue = count2 + (eventThreadName.equals(threadName) ? 1 : 0);
412
if (count1 != expectedValue) {
413
log3("ERROR: suspendCounts don't match for : " + threadName);
414
log3("before resuming : " + count1);
415
log3("after resuming : " + count2);
416
testExitCode = FAILED;
417
break;
418
}
419
}
420
eventRequest2.disable();
421
break;
422
423
case SUSPEND_ALL :
424
425
log2(" case SUSPEND_ALL");
426
for (String threadName : suspendsCounts1.keySet()) {
427
log2("checking " + threadName);
428
if (!event.request().equals(eventRequest3))
429
break;
430
if (!suspendsCounts2.containsKey(threadName)) {
431
log3("ERROR: couldn't get ThreadReference for " + threadName);
432
testExitCode = FAILED;
433
break;
434
}
435
int count1 = suspendsCounts1.get(threadName);
436
int count2 = suspendsCounts2.get(threadName);
437
if (count1 != count2 + 1) {
438
log3("ERROR: suspendCounts don't match for : " + threadName);
439
log3("before resuming : " + count1);
440
log3("after resuming : " + count2);
441
testExitCode = FAILED;
442
break;
443
}
444
}
445
eventRequest3.disable();
446
break;
447
448
default: throw new JDITestRuntimeException("** default case 1 **");
449
}
450
}
451
452
log2("......--> vm.resume()");
453
vm.resume();
454
informDebuggeeTestCase(i);
455
456
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
457
}
458
log1(" TESTING ENDS");
459
return;
460
}
461
462
// ============================== test's additional methods
463
464
private ModificationWatchpointRequest settingModificationWatchpointRequest (
465
ThreadReference thread,
466
ReferenceType testedClass,
467
String fieldName,
468
int suspendPolicy,
469
String property )
470
throws JDITestRuntimeException {
471
try {
472
log2("......setting up ModificationWatchpointRequest:");
473
log2(" thread: " + thread + "; class: " + testedClass + "; fieldName: " + fieldName);
474
Field field = testedClass.fieldByName(fieldName);
475
476
ModificationWatchpointRequest
477
awr = eventRManager.createModificationWatchpointRequest(field);
478
awr.putProperty("number", property);
479
awr.addThreadFilter(thread);
480
awr.setSuspendPolicy(suspendPolicy);
481
482
log2(" ModificationWatchpointRequest has been set up");
483
return awr;
484
} catch ( Exception e ) {
485
log3("ERROR: ATTENTION: Exception within settingModificationWatchpointRequest() : " + e);
486
log3(" ModificationWatchpointRequest HAS NOT BEEN SET UP");
487
throw new JDITestRuntimeException("** FAILURE to set up ModificationWatchpointRequest **");
488
}
489
}
490
/**
491
* Inform debuggee which thread test the debugger has completed.
492
* Used for synchronization, so the debuggee does not move too quickly.
493
* @param testCase index of just completed test
494
*/
495
void informDebuggeeTestCase(int testCase) {
496
try {
497
((ClassType)debuggeeClass)
498
.setValue(debuggeeClass.fieldByName("testCase"),
499
vm.mirrorOf(testCase));
500
} catch (InvalidTypeException ite) {
501
throw new Failure("** FAILURE setting testCase **");
502
} catch (ClassNotLoadedException cnle) {
503
throw new Failure("** FAILURE notifying debuggee **");
504
} catch (VMDisconnectedException e) {
505
throw new Failure("** FAILURE debuggee connection **");
506
}
507
}
508
}
509
510