Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/deleteEventRequest/delevtreq002.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.EventRequestManager.deleteEventRequest;
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
* EventRequestManager. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequestManager.deleteEventRequest()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* Once the eventRequest is deleted, no operations <BR>
47
* (for example, EventRequest.setEnabled(boolean)) are permitted - <BR>
48
* attempts to do so will generally cause <BR>
49
* an InvalidRequestStateException. <BR>
50
* Note: only operations specified to throw InvalidRequestStateException <BR>
51
* are not permitted. <BR>
52
* Testcases unclude all 12 subclasses of EventRequest created by <BR>
53
* EventRequestManager. <BR>
54
* <BR>
55
* The test has three phases and works as follows. <BR>
56
* <BR>
57
* In first phase, <BR>
58
* upon launching debuggee's VM which will be suspended, <BR>
59
* a debugger waits for the VMStartEvent within a predefined <BR>
60
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
61
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
62
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
63
* and waits for the event within the predefined time interval. <BR>
64
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
65
* Upon getting the ClassPrepareEvent, <BR>
66
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
67
* within debuggee's special methodForCommunication(). <BR>
68
* <BR>
69
* In second phase to check the assertion, <BR>
70
* the debugger and the debuggee perform the following. <BR>
71
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
72
* - The debuggee prepares testcases and invokes <BR>
73
* the methodForCommunication to be suspended and <BR>
74
* to inform the debugger with the event. <BR>
75
* - Upon getting the BreakpointEvent, <BR>
76
* the debugger performs the checks required. <BR>
77
* <BR>
78
* In third phase, at the end of the test, the debuggee changes <BR>
79
* the value of the "instruction" which the debugger and debuggee <BR>
80
* use to inform each other of needed actions, and both end. <BR>
81
* <BR>
82
*/
83
84
public class delevtreq002 extends JDIBase {
85
86
public static void main (String argv[]) {
87
88
int result = run(argv, System.out);
89
90
System.exit(result + PASS_BASE);
91
}
92
93
public static int run (String argv[], PrintStream out) {
94
95
int exitCode = new delevtreq002().runThis(argv, out);
96
97
if (exitCode != PASSED) {
98
System.out.println("TEST FAILED");
99
}
100
return testExitCode;
101
}
102
103
// ************************************************ test parameters
104
105
private String debuggeeName =
106
"nsk.jdi.EventRequestManager.deleteEventRequest.delevtreq002a";
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
EventRequest requestArray[] = new EventRequest[12];
260
261
String fieldName1 = "testField1";
262
String fieldName2 = "testField2";
263
String fieldName3 = "testField3";
264
265
266
log1(" TESTING BEGINS");
267
268
for (int i = 0; ; i++) {
269
270
vm.resume();
271
breakpointForCommunication();
272
273
int instruction = ((IntegerValue)
274
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
275
276
if (instruction == 0) {
277
vm.resume();
278
break;
279
}
280
281
log1(":::::: case: # " + i);
282
283
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
284
285
286
Field field1 = debuggeeClass.fieldByName(fieldName1);
287
288
ReferenceType refType = (ReferenceType)
289
debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2)).type();
290
291
ThreadReference threadRef = (ThreadReference)
292
debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName3));
293
294
String requests[] = { "AccessWatchpoint", "ModificationWatchpoint",
295
"Breakpoint", "ClassPrepare",
296
"ClassUnload", "Exception",
297
"MethodEntry", "MethodExit",
298
"Step", "ThreadDeath",
299
"ThreadStart", "VMDeath" };
300
301
requestArray[0] = eventRManager.createAccessWatchpointRequest(field1);
302
requestArray[1] = eventRManager.createModificationWatchpointRequest(field1);
303
requestArray[2] = eventRManager.createBreakpointRequest(breakpLocation);
304
requestArray[3] = eventRManager.createClassPrepareRequest();
305
requestArray[4] = eventRManager.createClassUnloadRequest();
306
requestArray[5] = eventRManager.createExceptionRequest(refType, false, false);
307
requestArray[6] = eventRManager.createMethodEntryRequest();
308
requestArray[7] = eventRManager.createMethodExitRequest();
309
requestArray[8] = eventRManager.createStepRequest(threadRef, StepRequest.STEP_MIN, StepRequest.STEP_OUT);
310
requestArray[9] = eventRManager.createThreadDeathRequest();
311
requestArray[10] = eventRManager.createThreadStartRequest();
312
requestArray[11] = eventRManager.createVMDeathRequest();
313
314
for (int i1 = 0; i1 < requestArray.length; i1++) {
315
316
log2("......eventRManager.deleteEventRequest(requestArray[i1]); :: " + requests[i1]);
317
eventRManager.deleteEventRequest(requestArray[i1]);
318
319
try {
320
requestArray[i1].addCountFilter(1);
321
testExitCode = FAILED;
322
log3("ERROR: NO InvalidRequestStateException for addCountFilter(1);");
323
} catch ( InvalidRequestStateException e ) {
324
}
325
try {
326
requestArray[i1].disable();
327
testExitCode = FAILED;
328
log3("ERROR: NO InvalidRequestStateException for disable();");
329
} catch ( InvalidRequestStateException e ) {
330
}
331
try {
332
requestArray[i1].enable();
333
testExitCode = FAILED;
334
log3("ERROR: NO InvalidRequestStateException for enable();");
335
} catch ( InvalidRequestStateException e ) {
336
}
337
try {
338
requestArray[i1].getProperty("number");
339
} catch ( InvalidRequestStateException e ) {
340
testExitCode = FAILED;
341
log3("ERROR: InvalidRequestStateException for getProperty('number');");
342
}
343
try {
344
requestArray[i1].isEnabled();
345
} catch ( InvalidRequestStateException e ) {
346
testExitCode = FAILED;
347
log3("ERROR: InvalidRequestStateException for isEnabled();");
348
}
349
try {
350
requestArray[i1].putProperty("number", "request" + i1);
351
} catch ( InvalidRequestStateException e ) {
352
testExitCode = FAILED;
353
log3("ERROR: InvalidRequestStateException for putProperty('number', 'request' + i1);");
354
}
355
try {
356
requestArray[i1].setEnabled(true);
357
testExitCode = FAILED;
358
log3("ERROR: NO InvalidRequestStateException for setEnabled(true);");
359
} catch ( InvalidRequestStateException e ) {
360
}
361
try {
362
requestArray[i1].setSuspendPolicy(EventRequest.SUSPEND_NONE);
363
testExitCode = FAILED;
364
log3("ERROR: NO InvalidRequestStateException for setSuspendPolicy(EventRequest.SUSPEND_NONE);");
365
} catch ( InvalidRequestStateException e ) {
366
}
367
try {
368
requestArray[i1].suspendPolicy();
369
} catch ( InvalidRequestStateException e ) {
370
testExitCode = FAILED;
371
log3("ERROR: InvalidRequestStateException for suspendPolicy();");
372
}
373
}
374
375
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376
}
377
log1(" TESTING ENDS");
378
return;
379
}
380
381
}
382
383