Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/disable/disable002.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.disable;
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.disable()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* Throws: InvalidRequestStateException - <BR>
47
* if this request has been deleted. <BR>
48
* The cases to test include all sub-types of EventRequest. <BR>
49
* <BR>
50
* The test has three phases and works as follows. <BR>
51
* <BR>
52
* In first phase, <BR>
53
* upon launching debuggee's VM which will be suspended, <BR>
54
* a debugger waits for the VMStartEvent within a predefined <BR>
55
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
56
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
57
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
58
* and waits for the event within the predefined time interval. <BR>
59
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
60
* Upon getting the ClassPrepareEvent, <BR>
61
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
62
* within debuggee's special methodForCommunication(). <BR>
63
* <BR>
64
* In second phase to check the assertion, <BR>
65
* the debugger and the debuggee perform the following loop. <BR>
66
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
67
* - The debuggee prepares new check case (as if) and invokes <BR>
68
* the methodForCommunication to be suspended and <BR>
69
* to inform the debugger with the event. <BR>
70
* - Upon getting the BreakpointEvent, <BR>
71
* the debugger performs the check case required. <BR>
72
* <BR>
73
* In third phase, at the end of the test, the debuggee changes <BR>
74
* the value of the "instruction" which the debugger and debuggee <BR>
75
* use to inform each other of needed actions, and both end. <BR>
76
* <BR>
77
*/
78
79
public class disable002 extends JDIBase {
80
81
public static void main (String argv[]) {
82
83
int result = run(argv, System.out);
84
85
System.exit(result + PASS_BASE);
86
}
87
88
public static int run (String argv[], PrintStream out) {
89
90
int exitCode = new disable002().runThis(argv, out);
91
92
if (exitCode != PASSED) {
93
System.out.println("TEST FAILED");
94
}
95
return testExitCode;
96
}
97
98
// ************************************************ test parameters
99
100
private String debuggeeName =
101
"nsk.jdi.EventRequest.disable.disable002a";
102
103
private String testedClassName =
104
"nsk.jdi.EventRequest.disable.disable002aTestClass11";
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
269
log1(" TESTING BEGINS");
270
271
for (int i = 0; ; i++) {
272
273
vm.resume();
274
breakpointForCommunication();
275
276
int instruction = ((IntegerValue)
277
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
278
279
if (instruction == 0) {
280
vm.resume();
281
break;
282
}
283
284
log1(":::::: case: # " + i);
285
286
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
287
288
289
switch (i) {
290
291
case 0:
292
thread1 = debuggee.threadByNameOrThrow(threadName1);
293
294
log2("......setting up StepRequest");
295
eventRequest1 = eventRManager.createStepRequest
296
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
297
break;
298
299
case 1:
300
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
301
302
log2("......setting up AccessWatchpointRequest");
303
eventRequest1 = eventRManager.createAccessWatchpointRequest
304
(testClassReference.fieldByName(fieldName1));
305
break;
306
307
case 2:
308
log2(".....setting up ModificationWatchpointRequest");
309
eventRequest1 = eventRManager.createModificationWatchpointRequest
310
(testClassReference.fieldByName(fieldName1));
311
break;
312
313
case 3:
314
log2(".....setting up ClassPrepareRequest");
315
eventRequest1 = eventRManager.createClassPrepareRequest();
316
break;
317
318
case 4:
319
log2(".....setting up ClassUnloadRequest");
320
eventRequest1 = eventRManager.createClassUnloadRequest();
321
break;
322
323
case 5:
324
log2(".....setting up MethodEntryRequest");
325
eventRequest1 = eventRManager.createMethodEntryRequest();
326
break;
327
328
case 6:
329
log2(".....setting up MethodExitRequest");
330
eventRequest1 = eventRManager.createMethodExitRequest();
331
break;
332
333
case 7:
334
log2(".....setting up ThreadDeathRequest");
335
eventRequest1 = eventRManager.createThreadDeathRequest();
336
break;
337
338
case 8:
339
log2(".....setting up ThreadStartRequest");
340
eventRequest1 = eventRManager.createThreadStartRequest();
341
break;
342
343
case 9:
344
log2(".....setting up VMDeathRequest");
345
eventRequest1 = eventRManager.createVMDeathRequest();
346
break;
347
348
case 10:
349
log2(".....setting up ExceptionRequest");
350
eventRequest1 = eventRManager.createExceptionRequest(
351
(ReferenceType)
352
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
353
true, true );
354
break;
355
356
case 11:
357
log2(".....setting up BreakpointRequest");
358
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
359
break;
360
361
362
default:
363
throw new JDITestRuntimeException("** default case 2 **");
364
}
365
366
log2("......eventRManager.deleteEventRequest(eventRequest1);");
367
eventRManager.deleteEventRequest(eventRequest1);
368
try {
369
log2("......eventRequest1.enable(); InvalidRequestStateException is expected");
370
eventRequest1.disable();
371
testExitCode = FAILED;
372
log3("ERROR: NO InvalidRequestStateException");
373
} catch ( InvalidRequestStateException e ) {
374
log2(" InvalidRequestStateException");
375
}
376
377
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
378
}
379
log1(" TESTING ENDS");
380
return;
381
}
382
383
384
}
385
386