Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareEvent/thread/thread001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2018, 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.ClassPrepareEvent.thread;
25
26
import com.sun.jdi.*;
27
import com.sun.jdi.event.*;
28
import com.sun.jdi.request.*;
29
30
import java.io.*;
31
import java.util.Iterator;
32
33
import nsk.share.*;
34
import nsk.share.jpda.*;
35
import nsk.share.jdi.*;
36
37
38
// This class is the debugger in the test
39
40
public class thread001 {
41
static final int PASSED = 0;
42
static final int FAILED = 2;
43
static final int JCK_STATUS_BASE = 95;
44
45
static final int TIMEOUT_DELTA = 1000; // milliseconds
46
47
static final String COMMAND_READY = "ready";
48
static final String COMMAND_QUIT = "quit";
49
static final String COMMAND_RUN = "run";
50
static final String COMMAND_DONE = "done";
51
static final String COMMAND_ERROR = "error";
52
53
static final String PACKAGE_NAME = "nsk.jdi.ClassPrepareEvent.thread";
54
static final String DEBUGEE_NAME = PACKAGE_NAME + ".thread001a";
55
56
static private Debugee debuggee;
57
static private VirtualMachine vm;
58
static private IOPipe pipe;
59
static private Log log;
60
static private ArgumentHandler argHandler;
61
62
static private ClassPrepareRequest checkedRequest;
63
static private ThreadReference eventThread;
64
65
static private String checkedThreads[][] = {
66
{"main", "thread001a", "0"},
67
{"main", "InnerThread", "0"},
68
{"innerThread", "OuterThread", "0"},
69
{"innerThread", "ClassForInnerThread", "0"},
70
{"outerThread", "ClassForOuterThread", "0"}
71
};
72
73
static private int threadStatus;
74
75
static private volatile boolean testFailed, eventsReceived, threadsStarted;
76
static private int eventTimeout;
77
78
public static void main (String args[]) {
79
System.exit(run(args, System.out) + JCK_STATUS_BASE);
80
}
81
82
public static int run(final String args[], final PrintStream out) {
83
String command;
84
85
testFailed = false;
86
eventsReceived = false;
87
threadsStarted = false;
88
89
argHandler = new ArgumentHandler(args);
90
log = new Log(out, argHandler);
91
eventTimeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
92
93
// launch debugee
94
Binder binder = new Binder(argHandler, log);
95
log.display("Connecting to debuggee");
96
debuggee = binder.bindToDebugee(DEBUGEE_NAME);
97
debuggee.redirectStderr(log, "refType001a >");
98
pipe = debuggee.createIOPipe();
99
vm = debuggee.VM();
100
101
// create request and wait for expected events
102
try {
103
104
// create request for ClassPrepareEvent
105
log.display("Creating request for ClassPrepareEvent");
106
EventRequestManager erManager = debuggee.VM().eventRequestManager();
107
if ((checkedRequest = erManager.createClassPrepareRequest()) == null) {
108
throw new Failure("TEST FAILED: unable to create ClassPrepareRequest");
109
}
110
log.display("ClassPrepareRequest is created");
111
112
checkedRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
113
// checkedRequest.enable();
114
115
switch (checkedRequest.suspendPolicy()) {
116
case EventRequest.SUSPEND_NONE:
117
log.display("Suspend policy is SUSPEND_NONE");
118
break;
119
case EventRequest.SUSPEND_ALL:
120
log.display("Suspend policy is SUSPEND_ALL");
121
break;
122
case EventRequest.SUSPEND_EVENT_THREAD:
123
log.display("Suspend policy is SUSPEND_EVENT_THREAD");
124
break;
125
default:
126
throw new Failure("TEST BUG: Unknown suspend policy: " + checkedRequest.suspendPolicy());
127
}
128
129
// define separate thread to handle received events
130
class EventHandler extends Thread {
131
132
public void run() {
133
134
// handle events until all threads started and all expected events received
135
while (!(threadsStarted && eventsReceived)) {
136
EventSet eventSet = null;
137
try {
138
eventSet = vm.eventQueue().remove(TIMEOUT_DELTA);
139
} catch (InterruptedException e) {
140
throw new Failure("Unexpected InterruptedException while receiving events: " + e);
141
}
142
143
if (eventSet == null) {
144
continue;
145
}
146
147
// handle each event
148
EventIterator eventIterator = eventSet.eventIterator();
149
while (eventIterator.hasNext()) {
150
Event event = eventIterator.nextEvent();
151
// log.display("\nEvent received:\n " + event);
152
153
// handle ClassPrepareEvent
154
if (event instanceof ClassPrepareEvent) {
155
ClassPrepareEvent castedEvent = (ClassPrepareEvent)event;
156
log.display("\nClassPrepareEvent received:\n " + event);
157
158
EventRequest eventRequest = castedEvent.request();
159
if (!(checkedRequest.equals(eventRequest))) {
160
log.complain("FAILURE 1: eventRequest is not equal to checked request");
161
testFailed = true;
162
}
163
164
VirtualMachine eventMachine = castedEvent.virtualMachine();
165
if (!(vm.equals(eventMachine))) {
166
log.complain("FAILURE 2: eventVirtualMachine is not equal to checked vm");
167
testFailed = true;
168
}
169
170
// test method ClassPrepareEvent.thread()
171
eventThread = castedEvent.thread();
172
String threadName = eventThread.name();
173
if (eventThread == null) {
174
log.complain("FAILURE 3: ClassPrepareEvent.thread() returns null");
175
testFailed = true;
176
} else if ((threadName == null) || (threadName.equals(""))) {
177
log.complain("FAILURE 4: thread reference has invalid empty name");
178
testFailed = true;
179
}
180
181
ReferenceType refType = castedEvent.referenceType();
182
if (refType == null) {
183
log.complain("FAILURE 5: ClassPrepareEvent.referenceType() returns null");
184
testFailed = true;
185
} else {
186
187
String className = refType.name();
188
if ( className.startsWith(PACKAGE_NAME)) {
189
190
log.display("Class " + className + " prepared in thread " + threadName);
191
192
// Check that thread is in VirtualMachine.allThreads() list
193
boolean found = false;
194
Iterator threadsList = vm.allThreads().iterator();
195
while (!found && threadsList.hasNext()) {
196
found = eventThread.equals((ThreadReference)threadsList.next());
197
}
198
if (!found) {
199
log.complain("FAILURE 6: " + threadName + " is not in debuggee's allThreads() list");
200
testFailed = true;
201
}
202
203
// Check that all expected debuggee's thread create ClassPrepareEvent only once
204
for (int i = 0; i < checkedThreads.length; i++) {
205
if (threadName.equals(checkedThreads[i][0]) && className.endsWith(checkedThreads[i][1])) {
206
if (checkedThreads[i][2] == "0") {
207
checkedThreads[i][2] = "1";
208
} else {
209
log.complain("FAILURE 7: ClassPrepareEvent for " + threadName + " is received more that once");
210
testFailed = true;
211
}
212
}
213
}
214
215
// check that thread is correctly suspended
216
if (checkedRequest.suspendPolicy() == EventRequest.SUSPEND_ALL ||
217
checkedRequest.suspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD) {
218
219
if (eventThread.isSuspended()) {
220
log.display("Thread " + threadName + " is correctly suspended");
221
} else {
222
log.complain("FAILURE 7: Thread " + threadName + " is not suspended");
223
testFailed = true;
224
}
225
}
226
227
// Check that all expected ClassPrepareEvent are received
228
eventsReceived = true;
229
for (int i = 0; i < checkedThreads.length; i++) {
230
if (checkedThreads[i][2] == "0") {
231
eventsReceived = false;
232
}
233
}
234
}
235
}
236
}
237
238
// ignore each oter event
239
240
} // event handled
241
242
// log.display("Resuming event set");
243
eventSet.resume();
244
245
} // event set handled
246
247
log.display("eventHandler completed");
248
249
} // for run()
250
251
} // for EventHandler
252
253
EventHandler eventHandler = new EventHandler();
254
log.display("Starting eventHandler");
255
eventHandler.start();
256
257
// enable event request and resume debugee
258
log.display("Enabling ClassPrepareEvent request");
259
checkedRequest.enable();
260
261
log.display("Resuming debuggee");
262
debuggee.resume();
263
264
// wait for debugee started
265
log.display("Waiting for command: " + COMMAND_READY);
266
command = pipe.readln();
267
if (!command.equals(COMMAND_READY)) {
268
throw new Failure("TEST BUG: unexpected debuggee's command: " + command);
269
}
270
271
// force debugee to start another thread
272
log.display("Sending a command: " + COMMAND_RUN);
273
pipe.println(COMMAND_RUN);
274
275
// wait for debugee started requested thread
276
log.display("Waiting for command: " + COMMAND_DONE);
277
command = pipe.readln();
278
if (!command.equals(COMMAND_DONE)) {
279
log.complain("TEST BUG: unexpected debuggee's command: " + command);
280
testFailed = true;
281
}
282
283
// notify EventHandler that all threads started
284
threadsStarted = true;
285
286
// wait for all expected events received or timeout exceeds
287
try {
288
eventHandler.join(eventTimeout);
289
if (eventHandler.isAlive()) {
290
log.complain("FAILURE 20: Timeout for waiting event was exceeded");
291
eventHandler.interrupt();
292
testFailed = true;
293
}
294
} catch (InterruptedException e) {
295
log.complain("TEST INCOMPLETE: InterruptedException caught while waiting for eventHandler's death");
296
testFailed = true;
297
}
298
299
// check that all expected debuggee's threads created ClassPrepareEvent
300
for (int i = 0; i < checkedThreads.length; i++) {
301
if (checkedThreads[i][2].equals("0")) {
302
log.complain("FAILURE 9: ClassPrepareEvent for " + checkedThreads[i][1] +
303
" in thread " + checkedThreads[i][0] + " is not received");
304
testFailed = true;
305
}
306
}
307
308
} catch (Failure e) {
309
log.complain("TEST FAILURE: " + e.getMessage());
310
testFailed = true;
311
} catch (Exception e) {
312
log.complain("Unexpected exception: " + e);
313
e.printStackTrace(out);
314
testFailed = true;
315
} finally {
316
317
318
// disable event requests to prevent appearance of further events
319
if (checkedRequest != null && checkedRequest.isEnabled()) {
320
log.display("Disabling StepEvent request");
321
checkedRequest.disable();
322
}
323
324
// force debugee to exit
325
log.display("Sending command: " + COMMAND_QUIT);
326
pipe.println(COMMAND_QUIT);
327
328
// wait for debuggee exits and analize its exit code
329
log.display("Waiting for debuggee terminating");
330
int debuggeeStatus = debuggee.endDebugee();
331
if (debuggeeStatus == PASSED + JCK_STATUS_BASE) {
332
log.display("Debuggee PASSED with exit code: " + debuggeeStatus);
333
} else {
334
log.complain("Debuggee FAILED with exit code: " + debuggeeStatus);
335
testFailed = true;
336
}
337
}
338
339
// check test results
340
if (testFailed) {
341
log.complain("TEST FAILED");
342
return FAILED;
343
}
344
345
log.display("TEST PASSED");
346
return PASSED;
347
}
348
}
349
350