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