Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/catchLocation/location001.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.ExceptionEvent.catchLocation;
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
import java.util.List;
33
34
import nsk.share.*;
35
import nsk.share.jpda.*;
36
import nsk.share.jdi.*;
37
38
39
// This class is the debugger in the test
40
41
public class location001 {
42
static final int PASSED = 0;
43
static final int FAILED = 2;
44
static final int JCK_STATUS_BASE = 95;
45
46
// time interval to wait for events
47
static final int TIMEOUT_DELTA = 1000; // milliseconds
48
49
// synchronization commands
50
static final String COMMAND_READY = "ready";
51
static final String COMMAND_QUIT = "quit";
52
static final String COMMAND_GO = "go";
53
static final String COMMAND_DONE = "done";
54
static final String COMMAND_ERROR = "error";
55
56
// checked classes names
57
static final String DEBUGGEE_NAME = "nsk.jdi.ExceptionEvent.catchLocation.location001a";
58
59
static final String USER_EXCEPTION = DEBUGGEE_NAME + "Exception";
60
static final String USER_ERROR = DEBUGGEE_NAME + "Error";
61
static final String USER_THROWABLE = DEBUGGEE_NAME + "Throwable";
62
static final String JAVA_EXCEPTION = "java.lang.NumberFormatException";
63
static final String JAVA_ERROR = "java.lang.StackOverflowError";
64
65
// scaffold objects
66
static private Debugee debuggee;
67
static private VirtualMachine vm;
68
static private IOPipe pipe;
69
static private Log log;
70
static private ArgumentHandler argHandler;
71
static private EventSet eventSet;
72
73
// timeout for waiting events
74
static private long eventTimeout;
75
76
// mirrors for checked classes and threads in debuggee
77
static private ExceptionRequest checkedRequest;
78
static private ReferenceType checkedClass;
79
static private ThreadReference checkedThread;
80
81
static private ReferenceType userException;
82
static private ReferenceType userError;
83
static private ReferenceType userThrowable;
84
85
86
// results of receiving particular events
87
static private boolean userExceptionReceived;
88
static private boolean userErrorReceived;
89
static private boolean userThrowableReceived;
90
static private boolean javaExceptionReceived;
91
static private boolean javaErrorReceived;
92
93
// results of test execution
94
static private boolean eventsReceived;
95
static private boolean testFailed;
96
97
// flag for EventHandler thread
98
static private volatile boolean exceptionsThrown;
99
100
// execute test from command line
101
public static void main (String args[]) {
102
System.exit(run(args, System.out) + JCK_STATUS_BASE);
103
}
104
105
// execute test from JCK-compatible harness
106
public static int run(final String args[], final PrintStream out) {
107
108
testFailed = false;
109
userExceptionReceived = false;
110
userErrorReceived = false;
111
userThrowableReceived = false;
112
javaExceptionReceived = false;
113
javaErrorReceived = false;
114
eventsReceived = false;
115
116
argHandler = new ArgumentHandler(args);
117
log = new Log(out, argHandler);
118
eventTimeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
119
120
// launch debuggee
121
Binder binder = new Binder(argHandler, log);
122
log.display("Connecting to debuggee");
123
debuggee = binder.bindToDebugee(DEBUGGEE_NAME);
124
debuggee.redirectStderr(log, "location001a >");
125
126
// create synchronization channel with debuggee
127
pipe = debuggee.createIOPipe();
128
vm = debuggee.VM();
129
EventRequestManager erManager = vm.eventRequestManager();
130
131
// resume debuggee
132
log.display("Resuming debuggee");
133
debuggee.resume();
134
135
// catch exceptions while testing and finally quit debuggee
136
try {
137
138
// wait for debuggee started
139
log.display("Waiting for command: " + COMMAND_READY);
140
String command = pipe.readln();
141
if (!command.equals(COMMAND_READY)) {
142
throw new Failure("TEST BUG: unexpected debuggee's command: " + command);
143
}
144
145
// get mirrors of checked classes in debuggee
146
log.display("Getting loaded classes in debuggee");
147
if ((checkedClass = debuggee.classByName(DEBUGGEE_NAME)) == null) {
148
throw new Failure("TEST BUG: cannot find " + DEBUGGEE_NAME);
149
}
150
151
if ((userException = debuggee.classByName(USER_EXCEPTION)) == null) {
152
throw new Failure("TEST BUG: cannot find " + USER_EXCEPTION);
153
}
154
155
if ((userError = debuggee.classByName(USER_ERROR)) == null) {
156
throw new Failure("TEST BUG: cannot find " + USER_ERROR);
157
}
158
159
if ((userThrowable = debuggee.classByName(USER_THROWABLE)) == null) {
160
throw new Failure("TEST BUG: cannot find " + USER_THROWABLE);
161
}
162
163
// get mirror of main thread in debuggee
164
log.display("Getting reference to main thread");
165
Iterator threadIterator = vm.allThreads().iterator();
166
while (threadIterator.hasNext()) {
167
ThreadReference curThread = (ThreadReference) threadIterator.next();
168
if (curThread.name().equals("main")) {
169
checkedThread = curThread;
170
}
171
}
172
if (checkedThread == null) {
173
throw new Failure("TEST BUG: unable to find reference to main thread");
174
}
175
176
// create ExceptionRequest for all throwable classes (initially disabled)
177
log.display("Creating ExceptionRequest");
178
boolean notifyCaught = true;
179
boolean notifyUncaught = true;
180
if ((checkedRequest = erManager.createExceptionRequest(null, notifyCaught, notifyUncaught)) == null) {
181
throw new Failure("TEST BUG: unable to create ExceptionRequest");
182
}
183
184
// define separate thread for handling received events
185
class EventHandler extends Thread {
186
public void run() {
187
// handle events until all exceptions thrown and
188
// all expected events received
189
while (!(exceptionsThrown && eventsReceived)) {
190
eventSet = null;
191
try {
192
eventSet = vm.eventQueue().remove(TIMEOUT_DELTA);
193
} catch (InterruptedException e) {
194
log.complain("Unexpected InterruptedException while receiving event: " + e);
195
break;
196
}
197
198
if (eventSet == null) {
199
continue;
200
}
201
202
// handle each event from event set
203
EventIterator eventIterator = eventSet.eventIterator();
204
while (eventIterator.hasNext()) {
205
206
Event event = eventIterator.nextEvent();
207
log.display("\nEvent received:\n " + event);
208
209
if (EventFilters.filtered(event))
210
continue;
211
212
// handle ExceptionEvent
213
if (event instanceof ExceptionEvent) {
214
215
ExceptionEvent castedEvent = (ExceptionEvent)event;
216
ReferenceType eventRefType = castedEvent.exception().referenceType();
217
Location eventLocation = castedEvent.location();
218
Location eventCatchLocation = castedEvent.catchLocation();
219
220
if (eventRefType.equals(userException)) {
221
log.display("ExceptionEvent for " + USER_EXCEPTION + " is received");
222
userExceptionReceived = true;
223
if (eventLocation.lineNumber() != location001a.userExceptionLocation) {
224
log.complain("FAILURE 1: incorrect location for " + USER_EXCEPTION +
225
"\nexpected: " + location001a.userExceptionLocation + ", got: " + eventLocation.lineNumber());
226
testFailed = true;
227
}
228
if (eventCatchLocation.lineNumber() != location001a.userExceptionCatchLocation) {
229
log.complain("FAILURE 1: incorrect catchLocation for " + USER_EXCEPTION +
230
"\nexpected: " + location001a.userExceptionCatchLocation + ", got: " + eventCatchLocation.lineNumber());
231
testFailed = true;
232
}
233
if (!(eventLocation.declaringType().equals(checkedClass))) {
234
log.complain("FAILURE 2: catchLocation.declaringType() does not equal to debuggee class:");
235
testFailed = true;
236
log.complain(eventLocation.declaringType().name());
237
}
238
239
} else if (eventRefType.equals(userError)) {
240
log.display("ExceptionEvent for " + USER_ERROR + " is received");
241
userErrorReceived = true;
242
if (eventLocation.lineNumber() != location001a.userErrorLocation) {
243
log.complain("FAILURE 3: incorrect location for " + USER_ERROR +
244
"\nexpected: " + location001a.userErrorLocation + ", got: " + eventLocation.lineNumber());
245
testFailed = true;
246
}
247
if (eventCatchLocation.lineNumber() != location001a.userErrorCatchLocation) {
248
log.complain("FAILURE 3: incorrect catchLocation for " + USER_ERROR +
249
"\nexpected: " + location001a.userErrorCatchLocation + ", got: " + eventCatchLocation.lineNumber());
250
testFailed = true;
251
}
252
if (!(eventLocation.declaringType().equals(checkedClass))) {
253
log.complain("FAILURE 4: catchLocation.declaringType() does not equal to debuggee class:");
254
testFailed = true;
255
log.complain(eventLocation.declaringType().name());
256
}
257
258
} else if (eventRefType.equals(userThrowable)) {
259
log.display("ExceptionEvent for " + USER_THROWABLE + " is received");
260
userThrowableReceived = true;
261
if (eventLocation.lineNumber() != location001a.userThrowableLocation) {
262
log.complain("FAILURE 5: incorrect location for " + USER_THROWABLE +
263
"\nexpected: " + location001a.userThrowableLocation + ", got: " + eventLocation.lineNumber());
264
testFailed = true;
265
}
266
if (eventCatchLocation.lineNumber() != location001a.userThrowableCatchLocation) {
267
log.complain("FAILURE 5: incorrect catchLocation for " + USER_THROWABLE +
268
"\nexpected: " + location001a.userThrowableCatchLocation + ", got: " + eventCatchLocation.lineNumber());
269
testFailed = true;
270
}
271
if (!(eventLocation.declaringType().equals(checkedClass))) {
272
log.complain("FAILURE 6: catchLocation.declaringType() does not equal to debuggee class:");
273
testFailed = true;
274
log.complain(eventLocation.declaringType().name());
275
}
276
} else {
277
String eventTypeName = eventRefType.name();
278
if (eventTypeName.equals(JAVA_EXCEPTION)) {
279
log.display("ExceptionEvent for " + JAVA_EXCEPTION + " is received");
280
javaExceptionReceived = true;
281
if (eventCatchLocation.lineNumber() != location001a.javaExceptionCatchLocation) {
282
log.complain("FAILURE 7: incorrect catchLocation for " + JAVA_EXCEPTION +
283
"\nexpected: " + location001a.javaExceptionCatchLocation + ", got: " + eventCatchLocation.lineNumber());
284
testFailed = true;
285
}
286
287
} else if (eventTypeName.equals(JAVA_ERROR)) {
288
log.display("ExceptionEvent for " + JAVA_ERROR + " is received");
289
javaErrorReceived = true;
290
if (eventCatchLocation.lineNumber() != location001a.javaErrorCatchLocation) {
291
log.complain("FAILURE 8: incorrect catchLocation for " + JAVA_ERROR +
292
"\nexpected: " + location001a.javaErrorCatchLocation + ", got: " + eventCatchLocation.lineNumber());
293
testFailed = true;
294
}
295
}
296
}
297
}
298
299
// ignore each other events
300
301
} // end of event handling loop
302
303
log.display("Resuming event set");
304
eventSet.resume();
305
306
// check if all expected events received
307
eventsReceived = userExceptionReceived && userErrorReceived
308
&& userThrowableReceived && javaExceptionReceived
309
&& javaErrorReceived;
310
311
} // end of event set handling loop
312
313
log.display("eventHandler completed");
314
315
} // end of run()
316
317
} // end of EventHandler
318
319
// start EventHandler thread
320
EventHandler eventHandler = new EventHandler();
321
log.display("Starting eventHandler");
322
eventHandler.start();
323
324
// enable event request
325
log.display("Enabling ExceptionRequest");
326
checkedRequest.enable();
327
328
// force debuggee to throw exceptions and generate events
329
log.display("Sending command: " + COMMAND_GO);
330
pipe.println(COMMAND_GO);
331
332
log.display("");
333
334
// wait for debuggee completed test case
335
log.display("Waiting for command: " + COMMAND_DONE);
336
command = pipe.readln();
337
if (command.equals(COMMAND_ERROR)) {
338
throw new Failure("TEST BUG: Unable to thrown all exceptions in debuggee");
339
}
340
if (!command.equals(COMMAND_DONE)) {
341
throw new Failure("TEST BUG: unknown debuggee's command: " + command);
342
}
343
344
// notify EventHandler that all checked exceptions thrown in debuggee
345
exceptionsThrown = true;
346
347
log.display("");
348
349
// wait for all expected events received or timeout exceeds
350
log.display("Waiting for all expected events received");
351
try {
352
eventHandler.join(eventTimeout);
353
if (eventHandler.isAlive()) {
354
log.complain("FAILURE 20: Timeout for waiting event was exceeded");
355
eventHandler.interrupt();
356
testFailed = true;
357
}
358
} catch (InterruptedException e) {
359
log.complain("TEST INCOMPLETE: InterruptedException caught while waiting for eventHandler's death");
360
testFailed = true;
361
}
362
363
// complain if not all expected events received
364
if (!userExceptionReceived) {
365
log.complain("FAILURE 9: " + USER_EXCEPTION + " was not received received");
366
testFailed= true;
367
}
368
if (!userErrorReceived) {
369
log.complain("FAILURE 10: " + USER_ERROR + " was not received received");
370
testFailed= true;
371
}
372
if (!userThrowableReceived) {
373
log.complain("FAILURE 11: " + USER_THROWABLE + " was not received received");
374
testFailed= true;
375
}
376
if (!javaExceptionReceived) {
377
log.complain("FAILURE 12: " + JAVA_EXCEPTION + " was not received received");
378
testFailed= true;
379
}
380
if (!javaErrorReceived) {
381
log.complain("FAILURE 13: " + JAVA_ERROR + " was not received received");
382
testFailed= true;
383
}
384
385
// end testing
386
387
} catch (Failure e) {
388
log.complain("TEST FAILURE: " + e.getMessage());
389
testFailed = true;
390
} catch (Exception e) {
391
log.complain("Unexpected exception: " + e);
392
e.printStackTrace(out);
393
testFailed = true;
394
} finally {
395
396
log.display("");
397
398
// disable event request to prevent appearance of further events
399
if (checkedRequest != null && checkedRequest.isEnabled()) {
400
log.display("Disabling event request");
401
checkedRequest.disable();
402
}
403
404
// force debugee to exit
405
log.display("Sending command: " + COMMAND_QUIT);
406
pipe.println(COMMAND_QUIT);
407
408
// wait for debuggee exits and analize its exit code
409
log.display("Waiting for debuggee terminating");
410
int debuggeeStatus = debuggee.endDebugee();
411
if (debuggeeStatus == PASSED + JCK_STATUS_BASE) {
412
log.display("Debuggee PASSED with exit code: " + debuggeeStatus);
413
} else {
414
log.complain("Debuggee FAILED with exit code: " + debuggeeStatus);
415
testFailed = true;
416
}
417
}
418
419
// check test results
420
if (testFailed) {
421
log.complain("TEST FAILED");
422
return FAILED;
423
}
424
425
log.display("TEST PASSED");
426
return PASSED;
427
}
428
}
429
430