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