Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/suspendPolicy/suspendpolicy003.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.suspendPolicy;
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.suspendPolicy()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks that for a ModificationWatchpointEvent set, <BR>
46
* the method returns values corresponding to one <BR>
47
* which suspends the most threads. <BR>
48
* The cases to check include event sets containing <BR>
49
* one to three threads with all possible combinations: <BR>
50
* NONE, THREAD, ALL, NONE+THREAD, NONE+ALL, <BR>
51
* THREAD+ALL, NONE+THREAD+ALL <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 above, <BR>
68
* the debugger and the debuggee perform the following loop. <BR>
69
* - The debugger sets up a ModificationWatchpointRequest, resumes <BR>
70
* the debuggee, and waits for the ModificationWatchpointEvent. <BR>
71
* - The debuggee invokes the special method which makes modification <BR>
72
* of a predefined variable to be resulting in the event. <BR>
73
* - Upon getting new event, the debugger <BR>
74
* performs the check corresponding to the event. <BR>
75
* <BR>
76
* Note. To inform each other of needed actions, the debugger and <BR>
77
* and the debuggee use debuggee's variable "instruction". <BR>
78
* In third phase, at the end, <BR>
79
* the debuggee changes the value of the "instruction" <BR>
80
* to inform the debugger of checks finished, and both end. <BR>
81
* <BR>
82
*/
83
84
public class suspendpolicy003 extends JDIBase {
85
86
public static void main (String argv[]) {
87
88
int result = run(argv, System.out);
89
90
System.exit(result + PASS_BASE);
91
}
92
93
public static int run (String argv[], PrintStream out) {
94
95
int exitCode = new suspendpolicy003().runThis(argv, out);
96
97
if (exitCode != PASSED) {
98
System.out.println("TEST FAILED");
99
}
100
return testExitCode;
101
}
102
103
// ************************************************ test parameters
104
105
private String debuggeeName =
106
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy003a";
107
108
private String testedClassName =
109
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy003aTestClass";
110
111
//====================================================== test program
112
113
private int runThis (String argv[], PrintStream out) {
114
115
argsHandler = new ArgumentHandler(argv);
116
logHandler = new Log(out, argsHandler);
117
Binder binder = new Binder(argsHandler, logHandler);
118
119
waitTime = argsHandler.getWaitTime() * 60000;
120
121
try {
122
log2("launching a debuggee :");
123
log2(" " + debuggeeName);
124
if (argsHandler.verbose()) {
125
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
126
} else {
127
debuggee = binder.bindToDebugee(debuggeeName);
128
}
129
if (debuggee == null) {
130
log3("ERROR: no debuggee launched");
131
return FAILED;
132
}
133
log2("debuggee launched");
134
} catch ( Exception e ) {
135
log3("ERROR: Exception : " + e);
136
log2(" test cancelled");
137
return FAILED;
138
}
139
140
debuggee.redirectOutput(logHandler);
141
142
vm = debuggee.VM();
143
144
eventQueue = vm.eventQueue();
145
if (eventQueue == null) {
146
log3("ERROR: eventQueue == null : TEST ABORTED");
147
vm.exit(PASS_BASE);
148
return FAILED;
149
}
150
151
log2("invocation of the method runTest()");
152
switch (runTest()) {
153
154
case 0 : log2("test phase has finished normally");
155
log2(" waiting for the debuggee to finish ...");
156
debuggee.waitFor();
157
158
log2("......getting the debuggee's exit status");
159
int status = debuggee.getStatus();
160
if (status != PASS_BASE) {
161
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
162
status + " != PASS_BASE");
163
testExitCode = FAILED;
164
} else {
165
log2("......debuggee returned expected exit status: " +
166
status + " == PASS_BASE");
167
}
168
break;
169
170
default : log3("ERROR: runTest() returned unexpected value");
171
172
case 1 : log3("test phase has not finished normally: debuggee is still alive");
173
log2("......forcing: vm.exit();");
174
testExitCode = FAILED;
175
try {
176
vm.exit(PASS_BASE);
177
} catch ( Exception e ) {
178
log3("ERROR: Exception : e");
179
}
180
break;
181
182
case 2 : log3("test cancelled due to VMDisconnectedException");
183
log2("......trying: vm.process().destroy();");
184
testExitCode = FAILED;
185
try {
186
Process vmProcess = vm.process();
187
if (vmProcess != null) {
188
vmProcess.destroy();
189
}
190
} catch ( Exception e ) {
191
log3("ERROR: Exception : e");
192
}
193
break;
194
}
195
196
return testExitCode;
197
}
198
199
200
/*
201
* Return value: 0 - normal end of the test
202
* 1 - ubnormal end of the test
203
* 2 - VMDisconnectedException while test phase
204
*/
205
206
private int runTest() {
207
208
try {
209
testRun();
210
211
log2("waiting for VMDeathEvent");
212
getEventSet();
213
if ( !(eventIterator.nextEvent() instanceof VMDeathEvent) ) {
214
log3("ERROR: last event is not the VMDeathEvent");
215
return 1;
216
}
217
218
log2("waiting for VMDisconnectEvent");
219
getEventSet();
220
if ( !(eventIterator.nextEvent() instanceof VMDisconnectEvent) ) {
221
log3("ERROR: last event is not the VMDisconnectEvent");
222
return 1;
223
}
224
225
return 0;
226
227
} catch ( VMDisconnectedException e ) {
228
log3("ERROR: VMDisconnectedException : " + e);
229
return 2;
230
} catch ( Exception e ) {
231
log3("ERROR: Exception : " + e);
232
return 1;
233
}
234
235
}
236
237
private void testRun()
238
throws JDITestRuntimeException, Exception {
239
240
if ( !vm.canWatchFieldModification() ) {
241
log2("......vm.canWatchFieldModification == false :: test cancelled");
242
vm.exit(PASS_BASE);
243
return;
244
}
245
246
eventRManager = vm.eventRequestManager();
247
248
log2("......getting ClassPrepareEvent for debuggee's class");
249
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
250
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
251
cpRequest.addClassFilter(debuggeeName);
252
cpRequest.enable();
253
vm.resume();
254
getEventSet();
255
cpRequest.disable();
256
257
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
258
debuggeeClass = event.referenceType();
259
260
if (!debuggeeClass.name().equals(debuggeeName))
261
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
262
log2(" received: ClassPrepareEvent for debuggeeClass");
263
264
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
265
266
String bPointMethod = "methodForCommunication";
267
String lineForComm = "lineForComm";
268
BreakpointRequest bpRequest;
269
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
270
bpRequest = settingBreakpoint(mainThread,
271
debuggeeClass,
272
bPointMethod, lineForComm, "zero");
273
bpRequest.enable();
274
275
vm.resume();
276
277
//------------------------------------------------------ testing section
278
279
log1(" TESTING BEGINS");
280
281
EventRequest eventRequest1 = null;
282
EventRequest eventRequest2 = null;
283
EventRequest eventRequest3 = null;
284
285
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
286
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
287
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
288
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
289
290
int policyExpected[] = { SUSPEND_NONE,
291
SUSPEND_THREAD,
292
SUSPEND_ALL,
293
SUSPEND_THREAD,
294
SUSPEND_ALL,
295
SUSPEND_ALL,
296
SUSPEND_ALL };
297
int policy = 0;
298
299
300
ReferenceType testClassReference = null;
301
302
String fieldName = "var2";
303
304
305
for (int i = 0; ; i++) {
306
307
308
breakpointForCommunication();
309
310
int instruction = ((IntegerValue)
311
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
312
if (instruction == 0) {
313
vm.resume();
314
break;
315
}
316
317
318
log1(":::::: case: # " + i);
319
320
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
321
322
switch (i) {
323
324
case 0:
325
testClassReference =
326
(ReferenceType) vm.classesByName(testedClassName).get(0);
327
328
eventRequest1 = settingModificationWatchpointRequest (mainThread,
329
testClassReference, fieldName,
330
SUSPEND_NONE, "ModificationWatchpointRequest1");
331
eventRequest1.enable();
332
break;
333
334
case 1:
335
eventRequest2 = settingModificationWatchpointRequest (mainThread,
336
testClassReference, fieldName,
337
SUSPEND_THREAD, "ModificationWatchpointRequest2");
338
eventRequest2.enable();
339
break;
340
341
case 2:
342
eventRequest3 = settingModificationWatchpointRequest (mainThread,
343
testClassReference, fieldName,
344
SUSPEND_ALL, "ModificationWatchpointRequest3");
345
eventRequest3.enable();
346
break;
347
348
case 3:
349
eventRequest1 = settingModificationWatchpointRequest (mainThread,
350
testClassReference, fieldName,
351
SUSPEND_NONE, "ModificationWatchpointRequest4");
352
eventRequest1.enable();
353
eventRequest2 = settingModificationWatchpointRequest (mainThread,
354
testClassReference, fieldName,
355
SUSPEND_THREAD, "ModificationWatchpointRequest5");
356
eventRequest2.enable();
357
break;
358
359
case 4:
360
eventRequest1 = settingModificationWatchpointRequest (mainThread,
361
testClassReference, fieldName,
362
SUSPEND_NONE, "ModificationWatchpointRequest6");
363
eventRequest1.enable();
364
eventRequest3 = settingModificationWatchpointRequest (mainThread,
365
testClassReference, fieldName,
366
SUSPEND_ALL, "ModificationWatchpointRequest7");
367
eventRequest3.enable();
368
break;
369
370
case 5:
371
eventRequest2 = settingModificationWatchpointRequest (mainThread,
372
testClassReference, fieldName,
373
SUSPEND_THREAD, "ModificationWatchpointRequest8");
374
eventRequest2.enable();
375
eventRequest3 = settingModificationWatchpointRequest (mainThread,
376
testClassReference, fieldName,
377
SUSPEND_ALL, "ModificationWatchpointRequest9");
378
eventRequest3.enable();
379
break;
380
381
case 6:
382
eventRequest1 = settingModificationWatchpointRequest (mainThread,
383
testClassReference, fieldName,
384
SUSPEND_NONE, "ModificationWatchpointRequest10");
385
eventRequest1.enable();
386
eventRequest2 = settingModificationWatchpointRequest (mainThread,
387
testClassReference, fieldName,
388
SUSPEND_THREAD, "ModificationWatchpointRequest11");
389
eventRequest2.enable();
390
eventRequest3 = settingModificationWatchpointRequest (mainThread,
391
testClassReference, fieldName,
392
SUSPEND_ALL, "ModificationWatchpointRequest12");
393
eventRequest3.enable();
394
break;
395
396
397
default:
398
throw new JDITestRuntimeException("** default case 2 **");
399
}
400
401
log2("......waiting for new AccessWatchpointEvent : " + i);
402
mainThread.resume();
403
getEventSet();
404
405
Event newEvent = eventIterator.nextEvent();
406
log2(" got new Event with propety 'number' == " + newEvent.request().getProperty("number"));
407
if ( !( newEvent instanceof ModificationWatchpointEvent)) {
408
log3("ERROR: new event is not ModificationWatchpointEvent");
409
testExitCode = FAILED;
410
} else {
411
log2(" Event is instanceof ModificationWatchpointEvent");
412
policy = eventSet.suspendPolicy();
413
if (policy != policyExpected[i]) {
414
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
415
log3(" eventSet.suspendPolicy() == " + policy);
416
log3(" policyExpected == " + policyExpected[i]);
417
testExitCode = FAILED;
418
}
419
}
420
421
switch (i) {
422
case 0: eventRequest1.disable(); break;
423
case 1: eventRequest2.disable(); break;
424
case 2: eventRequest3.disable(); break;
425
case 3: eventRequest1.disable(); eventRequest2.disable(); break;
426
case 4: eventRequest1.disable(); eventRequest3.disable(); break;
427
case 5: eventRequest2.disable(); eventRequest3.disable(); break;
428
case 6: eventRequest1.disable(); eventRequest2.disable();
429
eventRequest3.disable(); break;
430
}
431
432
switch (policy) {
433
case SUSPEND_NONE : break;
434
case SUSPEND_THREAD : mainThread.resume(); break;
435
case SUSPEND_ALL : vm.resume(); break;
436
default: throw new JDITestRuntimeException("** default case 3 **");
437
}
438
439
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440
}
441
log1(" TESTING ENDS");
442
return;
443
}
444
445
446
// ============================== test's additional methods
447
448
private ModificationWatchpointRequest settingModificationWatchpointRequest (
449
ThreadReference thread,
450
ReferenceType testedClass,
451
String fieldName,
452
int suspendPolicy,
453
String property )
454
throws JDITestRuntimeException {
455
try {
456
log2("......setting up ModificationWatchpointRequest:");
457
log2(" thread: " + thread + "; class: " + testedClass + "; fieldName: " + fieldName);
458
Field field = testedClass.fieldByName(fieldName);
459
460
ModificationWatchpointRequest
461
awr = eventRManager.createModificationWatchpointRequest(field);
462
awr.putProperty("number", property);
463
awr.addThreadFilter(thread);
464
awr.setSuspendPolicy(suspendPolicy);
465
466
log2(" ModificationWatchpointRequest has been set up");
467
return awr;
468
} catch ( Exception e ) {
469
log3("ERROR: ATTENTION: Exception within settingModificationWatchpointRequest() : " + e);
470
log3(" ModificationWatchpointRequest HAS NOT BEEN SET UP");
471
throw new JDITestRuntimeException("** FAILURE to set up ModificationWatchpointRequest **");
472
}
473
}
474
475
}
476
477