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