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/suspendpolicy010.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 StepEvent 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 thread with all possible combinations: <BR>
50
* NONE, THREAD, ALL <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check the above, <BR>
67
* the debugger and the debuggee perform the following loop. <BR>
68
* - The debugger sets up a StepRequest, resumes <BR>
69
* the debuggee, and waits for the StepEvent. <BR>
70
* - The debuggee invokes the special method to be resulting in the event.<BR>
71
* - Upon getting new event, the debugger <BR>
72
* performs the check corresponding to the event. <BR>
73
* <BR>
74
* Note. To inform each other of needed actions, the debugger and <BR>
75
* and the debuggee use debuggee's variable "instruction". <BR>
76
* In third phase, at the end, <BR>
77
* the debuggee changes the value of the "instruction" <BR>
78
* to inform the debugger of checks finished, and both end. <BR>
79
* <BR>
80
*/
81
82
public class suspendpolicy010 extends JDIBase {
83
84
public static void main (String argv[]) {
85
86
int result = run(argv, System.out);
87
88
System.exit(result + PASS_BASE);
89
}
90
91
public static int run (String argv[], PrintStream out) {
92
93
int exitCode = new suspendpolicy010().runThis(argv, out);
94
95
if (exitCode != PASSED) {
96
System.out.println("TEST FAILED");
97
}
98
return testExitCode;
99
}
100
101
// ************************************************ test parameters
102
103
private String debuggeeName =
104
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy010a";
105
106
private String testedClassName =
107
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy010aTestClass";
108
109
//====================================================== test program
110
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
vm.resume();
268
269
//------------------------------------------------------ testing section
270
271
log1(" TESTING BEGINS");
272
273
EventRequest eventRequest1 = null;
274
EventRequest eventRequest2 = null;
275
EventRequest eventRequest3 = null;
276
277
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
278
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
279
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
280
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
281
282
int policyExpected[] = { SUSPEND_NONE,
283
SUSPEND_THREAD,
284
SUSPEND_ALL,
285
SUSPEND_THREAD,
286
SUSPEND_ALL,
287
SUSPEND_ALL,
288
SUSPEND_ALL };
289
int policy = 0;
290
291
292
for (int i = 0; ; i++) {
293
294
breakpointForCommunication();
295
296
int instruction = ((IntegerValue)
297
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
298
if (instruction == 0) {
299
vm.resume();
300
break;
301
}
302
303
log1(":::::: case: # " + i);
304
305
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
306
307
switch (i) {
308
309
case 0:
310
eventRequest1 = settingStepRequest (mainThread,
311
SUSPEND_NONE, "StepRequest1");
312
eventRequest1.enable();
313
break;
314
315
case 1:
316
eventRequest2 = settingStepRequest (mainThread,
317
SUSPEND_THREAD, "StepRequest2");
318
eventRequest2.enable();
319
break;
320
321
case 2:
322
eventRequest3 = settingStepRequest (mainThread,
323
324
SUSPEND_ALL, "StepRequest3");
325
eventRequest3.enable();
326
break;
327
328
329
default:
330
throw new JDITestRuntimeException("** default case 2 **");
331
}
332
333
mainThread.resume();
334
getEventSet();
335
336
if ( !(eventIterator.nextEvent() instanceof StepEvent)) {
337
log3("ERROR: new event is not StepEvent");
338
testExitCode = FAILED;
339
} else {
340
log2("......got : instanceof StepEvent");
341
policy = eventSet.suspendPolicy();
342
if (policy != policyExpected[i]) {
343
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
344
log3(" eventSet.suspendPolicy() == " + policy);
345
log3(" policyExpected == " + policyExpected[i]);
346
testExitCode = FAILED;
347
}
348
}
349
350
switch (i) {
351
case 0: eventRequest1.disable(); break;
352
case 1: eventRequest2.disable(); break;
353
case 2: eventRequest3.disable(); break;
354
}
355
356
switch (policy) {
357
case SUSPEND_NONE : break;
358
case SUSPEND_THREAD : mainThread.resume(); break;
359
case SUSPEND_ALL : vm.resume(); break;
360
default: throw new JDITestRuntimeException("** default case 3 **");
361
}
362
363
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
}
365
log1(" TESTING ENDS");
366
return;
367
}
368
369
// ============================== test's additional methods
370
371
private StepRequest settingStepRequest ( ThreadReference thread,
372
int suspendPolicy,
373
String property )
374
throws JDITestRuntimeException {
375
try {
376
log2("......setting up StepRequest:");
377
log2(" thread: " + thread + "; property: " + property);
378
379
StepRequest
380
str = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
381
str.putProperty("number", property);
382
str.addCountFilter(1);
383
str.setSuspendPolicy(suspendPolicy);
384
385
log2(" StepRequest has been set up");
386
return str;
387
} catch ( Exception e ) {
388
log3("ERROR: ATTENTION: Exception within settingStepRequest() : " + e);
389
log3(" StepRequest HAS NOT BEEN SET UP");
390
throw new JDITestRuntimeException("** FAILURE to set up StepRequest **");
391
}
392
}
393
394
}
395
396