Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/setSuspendPolicy/setsuspendpolicy001.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.EventRequest.setSuspendPolicy;
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
* EventRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequest.setSuspendPolicy()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on following assertions: <BR>
46
* - a value of policy is equal to one assigned by last method <BR>
47
* setSuspendPolicy(int); <BR>
48
* - InvalidRequestStateException is thrown <BR>
49
* if this request is currently enabled; <BR>
50
* - InvalidRequestStateException is thrown <BR>
51
* if this request has been deleted. <BR>
52
* The cases to check include Requests of all sub-types. <BR>
53
* <BR>
54
* The test has three phases and works as follows. <BR>
55
* <BR>
56
* In first phase, <BR>
57
* upon launching debuggee's VM which will be suspended, <BR>
58
* a debugger waits for the VMStartEvent within a predefined <BR>
59
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
60
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
61
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
62
* and waits for the event within the predefined time interval. <BR>
63
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
64
* Upon getting the ClassPrepareEvent, <BR>
65
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
66
* within debuggee's special methodForCommunication(). <BR>
67
* <BR>
68
* In second phase to check the assertion, <BR>
69
* the debugger and the debuggee perform the following loop. <BR>
70
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
71
* - The debuggee prepares new check case (as if) and invokes <BR>
72
* the methodForCommunication to be suspended and <BR>
73
* to inform the debugger with the event. <BR>
74
* - Upon getting the BreakpointEvent, <BR>
75
* the debugger performs the check case required. <BR>
76
* <BR>
77
* In third phase, at the end of the test, the debuggee changes <BR>
78
* the value of the "instruction" which the debugger and debuggee <BR>
79
* use to inform each other of needed actions, and both end. <BR>
80
* <BR>
81
*/
82
83
public class setsuspendpolicy001 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 setsuspendpolicy001().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.EventRequest.setSuspendPolicy.setsuspendpolicy001a";
106
107
private String testedClassName =
108
"nsk.jdi.EventRequest.setSuspendPolicy.TestClass11";
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
return 0;
214
215
log3("ERROR: last event is not the VMDeathEvent");
216
return 1;
217
} catch ( VMDisconnectedException e ) {
218
log3("ERROR: VMDisconnectedException : " + e);
219
return 2;
220
} catch ( Exception e ) {
221
log3("ERROR: Exception : " + e);
222
return 1;
223
}
224
225
}
226
227
private void testRun()
228
throws JDITestRuntimeException, Exception {
229
230
eventRManager = vm.eventRequestManager();
231
232
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
233
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
234
cpRequest.addClassFilter(debuggeeName);
235
236
cpRequest.enable();
237
vm.resume();
238
getEventSet();
239
cpRequest.disable();
240
241
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
242
debuggeeClass = event.referenceType();
243
244
if (!debuggeeClass.name().equals(debuggeeName))
245
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
246
247
log2(" received: ClassPrepareEvent for debuggeeClass");
248
249
String bPointMethod = "methodForCommunication";
250
String lineForComm = "lineForComm";
251
252
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
253
254
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
255
debuggeeClass,
256
bPointMethod, lineForComm, "zero");
257
bpRequest.enable();
258
259
//------------------------------------------------------ testing section
260
261
262
EventRequest eventRequest1 = null;
263
264
String fieldName1 = "var101";
265
String fieldName2 = "excObj";
266
267
ThreadReference thread1 = null;
268
String threadName1 = "thread1";
269
270
ReferenceType testClassReference = null;
271
272
String propertyName = "name";
273
String propertyValue1 = "value1";
274
String propertyValue2 = "value2";
275
276
277
log1(" TESTING BEGINS");
278
279
for (int i = 0; ; i++) {
280
281
vm.resume();
282
breakpointForCommunication();
283
284
int instruction = ((IntegerValue)
285
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
286
287
if (instruction == 0) {
288
vm.resume();
289
break;
290
}
291
292
log1(":::::: case: # " + i);
293
294
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
295
296
297
switch (i) {
298
299
case 0:
300
thread1 = debuggee.threadByNameOrThrow(threadName1);
301
302
log2("......setting up StepRequest");
303
eventRequest1 = eventRManager.createStepRequest
304
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
305
break;
306
307
case 1:
308
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
309
310
log2("......setting up AccessWatchpointRequest");
311
eventRequest1 = eventRManager.createAccessWatchpointRequest
312
(testClassReference.fieldByName(fieldName1));
313
break;
314
315
case 2:
316
log2(".....setting up ModificationWatchpointRequest");
317
eventRequest1 = eventRManager.createModificationWatchpointRequest
318
(testClassReference.fieldByName(fieldName1));
319
break;
320
321
case 3:
322
log2(".....setting up ClassPrepareRequest");
323
eventRequest1 = eventRManager.createClassPrepareRequest();
324
break;
325
326
case 4:
327
log2(".....setting up ClassUnloadRequest");
328
eventRequest1 = eventRManager.createClassUnloadRequest();
329
break;
330
331
case 5:
332
log2(".....setting up MethodEntryRequest");
333
eventRequest1 = eventRManager.createMethodEntryRequest();
334
break;
335
336
case 6:
337
log2(".....setting up MethodExitRequest");
338
eventRequest1 = eventRManager.createMethodExitRequest();
339
break;
340
341
case 7:
342
log2(".....setting up ThreadDeathRequest");
343
eventRequest1 = eventRManager.createThreadDeathRequest();
344
break;
345
346
case 8:
347
log2(".....setting up ThreadStartRequest");
348
eventRequest1 = eventRManager.createThreadStartRequest();
349
break;
350
351
case 9:
352
log2(".....setting up VMDeathRequest");
353
eventRequest1 = eventRManager.createVMDeathRequest();
354
break;
355
356
case 10:
357
log2(".....setting up ExceptionRequest");
358
eventRequest1 = eventRManager.createExceptionRequest(
359
(ReferenceType)
360
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
361
true, true );
362
break;
363
364
case 11:
365
log2(".....setting up BreakpointRequest");
366
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
367
break;
368
369
370
default:
371
throw new JDITestRuntimeException("** default case 2 **");
372
}
373
374
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);");
375
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);
376
377
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_ALL);");
378
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_ALL);
379
380
log2(" checking up on eventRequest1");
381
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_ALL) {
382
testExitCode = FAILED;
383
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_ALL");
384
}
385
386
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD );");
387
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD );
388
389
log2(" checking up on eventRequest1");
390
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD ) {
391
testExitCode = FAILED;
392
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD ");
393
}
394
395
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);");
396
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);
397
398
log2(" checking up on eventRequest1");
399
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_NONE) {
400
testExitCode = FAILED;
401
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_NONE");
402
}
403
404
vm.suspend();
405
log2("......eventRequest1.setEnabled(true);");
406
eventRequest1.setEnabled(true);
407
try {
408
log2(" checking up on eventRequest1; InvalidRequestStateException is expected");
409
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);
410
testExitCode = FAILED;
411
log3("ERROR: NO InvalidRequestStateException");
412
} catch ( InvalidRequestStateException e ) {
413
log2(" InvalidRequestStateException");
414
}
415
log2("......eventRManager.deleteEventRequest(eventRequest1);");
416
eventRManager.deleteEventRequest(eventRequest1);
417
try {
418
log2(" checking up on eventRequest1; InvalidRequestStateException is expected");
419
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);
420
testExitCode = FAILED;
421
log3("ERROR: NO InvalidRequestStateException");
422
} catch ( InvalidRequestStateException e ) {
423
log2(" InvalidRequestStateException");
424
}
425
vm.resume();
426
427
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
428
}
429
log1(" TESTING ENDS");
430
return;
431
}
432
433
}
434
435