Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/methodExitRequests/methexitreq002.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.methodExitRequests;
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.methodExitRequests()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - The list is unmodifiable. <BR>
47
* - The list of the enabled and disabled method exit requests. <BR>
48
* - This list is changes as requests are added and deleted. <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_EVENT_THREAD <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. <BR>
66
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
67
* - The debuggee prepares the check case 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 checking up on assertions. <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 methexitreq002 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 methexitreq002().runThis(argv, out);
91
92
if (exitCode != PASSED) {
93
System.out.println("TEST FAILED");
94
}
95
return testExitCode;
96
}
97
// ************************************************ test parameters
98
99
private String debuggeeName =
100
"nsk.jdi.EventRequestManager.methodExitRequests.methexitreq002a";
101
102
//====================================================== test program
103
104
private int runThis (String argv[], PrintStream out) {
105
106
argsHandler = new ArgumentHandler(argv);
107
logHandler = new Log(out, argsHandler);
108
Binder binder = new Binder(argsHandler, logHandler);
109
110
waitTime = argsHandler.getWaitTime() * 60000;
111
112
try {
113
log2("launching a debuggee :");
114
log2(" " + debuggeeName);
115
if (argsHandler.verbose()) {
116
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
117
} else {
118
debuggee = binder.bindToDebugee(debuggeeName);
119
}
120
if (debuggee == null) {
121
log3("ERROR: no debuggee launched");
122
return FAILED;
123
}
124
log2("debuggee launched");
125
} catch ( Exception e ) {
126
log3("ERROR: Exception : " + e);
127
log2(" test cancelled");
128
return FAILED;
129
}
130
131
debuggee.redirectOutput(logHandler);
132
133
vm = debuggee.VM();
134
135
eventQueue = vm.eventQueue();
136
if (eventQueue == null) {
137
log3("ERROR: eventQueue == null : TEST ABORTED");
138
vm.exit(PASS_BASE);
139
return FAILED;
140
}
141
142
log2("invocation of the method runTest()");
143
switch (runTest()) {
144
145
case 0 : log2("test phase has finished normally");
146
log2(" waiting for the debuggee to finish ...");
147
debuggee.waitFor();
148
149
log2("......getting the debuggee's exit status");
150
int status = debuggee.getStatus();
151
if (status != PASS_BASE) {
152
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
153
status + " != PASS_BASE");
154
testExitCode = FAILED;
155
} else {
156
log2("......debuggee returned expected exit status: " +
157
status + " == PASS_BASE");
158
}
159
break;
160
161
default : log3("ERROR: runTest() returned unexpected value");
162
163
case 1 : log3("test phase has not finished normally: debuggee is still alive");
164
log2("......forcing: vm.exit();");
165
testExitCode = FAILED;
166
try {
167
vm.exit(PASS_BASE);
168
} catch ( Exception e ) {
169
log3("ERROR: Exception : " + e);
170
}
171
break;
172
173
case 2 : log3("test cancelled due to VMDisconnectedException");
174
log2("......trying: vm.process().destroy();");
175
testExitCode = FAILED;
176
try {
177
Process vmProcess = vm.process();
178
if (vmProcess != null) {
179
vmProcess.destroy();
180
}
181
} catch ( Exception e ) {
182
log3("ERROR: Exception : " + e);
183
}
184
break;
185
}
186
187
return testExitCode;
188
}
189
190
191
/*
192
* Return value: 0 - normal end of the test
193
* 1 - ubnormal end of the test
194
* 2 - VMDisconnectedException while test phase
195
*/
196
197
private int runTest() {
198
199
try {
200
testRun();
201
202
log2("waiting for VMDeathEvent");
203
getEventSet();
204
if (eventIterator.nextEvent() instanceof VMDeathEvent)
205
return 0;
206
207
log3("ERROR: last event is not the VMDeathEvent");
208
return 1;
209
} catch ( VMDisconnectedException e ) {
210
log3("ERROR: VMDisconnectedException : " + e);
211
return 2;
212
} catch ( Exception e ) {
213
log3("ERROR: Exception : " + e);
214
return 1;
215
}
216
217
}
218
219
private void testRun()
220
throws JDITestRuntimeException, Exception {
221
222
eventRManager = vm.eventRequestManager();
223
224
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
225
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
226
cpRequest.addClassFilter(debuggeeName);
227
228
cpRequest.enable();
229
vm.resume();
230
getEventSet();
231
cpRequest.disable();
232
233
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
234
debuggeeClass = event.referenceType();
235
236
if (!debuggeeClass.name().equals(debuggeeName))
237
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
238
239
log2(" received: ClassPrepareEvent for debuggeeClass");
240
241
String bPointMethod = "methodForCommunication";
242
String lineForComm = "lineForComm";
243
244
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
245
246
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
247
debuggeeClass,
248
bPointMethod, lineForComm, "zero");
249
bpRequest.enable();
250
251
//------------------------------------------------------ testing section
252
253
List requests = null;
254
ListIterator li = null;
255
256
MethodExitRequest request = null;
257
MethodExitRequest meRequests[] = { null, null, null, null, null,
258
null, null, null, null, null };
259
int listSize;
260
int flag;
261
262
263
log1(" TESTING BEGINS");
264
265
for (int i = 0; ; i++) {
266
267
vm.resume();
268
breakpointForCommunication();
269
270
int instruction = ((IntegerValue)
271
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
272
273
if (instruction == 0) {
274
vm.resume();
275
break;
276
}
277
278
log1(":::::: case: # " + i);
279
280
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
281
282
log2("......creating MethodExitRequests");
283
for (int i1 = 0; i1 < meRequests.length; i1++) {
284
meRequests[i1] = eventRManager.createMethodExitRequest();
285
meRequests[i1].putProperty("number", String.valueOf(i1));
286
287
log2("......checking up on returned List after creating new MethodExitRequest");
288
requests = eventRManager.methodExitRequests();
289
listSize = requests.size();
290
if ( listSize != (i1 + 1) ) {
291
testExitCode = FAILED;
292
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + (i1 + 1));
293
}
294
flag = 0;
295
li = requests.listIterator();
296
while (li.hasNext()) {
297
request = (MethodExitRequest) li.next();
298
if ( !request.isEnabled() ) {
299
flag++;
300
if (flag > 1) {
301
testExitCode = FAILED;
302
log3("ERROR: # of disabled requests > 1 : " + flag);
303
}
304
if ( !request.getProperty("number").equals(String.valueOf(i1)) ) {
305
testExitCode = FAILED;
306
log3("ERROR: in the List, disabled is request expected to be enabled : # == " + i1);
307
}
308
} else {
309
if ( request.getProperty("number").equals(String.valueOf(i1)) ) {
310
testExitCode = FAILED;
311
log3("ERROR: in the List, enabled is newly created disabled request : # == " + i1);
312
}
313
}
314
}
315
316
log2(" enabling created MethodExitRequest");
317
meRequests[i1].enable();
318
requests = eventRManager.methodExitRequests();
319
listSize = requests.size();
320
if ( listSize != (i1 + 1) ) {
321
testExitCode = FAILED;
322
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + (i1 + 1));
323
}
324
325
li = requests.listIterator();
326
while (li.hasNext()) {
327
request = (MethodExitRequest) li.next();
328
if ( !request.isEnabled() ) {
329
testExitCode = FAILED;
330
log3("ERROR: returned List contains disabled request : " + request);
331
}
332
}
333
334
log2(" removing item from the List; UnsupportedOperationException is expected");
335
try {
336
requests.remove(i1);
337
testExitCode = FAILED;
338
log3("ERROR: NO exception");
339
} catch ( UnsupportedOperationException e ) {
340
log2(" UnsupportedOperationException ");
341
}
342
}
343
344
log2("......deleting MethodExitRequests");
345
for (int i2 = meRequests.length -1; i2 >= 0; i2--) {
346
eventRManager.deleteEventRequest(meRequests[i2]);
347
requests = eventRManager.methodExitRequests();
348
listSize = requests.size();
349
if ( listSize != i2 ) {
350
testExitCode = FAILED;
351
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + i2);
352
}
353
log2(" removing item from the List; UnsupportedOperationException is expected");
354
try {
355
requests.remove(i2);
356
testExitCode = FAILED;
357
log3("ERROR: NO exception");
358
} catch ( UnsupportedOperationException e ) {
359
log2(" UnsupportedOperationException ");
360
}
361
}
362
363
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
}
365
log1(" TESTING ENDS");
366
return;
367
}
368
369
protected void breakpointForCommunication()
370
throws JDITestRuntimeException {
371
log2("breakpointForCommunication");
372
373
do {
374
getEventSet();
375
376
Event event = eventIterator.nextEvent();
377
if (event instanceof BreakpointEvent)
378
return;
379
380
log2(" received: " + event);
381
382
if (EventFilters.filtered(event, debuggeeName)) {
383
eventSet.resume();
384
}
385
else {
386
break;
387
}
388
} while (true);
389
390
throw new JDITestRuntimeException("** event IS NOT a breakpoint **");
391
}
392
393
}
394
395