Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/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.EventRequest.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
* EventRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequest.suspendPolicy()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on following assertions: <BR>
46
* - Returns: the current suspend mode for this request <BR>
47
* The cases to check include Requests of all sub-types. <BR>
48
* <BR>
49
* The test has three phases and works as follows. <BR>
50
* <BR>
51
* In first phase, <BR>
52
* upon launching debuggee's VM which will be suspended, <BR>
53
* a debugger waits for the VMStartEvent within a predefined <BR>
54
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
55
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
56
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
57
* and waits for the event within the predefined time interval. <BR>
58
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
59
* Upon getting the ClassPrepareEvent, <BR>
60
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
61
* within debuggee's special methodForCommunication(). <BR>
62
* <BR>
63
* In second phase to check the assertion, <BR>
64
* the debugger and the debuggee perform the following loop. <BR>
65
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
66
* - The debuggee prepares new check case (as if) and invokes <BR>
67
* the methodForCommunication to be suspended and <BR>
68
* to inform the debugger with the event. <BR>
69
* - Upon getting the BreakpointEvent, <BR>
70
* the debugger performs the check case required. <BR>
71
* <BR>
72
* In third phase, at the end of the test, the debuggee changes <BR>
73
* the value of the "instruction" which the debugger and debuggee <BR>
74
* use to inform each other of needed actions, and both end. <BR>
75
* <BR>
76
*/
77
78
public class suspendpolicy001 extends JDIBase {
79
80
public static void main (String argv[]) {
81
82
int result = run(argv, System.out);
83
84
System.exit(result + PASS_BASE);
85
}
86
87
public static int run (String argv[], PrintStream out) {
88
89
int exitCode = new suspendpolicy001().runThis(argv, out);
90
91
if (exitCode != PASSED) {
92
System.out.println("TEST FAILED");
93
}
94
return testExitCode;
95
}
96
97
// ************************************************ test parameters
98
99
private String debuggeeName =
100
"nsk.jdi.EventRequest.suspendPolicy.suspendpolicy001a";
101
102
private String testedClassName =
103
"nsk.jdi.EventRequest.suspendPolicy.TestClass11";
104
105
106
//====================================================== test program
107
108
private int runThis (String argv[], PrintStream out) {
109
110
argsHandler = new ArgumentHandler(argv);
111
logHandler = new Log(out, argsHandler);
112
Binder binder = new Binder(argsHandler, logHandler);
113
114
waitTime = argsHandler.getWaitTime() * 60000;
115
116
try {
117
log2("launching a debuggee :");
118
log2(" " + debuggeeName);
119
if (argsHandler.verbose()) {
120
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
121
} else {
122
debuggee = binder.bindToDebugee(debuggeeName);
123
}
124
if (debuggee == null) {
125
log3("ERROR: no debuggee launched");
126
return FAILED;
127
}
128
log2("debuggee launched");
129
} catch ( Exception e ) {
130
log3("ERROR: Exception : " + e);
131
log2(" test cancelled");
132
return FAILED;
133
}
134
135
debuggee.redirectOutput(logHandler);
136
137
vm = debuggee.VM();
138
139
eventQueue = vm.eventQueue();
140
if (eventQueue == null) {
141
log3("ERROR: eventQueue == null : TEST ABORTED");
142
vm.exit(PASS_BASE);
143
return FAILED;
144
}
145
146
log2("invocation of the method runTest()");
147
switch (runTest()) {
148
149
case 0 : log2("test phase has finished normally");
150
log2(" waiting for the debuggee to finish ...");
151
debuggee.waitFor();
152
153
log2("......getting the debuggee's exit status");
154
int status = debuggee.getStatus();
155
if (status != PASS_BASE) {
156
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
157
status + " != PASS_BASE");
158
testExitCode = FAILED;
159
} else {
160
log2("......debuggee returned expected exit status: " +
161
status + " == PASS_BASE");
162
}
163
break;
164
165
default : log3("ERROR: runTest() returned unexpected value");
166
167
case 1 : log3("test phase has not finished normally: debuggee is still alive");
168
log2("......forcing: vm.exit();");
169
testExitCode = FAILED;
170
try {
171
vm.exit(PASS_BASE);
172
} catch ( Exception e ) {
173
log3("ERROR: Exception : " + e);
174
}
175
break;
176
177
case 2 : log3("test cancelled due to VMDisconnectedException");
178
log2("......trying: vm.process().destroy();");
179
testExitCode = FAILED;
180
try {
181
Process vmProcess = vm.process();
182
if (vmProcess != null) {
183
vmProcess.destroy();
184
}
185
} catch ( Exception e ) {
186
log3("ERROR: Exception : " + e);
187
}
188
break;
189
}
190
191
return testExitCode;
192
}
193
194
195
/*
196
* Return value: 0 - normal end of the test
197
* 1 - ubnormal end of the test
198
* 2 - VMDisconnectedException while test phase
199
*/
200
201
private int runTest() {
202
203
try {
204
testRun();
205
206
log2("waiting for VMDeathEvent");
207
getEventSet();
208
if (eventIterator.nextEvent() instanceof VMDeathEvent)
209
return 0;
210
211
log3("ERROR: last event is not the VMDeathEvent");
212
return 1;
213
} catch ( VMDisconnectedException e ) {
214
log3("ERROR: VMDisconnectedException : " + e);
215
return 2;
216
} catch ( Exception e ) {
217
log3("ERROR: Exception : " + e);
218
return 1;
219
}
220
221
}
222
223
private void testRun()
224
throws JDITestRuntimeException, Exception {
225
226
eventRManager = vm.eventRequestManager();
227
228
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
229
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
230
cpRequest.addClassFilter(debuggeeName);
231
232
cpRequest.enable();
233
vm.resume();
234
getEventSet();
235
cpRequest.disable();
236
237
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
238
debuggeeClass = event.referenceType();
239
240
if (!debuggeeClass.name().equals(debuggeeName))
241
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
242
243
log2(" received: ClassPrepareEvent for debuggeeClass");
244
245
String bPointMethod = "methodForCommunication";
246
String lineForComm = "lineForComm";
247
248
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
249
250
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
251
debuggeeClass,
252
bPointMethod, lineForComm, "zero");
253
bpRequest.enable();
254
255
//------------------------------------------------------ testing section
256
257
258
EventRequest eventRequest1 = null;
259
260
String fieldName1 = "var101";
261
String fieldName2 = "excObj";
262
263
ThreadReference thread1 = null;
264
String threadName1 = "thread1";
265
266
ReferenceType testClassReference = null;
267
268
String propertyName = "name";
269
String propertyValue1 = "value1";
270
String propertyValue2 = "value2";
271
272
273
log1(" TESTING BEGINS");
274
275
for (int i = 0; ; i++) {
276
277
vm.resume();
278
breakpointForCommunication();
279
280
int instruction = ((IntegerValue)
281
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
282
283
if (instruction == 0) {
284
vm.resume();
285
break;
286
}
287
288
log1(":::::: case: # " + i);
289
290
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
291
292
293
switch (i) {
294
295
case 0:
296
thread1 = debuggee.threadByNameOrThrow(threadName1);
297
298
log2("......setting up StepRequest");
299
eventRequest1 = eventRManager.createStepRequest
300
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
301
break;
302
303
case 1:
304
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
305
306
log2("......setting up AccessWatchpointRequest");
307
eventRequest1 = eventRManager.createAccessWatchpointRequest
308
(testClassReference.fieldByName(fieldName1));
309
break;
310
311
case 2:
312
log2(".....setting up ModificationWatchpointRequest");
313
eventRequest1 = eventRManager.createModificationWatchpointRequest
314
(testClassReference.fieldByName(fieldName1));
315
break;
316
317
case 3:
318
log2(".....setting up ClassPrepareRequest");
319
eventRequest1 = eventRManager.createClassPrepareRequest();
320
break;
321
322
case 4:
323
log2(".....setting up ClassUnloadRequest");
324
eventRequest1 = eventRManager.createClassUnloadRequest();
325
break;
326
327
case 5:
328
log2(".....setting up MethodEntryRequest");
329
eventRequest1 = eventRManager.createMethodEntryRequest();
330
break;
331
332
case 6:
333
log2(".....setting up MethodExitRequest");
334
eventRequest1 = eventRManager.createMethodExitRequest();
335
break;
336
337
case 7:
338
log2(".....setting up ThreadDeathRequest");
339
eventRequest1 = eventRManager.createThreadDeathRequest();
340
break;
341
342
case 8:
343
log2(".....setting up ThreadStartRequest");
344
eventRequest1 = eventRManager.createThreadStartRequest();
345
break;
346
347
case 9:
348
log2(".....setting up VMDeathRequest");
349
eventRequest1 = eventRManager.createVMDeathRequest();
350
break;
351
352
case 10:
353
log2(".....setting up ExceptionRequest");
354
eventRequest1 = eventRManager.createExceptionRequest(
355
(ReferenceType)
356
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
357
true, true );
358
break;
359
360
case 11:
361
log2(".....setting up BreakpointRequest");
362
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
363
break;
364
365
366
default:
367
throw new JDITestRuntimeException("** default case 2 **");
368
}
369
370
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_ALL);");
371
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_ALL);
372
373
log2(" checking up on eventRequest1");
374
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_ALL) {
375
testExitCode = FAILED;
376
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_ALL");
377
}
378
379
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD );");
380
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD );
381
382
log2(" checking up on eventRequest1");
383
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD ) {
384
testExitCode = FAILED;
385
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_EVENT_THREAD ");
386
}
387
388
log2("......eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);");
389
eventRequest1.setSuspendPolicy(EventRequest.SUSPEND_NONE);
390
391
log2(" checking up on eventRequest1");
392
if ( eventRequest1.suspendPolicy() != EventRequest.SUSPEND_NONE) {
393
testExitCode = FAILED;
394
log3("ERROR: suspendPolicy() != EventRequest.SUSPEND_NONE");
395
}
396
397
eventRManager.deleteEventRequest(eventRequest1);
398
399
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
400
}
401
log1(" TESTING ENDS");
402
return;
403
}
404
405
}
406
407