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/suspendpolicy008.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 ThreadStartEvent 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 one to three new ThreadStartRequests, <BR>
70
* resumes the debuggee, and waits for the ThreadStartEvents. <BR>
71
* - The debuggee starts new thread to be resulting in the events. <BR>
72
* - Upon getting new ThreadStartEvent, <BR>
73
* the debugger performs the check corresponding to the EventSet. <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 suspendpolicy008 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 suspendpolicy008().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.suspendpolicy008a";
106
107
private String testedClassName =
108
"nsk.jdi.EventSet.suspendPolicy.TestClass";
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
for (int i = 0; ; i++) {
294
295
breakpointForCommunication();
296
297
int instruction = ((IntegerValue)
298
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
299
if (instruction == 0) {
300
vm.resume();
301
break;
302
}
303
304
305
log1(":::::: case: # " + i);
306
307
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
308
309
switch (i) {
310
311
case 0:
312
eventRequest1 = settingThreadStartRequest (
313
SUSPEND_NONE, "ThreadStartRequest1");
314
eventRequest1.enable();
315
break;
316
317
case 1:
318
eventRequest2 = settingThreadStartRequest (
319
SUSPEND_THREAD, "ThreadStartRequest2");
320
eventRequest2.enable();
321
break;
322
323
case 2:
324
eventRequest3 = settingThreadStartRequest (
325
SUSPEND_ALL, "ThreadStartRequest3");
326
eventRequest3.enable();
327
break;
328
329
case 3:
330
eventRequest1 = settingThreadStartRequest (
331
SUSPEND_NONE, "ThreadStartRequest1");
332
eventRequest1.enable();
333
eventRequest2 = settingThreadStartRequest (
334
SUSPEND_THREAD, "ThreadStartRequest2");
335
eventRequest2.enable();
336
break;
337
338
case 4:
339
eventRequest1 = settingThreadStartRequest (
340
SUSPEND_NONE, "ThreadStartRequest1");
341
eventRequest1.enable();
342
eventRequest3 = settingThreadStartRequest (
343
SUSPEND_ALL, "ThreadStartRequest3");
344
eventRequest3.enable();
345
break;
346
347
case 5:
348
eventRequest2 = settingThreadStartRequest (
349
SUSPEND_THREAD, "ThreadStartRequest2");
350
eventRequest2.enable();
351
eventRequest3 = settingThreadStartRequest (
352
SUSPEND_ALL, "ThreadStartRequest3");
353
eventRequest3.enable();
354
break;
355
356
case 6:
357
eventRequest1 = settingThreadStartRequest (
358
SUSPEND_NONE, "ThreadStartRequest1");
359
eventRequest1.enable();
360
eventRequest2 = settingThreadStartRequest (
361
SUSPEND_THREAD, "ThreadStartRequest2");
362
eventRequest2.enable();
363
eventRequest3 = settingThreadStartRequest (
364
SUSPEND_ALL, "ThreadStartRequest3");
365
eventRequest3.enable();
366
break;
367
368
369
default:
370
throw new JDITestRuntimeException("** default case 2 **");
371
}
372
373
mainThread.resume();
374
getEventSet();
375
376
if ( !(eventIterator.nextEvent() instanceof ThreadStartEvent)) {
377
log3("ERROR: new event is not ThreadStartEvent");
378
testExitCode = FAILED;
379
} else {
380
log2("......got : instanceof ThreadStartEvent");
381
policy = eventSet.suspendPolicy();
382
if (policy != policyExpected[i]) {
383
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
384
log3(" eventSet.suspendPolicy() == " + policy);
385
log3(" policyExpected == " + policyExpected[i]);
386
testExitCode = FAILED;
387
}
388
}
389
390
switch (i) {
391
case 0: eventRequest1.disable(); break;
392
case 1: eventRequest2.disable(); break;
393
case 2: eventRequest3.disable(); break;
394
case 3: eventRequest1.disable(); eventRequest2.disable(); break;
395
case 4: eventRequest1.disable(); eventRequest3.disable(); break;
396
case 5: eventRequest2.disable(); eventRequest3.disable(); break;
397
case 6: eventRequest1.disable(); eventRequest2.disable();
398
eventRequest3.disable(); break;
399
}
400
401
switch (policy) {
402
case SUSPEND_NONE : break;
403
case SUSPEND_THREAD : vm.resume(); break;
404
case SUSPEND_ALL : vm.resume(); break;
405
default: throw new JDITestRuntimeException("** default case 3 **");
406
}
407
408
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
409
}
410
log1(" TESTING ENDS");
411
return;
412
}
413
414
// ============================== test's additional methods
415
416
private ThreadStartRequest settingThreadStartRequest(int suspendPolicy,
417
String property)
418
throws JDITestRuntimeException {
419
try {
420
ThreadStartRequest tsr = eventRManager.createThreadStartRequest();
421
// tsr.addThreadFilter(mainThread);
422
tsr.addCountFilter(1);
423
tsr.setSuspendPolicy(suspendPolicy);
424
tsr.putProperty("number", property);
425
return tsr;
426
} catch ( Exception e ) {
427
log3("ERROR: ATTENTION: Exception within settingThreadStartRequest() : " + e);
428
log3(" ThreadStartRequest HAS NOT BEEN SET UP");
429
throw new JDITestRuntimeException("** FAILURE to set up ThreadStartRequest **");
430
}
431
}
432
433
}
434
435