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