Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventQueue/remove/remove004.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.EventQueue.remove;
25
26
import jdk.test.lib.Utils;
27
import nsk.share.*;
28
import nsk.share.jpda.*;
29
import nsk.share.jdi.*;
30
31
import com.sun.jdi.*;
32
import com.sun.jdi.event.*;
33
import com.sun.jdi.request.*;
34
35
import java.util.*;
36
import java.io.*;
37
38
/**
39
* The test for the implementation of an object of the type <BR>
40
* EventQueue. <BR>
41
* <BR>
42
* The test checks up that results of the method <BR>
43
* <code>com.sun.jdi.EventQueue.remove()</code> <BR>
44
* complies with its spec. <BR>
45
* <BR>
46
* Since method's assertion is <BR>
47
* "Waits forever for the next available event." <BR>
48
* in the condition of a limited time for testing, <BR>
49
* the test case limits time for waiting for the next event <BR>
50
* to the standard value of WAITTIME set up in the testbase_nsk.<BR>
51
* <BR>
52
* The test works as follows. <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 <BR>
57
* for debuggee's ClassPrepareEvent with SUSPEND_EVENT_THREAD, <BR>
58
* resumes the VM, and waits for the event within the predefined<BR>
59
* time interval. 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
* the debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
63
* The debuggee prepares new check and invokes the methodForCommunication<BR>
64
* to be suspended and to inform the debugger with the event. <BR>
65
* Upon getting the BreakpointEvent, the debugger performs the check. <BR>
66
* At the end, the debuggee changes the value of the "instruction" <BR>
67
* to inform the debugger of checks finished, and both end. <BR>
68
* <BR>
69
* The check includes two steps. <BR>
70
* In first one, second thread waits for any incoming event from the <BR>
71
* debugger which is sleeping for some time; hence, <BR>
72
* no events are expected to be received at the debugger end. <BR>
73
* In second, second thread is interrupted, and the debugger waits for <BR>
74
* a breakpoint event after the debuggee finishes sleeping. <BR>
75
*/
76
77
public class remove004 extends JDIBase {
78
79
public static void main (String argv[]) {
80
81
int result = run(argv, System.out);
82
83
System.exit(result + PASS_BASE);
84
}
85
86
public static int run (String argv[], PrintStream out) {
87
88
int exitCode = new remove004().runThis(argv, out);
89
90
if (exitCode != PASSED) {
91
System.out.println("TEST FAILED");
92
}
93
return testExitCode;
94
}
95
96
// ************************************************ test parameters
97
98
private String debuggeeName =
99
"nsk.jdi.EventQueue.remove.remove004a";
100
101
//====================================================== test program
102
103
static Value trueValue;
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 = Utils.adjustTimeout(argsHandler.getWaitTime() * 1000);
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
trueValue = debuggeeClass.getValue(debuggeeClass.fieldByName("BOOLEAN_TRUE_VALUE"));
241
242
log2(" received: ClassPrepareEvent for debuggeeClass");
243
244
String bPointMethod = "methodForCommunication";
245
String lineForComm = "lineForComm";
246
BreakpointRequest bpRequest;
247
248
try {
249
bpRequest = settingBreakpoint(debuggee.threadByNameOrThrow("main"),
250
debuggeeClass,
251
bPointMethod, lineForComm, "zero");
252
} catch ( Exception e ) {
253
throw e;
254
}
255
bpRequest.enable();
256
257
//------------------------------------------------------ testing section
258
259
log1(" TESTING BEGINS");
260
vm.resume();
261
262
for (int i = 0; ; i++) {
263
264
breakpointForCommunication();
265
266
int instruction = ((IntegerValue)
267
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
268
269
if (instruction == 0) {
270
vm.resume();
271
break;
272
}
273
274
log1(" new check: # " + i);
275
276
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
277
278
vm.resume();
279
280
Threadremove004 thread2 = new Threadremove004("thread2");
281
log2(" thread2 is created");
282
283
synchronized (lockingObject) {
284
synchronized (waitnotifyObj) {
285
log2(" before: thread2.start()");
286
thread2.start();
287
288
try {
289
log2(" before: waitnotifyObj.wait();");
290
waitnotifyObj.wait();
291
} catch ( Exception e) {
292
log3("ERROR: Exception : " + e );
293
testExitCode = FAILED;
294
throw new JDITestRuntimeException("** Exception while waiting: notify() **");
295
}
296
}
297
}
298
log2("mainThread is out of: synchronized (lockingObject)");
299
300
Object waitObj = new Object();
301
302
synchronized (waitObj) {
303
waitObj.wait(waitTime);
304
if (!thread2.isAlive()) {
305
log3("ERROR: thread2 is not alive");
306
testExitCode = FAILED;
307
break;
308
}
309
310
thread2.interrupt();
311
312
for (int i2 = 0; i2 < waitTime; ) {
313
waitObj.wait(1000);
314
if (!thread2.isAlive()) {
315
break;
316
}
317
i2 += 1000;
318
}
319
if (thread2.isAlive()) {
320
log3("ERROR: thread2 is still alive");
321
testExitCode = FAILED;
322
break;
323
}
324
}
325
326
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327
}
328
log1(" TESTING ENDS");
329
return;
330
}
331
332
// ============================== test's additional methods
333
334
335
public static Object waitnotifyObj = new Object();
336
public static Object lockingObject = new Object();
337
338
class Threadremove004 extends Thread {
339
340
public Threadremove004(String threadName) {
341
super(threadName);
342
}
343
344
public void run() {
345
log2("-----t2: method 'run' enter");
346
synchronized (waitnotifyObj) {
347
log2("-----t2: entered into block: synchronized (waitnotifyObj)");
348
waitnotifyObj.notify();
349
}
350
log2("-----t2: exited from block: synchronized (waitnotifyObj)");
351
synchronized (lockingObject) {
352
log2("-----t2: entered into block: synchronized (lockingObject)");
353
}
354
log2("-----t2: exited from block: synchronized (lockingObject)");
355
356
try {
357
log2("-----t2: eventSet = eventQueue.remove(); expects: InterruptedException");
358
eventSet = eventQueue.remove();
359
throw new JDITestRuntimeException("** return from eventQueue.remove(); **");
360
} catch (InterruptedException e1) {
361
log2("-----t2: InterruptedException");
362
// Signal to debuggee to stop sleeping
363
try {
364
((ClassType) debuggeeClass).setValue(debuggeeClass.fieldByName("stopSleeping"),
365
trueValue);
366
} catch (InvalidTypeException | ClassNotLoadedException e) {
367
log3("ERROR: -----t2: Exception : " + e);
368
testExitCode = FAILED;
369
}
370
} catch (Exception e) {
371
log3("ERROR: -----t2: Exception : " + e);
372
testExitCode = FAILED;
373
}
374
375
log2("-----t2: method 'run' exit");
376
return;
377
}
378
}
379
}
380
381