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/suspendpolicy005.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 an ExceptionEvent set, <BR>
46
* the method returns a value 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 ExceptionRequest, <BR>
70
* resumes the debuggee, and waits for the ExceptionEvent. <BR>
71
* - The debuggee invokes the special method in which <BR>
72
* NullPointerException is thrown 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 suspendpolicy005 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 suspendpolicy005().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.suspendpolicy005a";
107
108
private String testedClassName =
109
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy005aTestClass";
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
eventRManager = vm.eventRequestManager();
241
242
log2("......getting ClassPrepareEvent for debuggee's class");
243
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
244
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
245
cpRequest.addClassFilter(debuggeeName);
246
cpRequest.enable();
247
vm.resume();
248
getEventSet();
249
cpRequest.disable();
250
251
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
252
debuggeeClass = event.referenceType();
253
254
if (!debuggeeClass.name().equals(debuggeeName))
255
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
256
log2(" received: ClassPrepareEvent for debuggeeClass");
257
258
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
259
260
String bPointMethod = "methodForCommunication";
261
String lineForComm = "lineForComm";
262
BreakpointRequest bpRequest;
263
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
264
bpRequest = settingBreakpoint(mainThread,
265
debuggeeClass,
266
bPointMethod, lineForComm, "zero");
267
bpRequest.enable();
268
269
vm.resume();
270
271
//------------------------------------------------------ testing section
272
273
log1(" TESTING BEGINS");
274
275
EventRequest eventRequest1 = null;
276
EventRequest eventRequest2 = null;
277
EventRequest eventRequest3 = null;
278
279
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
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
int policyExpected[] = { SUSPEND_NONE,
285
SUSPEND_THREAD,
286
SUSPEND_ALL,
287
SUSPEND_THREAD,
288
SUSPEND_ALL,
289
SUSPEND_ALL,
290
SUSPEND_ALL };
291
int policy = 0;
292
293
294
ReferenceType testClassReference = null;
295
296
String methodName = "method";
297
String bpLineName = "breakpointLine";
298
299
300
for (int i = 0; ; i++) {
301
302
303
breakpointForCommunication();
304
305
int instruction = ((IntegerValue)
306
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
307
if (instruction == 0) {
308
vm.resume();
309
break;
310
}
311
312
313
log1(":::::: case: # " + i);
314
315
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
316
317
switch (i) {
318
319
case 0:
320
testClassReference =
321
(ReferenceType) vm.classesByName(testedClassName).get(0);
322
323
eventRequest1 = settingExceptionRequest (mainThread,
324
debuggeeClass, //testClassReference,
325
SUSPEND_NONE, "ExceptionRequest1");
326
eventRequest1.enable();
327
break;
328
329
case 1:
330
eventRequest2 = settingExceptionRequest (mainThread,
331
debuggeeClass, //testClassReference,
332
SUSPEND_THREAD, "ExceptionRequest2");
333
eventRequest2.enable();
334
break;
335
336
case 2:
337
eventRequest3 = settingExceptionRequest (mainThread,
338
debuggeeClass, //testClassReference,
339
SUSPEND_ALL, "ExceptionRequest3");
340
eventRequest3.enable();
341
break;
342
343
case 3:
344
eventRequest1 = settingExceptionRequest (mainThread,
345
debuggeeClass, // testClassReference,
346
SUSPEND_NONE, "ExceptionRequest4");
347
eventRequest1.enable();
348
eventRequest2 = settingExceptionRequest (mainThread,
349
debuggeeClass, //testClassReference,
350
SUSPEND_THREAD, "ExceptionRequest5");
351
eventRequest2.enable();
352
break;
353
354
case 4:
355
eventRequest1 = settingExceptionRequest (mainThread,
356
debuggeeClass, //testClassReference,
357
SUSPEND_NONE, "ExceptionRequest6");
358
eventRequest1.enable();
359
eventRequest3 = settingExceptionRequest (mainThread,
360
debuggeeClass, //testClassReference,
361
SUSPEND_ALL, "ExceptionRequest7");
362
eventRequest3.enable();
363
break;
364
365
case 5:
366
eventRequest2 = settingExceptionRequest (mainThread,
367
debuggeeClass, //testClassReference,
368
SUSPEND_THREAD, "ExceptionRequest8");
369
eventRequest2.enable();
370
eventRequest3 = settingExceptionRequest (mainThread,
371
debuggeeClass, //testClassReference,
372
SUSPEND_ALL, "ExceptionRequest9");
373
eventRequest3.enable();
374
break;
375
376
case 6:
377
eventRequest1 = settingExceptionRequest (mainThread,
378
debuggeeClass, //testClassReference,
379
SUSPEND_NONE, "ExceptionRequest10");
380
eventRequest1.enable();
381
eventRequest2 = settingExceptionRequest (mainThread,
382
debuggeeClass, //testClassReference,
383
SUSPEND_THREAD, "ExceptionRequest11");
384
eventRequest2.enable();
385
eventRequest3 = settingExceptionRequest (mainThread,
386
debuggeeClass, //testClassReference,
387
SUSPEND_ALL, "ExceptionRequest12");
388
eventRequest3.enable();
389
break;
390
391
392
default:
393
throw new JDITestRuntimeException("** default case 2 **");
394
}
395
396
log2("......waiting for new ExceptionEvent : " + i);
397
mainThread.resume();
398
getEventSet();
399
400
Event newEvent = eventIterator.nextEvent();
401
log2(" got new Event with propety 'number' == " + newEvent.request().getProperty("number"));
402
if ( !( newEvent instanceof ExceptionEvent)) {
403
log3("ERROR: new event is not ExceptionEvent");
404
testExitCode = FAILED;
405
} else {
406
log2(" Event is instanceof ExceptionEvent");
407
policy = eventSet.suspendPolicy();
408
if (policy != policyExpected[i]) {
409
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
410
log3(" eventSet.suspendPolicy() == " + policy);
411
log3(" policyExpected == " + policyExpected[i]);
412
testExitCode = FAILED;
413
}
414
}
415
416
switch (i) {
417
case 0: eventRequest1.disable(); break;
418
case 1: eventRequest2.disable(); break;
419
case 2: eventRequest3.disable(); break;
420
case 3: eventRequest1.disable(); eventRequest2.disable(); break;
421
case 4: eventRequest1.disable(); eventRequest3.disable(); break;
422
case 5: eventRequest2.disable(); eventRequest3.disable(); break;
423
case 6: eventRequest1.disable(); eventRequest2.disable();
424
eventRequest3.disable(); break;
425
}
426
427
switch (policy) {
428
case SUSPEND_NONE : break;
429
case SUSPEND_THREAD : mainThread.resume(); break;
430
case SUSPEND_ALL : vm.resume(); break;
431
default: throw new JDITestRuntimeException("** default case 3 **");
432
}
433
434
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
435
}
436
log1(" TESTING ENDS");
437
return;
438
}
439
440
// ============================== test's additional methods
441
442
private ExceptionRequest settingExceptionRequest ( ThreadReference thread,
443
ReferenceType testedClass,
444
int suspendPolicy,
445
String property )
446
throws JDITestRuntimeException {
447
try {
448
log2("......setting up ExceptionRequest:");
449
log2(" thread: " + thread + "; class: " + testedClass + "; property: " + property);
450
451
ExceptionRequest
452
excr = eventRManager.createExceptionRequest(null, true, true);
453
excr.putProperty("number", property);
454
excr.addThreadFilter(thread);
455
excr.addClassFilter(testedClass);
456
excr.setSuspendPolicy(suspendPolicy);
457
458
log2(" ExceptionRequest has been set up");
459
return excr;
460
} catch ( Exception e ) {
461
log3("ERROR: ATTENTION: Exception within settingExceptionRequest() : " + e);
462
log3(" ExceptionRequest HAS NOT BEEN SET UP");
463
throw new JDITestRuntimeException("** FAILURE to set up ExceptionRequest **");
464
}
465
}
466
467
}
468
469