Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/enable/enable002.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.enable;
25
26
import nsk.share.*;
27
import nsk.share.jdi.*;
28
29
import com.sun.jdi.*;
30
import com.sun.jdi.event.*;
31
import com.sun.jdi.request.*;
32
33
import java.io.*;
34
35
/**
36
* The test for the implementation of an object of the type <BR>
37
* EventRequest. <BR>
38
* <BR>
39
* The test checks that results of the method <BR>
40
* <code>com.sun.jdi.EventRequest.enable()</code> <BR>
41
* complies with its spec. <BR>
42
* <BR>
43
* The test checks up on the following assertion: <BR>
44
* Throws: InvalidRequestStateException - <BR>
45
* if this request has been deleted. <BR>
46
* IllegalThreadStateException - <BR>
47
* if this is a StepRequest and <BR>
48
* the thread named in the request has died. <BR>
49
* The cases to test include all sub-types of EventRequest. <BR>
50
* <BR>
51
* The test has three phases and works as follows. <BR>
52
* <BR>
53
* In first phase, <BR>
54
* upon launching debuggee's VM which will be suspended, <BR>
55
* a debugger waits for the VMStartEvent within a predefined <BR>
56
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
57
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
58
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
59
* and waits for the event within the predefined time interval. <BR>
60
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
61
* Upon getting the ClassPrepareEvent, <BR>
62
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
63
* within debuggee's special methodForCommunication(). <BR>
64
* <BR>
65
* In second phase to check the assertion, <BR>
66
* the debugger and the debuggee perform the following loop. <BR>
67
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
68
* - The debuggee prepares new check case (as if) and invokes <BR>
69
* the methodForCommunication to be suspended and <BR>
70
* to inform the debugger with the event. <BR>
71
* - Upon getting the BreakpointEvent, <BR>
72
* the debugger performs the check case required. <BR>
73
* <BR>
74
* In third phase, at the end of the test, the debuggee changes <BR>
75
* the value of the "instruction" which the debugger and debuggee <BR>
76
* use to inform each other of needed actions, and both end. <BR>
77
* <BR>
78
*/
79
80
public class enable002 extends JDIBase {
81
82
public static void main (String argv[]) {
83
84
int result = run(argv, System.out);
85
86
System.exit(result + PASS_BASE);
87
}
88
89
public static int run (String argv[], PrintStream out) {
90
91
int exitCode = new enable002().runThis(argv, out);
92
93
if (exitCode != PASSED) {
94
System.out.println("TEST FAILED");
95
}
96
return testExitCode;
97
}
98
99
// ************************************************ test parameters
100
101
private String debuggeeName =
102
"nsk.jdi.EventRequest.enable.enable002a";
103
104
private String testedClassName =
105
"nsk.jdi.EventRequest.enable.enable002aTestClass11";
106
107
108
//====================================================== test program
109
110
private int runThis (String argv[], PrintStream out) {
111
112
argsHandler = new ArgumentHandler(argv);
113
logHandler = new Log(out, argsHandler);
114
Binder binder = new Binder(argsHandler, logHandler);
115
116
waitTime = argsHandler.getWaitTime() * 60000;
117
118
try {
119
log2("launching a debuggee :");
120
log2(" " + debuggeeName);
121
if (argsHandler.verbose()) {
122
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
123
} else {
124
debuggee = binder.bindToDebugee(debuggeeName);
125
}
126
if (debuggee == null) {
127
log3("ERROR: no debuggee launched");
128
return FAILED;
129
}
130
log2("debuggee launched");
131
} catch ( Exception e ) {
132
log3("ERROR: Exception : " + e);
133
log2(" test cancelled");
134
return FAILED;
135
}
136
137
debuggee.redirectOutput(logHandler);
138
139
vm = debuggee.VM();
140
141
eventQueue = vm.eventQueue();
142
if (eventQueue == null) {
143
log3("ERROR: eventQueue == null : TEST ABORTED");
144
vm.exit(PASS_BASE);
145
return FAILED;
146
}
147
148
log2("invocation of the method runTest()");
149
switch (runTest()) {
150
151
case 0 : log2("test phase has finished normally");
152
log2(" waiting for the debuggee to finish ...");
153
debuggee.waitFor();
154
155
log2("......getting the debuggee's exit status");
156
int status = debuggee.getStatus();
157
if (status != PASS_BASE) {
158
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
159
status + " != PASS_BASE");
160
testExitCode = FAILED;
161
} else {
162
log2("......debuggee returned expected exit status: " +
163
status + " == PASS_BASE");
164
}
165
break;
166
167
default : log3("ERROR: runTest() returned unexpected value");
168
169
case 1 : log3("test phase has not finished normally: debuggee is still alive");
170
log2("......forcing: vm.exit();");
171
testExitCode = FAILED;
172
try {
173
vm.exit(PASS_BASE);
174
} catch ( Exception e ) {
175
log3("ERROR: Exception : " + e);
176
}
177
break;
178
179
case 2 : log3("test cancelled due to VMDisconnectedException");
180
log2("......trying: vm.process().destroy();");
181
testExitCode = FAILED;
182
try {
183
Process vmProcess = vm.process();
184
if (vmProcess != null) {
185
vmProcess.destroy();
186
}
187
} catch ( Exception e ) {
188
log3("ERROR: Exception : " + e);
189
}
190
break;
191
}
192
193
return testExitCode;
194
}
195
196
197
/*
198
* Return value: 0 - normal end of the test
199
* 1 - ubnormal end of the test
200
* 2 - VMDisconnectedException while test phase
201
*/
202
203
private int runTest() {
204
205
try {
206
testRun();
207
208
log2("waiting for VMDeathEvent");
209
getEventSet();
210
if (eventIterator.nextEvent() instanceof VMDeathEvent)
211
return 0;
212
213
log3("ERROR: last event is not the VMDeathEvent");
214
return 1;
215
} catch ( VMDisconnectedException e ) {
216
log3("ERROR: VMDisconnectedException : " + e);
217
return 2;
218
} catch ( Exception e ) {
219
log3("ERROR: Exception : " + e);
220
return 1;
221
}
222
223
}
224
225
private void testRun()
226
throws JDITestRuntimeException, Exception {
227
228
eventRManager = vm.eventRequestManager();
229
230
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
231
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
232
cpRequest.addClassFilter(debuggeeName);
233
234
cpRequest.enable();
235
vm.resume();
236
getEventSet();
237
cpRequest.disable();
238
239
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
240
debuggeeClass = event.referenceType();
241
242
if (!debuggeeClass.name().equals(debuggeeName))
243
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
244
245
log2(" received: ClassPrepareEvent for debuggeeClass");
246
247
String bPointMethod = "methodForCommunication";
248
String lineForComm = "lineForComm";
249
250
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
251
252
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
253
debuggeeClass,
254
bPointMethod, lineForComm, "zero");
255
bpRequest.enable();
256
257
//------------------------------------------------------ testing section
258
259
260
EventRequest eventRequest1 = null;
261
262
String fieldName1 = "var101";
263
String fieldName2 = "excObj";
264
265
ThreadReference thread1 = null;
266
String threadName1 = "thread1";
267
268
ReferenceType testClassReference = null;
269
270
271
log1(" TESTING BEGINS");
272
273
for (int i = 0; ; i++) {
274
275
vm.resume();
276
breakpointForCommunication();
277
278
int instruction = ((IntegerValue)
279
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
280
281
if (instruction == 0) {
282
vm.resume();
283
break;
284
}
285
286
log1(":::::: case: # " + i);
287
288
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
289
290
291
switch (i) {
292
293
case 0:
294
thread1 = debuggee.threadByNameOrThrow(threadName1);
295
296
log2("......setting up StepRequest");
297
eventRequest1 = eventRManager.createStepRequest
298
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
299
vm.resume();
300
breakpointForCommunication();
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
if (eventRequest1 instanceof StepRequest) {
371
try {
372
log2("......eventRequest1.enable(); IllegalThreadStateException is expected");
373
eventRequest1.enable();
374
testExitCode = FAILED;
375
log3("ERROR: NO IllegalThreadStateException for StepRequest");
376
} catch ( IllegalThreadStateException e ) {
377
log2(" IllegalThreadStateException");
378
}
379
}
380
381
log2("......eventRManager.deleteEventRequest(eventRequest1);");
382
eventRManager.deleteEventRequest(eventRequest1);
383
try {
384
log2("......eventRequest1.enable(); InvalidRequestStateException is expected");
385
eventRequest1.enable();
386
testExitCode = FAILED;
387
log3("ERROR: NO InvalidRequestStateException");
388
} catch ( InvalidRequestStateException e ) {
389
log2(" InvalidRequestStateException");
390
}
391
392
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393
}
394
log1(" TESTING ENDS");
395
return;
396
}
397
398
}
399
400