Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionRequest/exception/exception001.java
41162 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.ExceptionRequest.exception;
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
* ExceptionRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.ExceptionRequest.exception()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks if a boolean value, an argument of the method <BR>
46
* EventRequestManager.createExceptionRequest(), <BR>
47
* is equal to one returned by the method <BR>
48
* ExceptionRequest.exception() <BR>
49
* The cases to test include a ReferenceType <BR>
50
* mirroring NullPointerException, and null. <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check the assertion, <BR>
67
* the debugger and the debuggee perform the following. <BR>
68
* - The debugger <BR>
69
* - gets ReferenceType value mirroring NullPointerException, <BR>
70
* - sets up two ExceptionRequests with the ReferenceType and null <BR>
71
* values of the exception arguments, <BR>
72
* - gets the values of the Request with the method <BR>
73
* StepRequest.exception(), and <BR>
74
* - compares the values. <BR>
75
* <BR>
76
* In third phase, at the end of the test, the debuggee changes <BR>
77
* the value of the "instruction" which the debugger and debuggee <BR>
78
* use to inform each other of needed actions, and both end. <BR>
79
* <BR>
80
*/
81
82
public class exception001 extends JDIBase {
83
84
public static void main (String argv[]) {
85
86
int result = run(argv, System.out);
87
88
System.exit(result + PASS_BASE);
89
}
90
91
public static int run (String argv[], PrintStream out) {
92
93
int exitCode = new exception001().runThis(argv, out);
94
95
if (exitCode != PASSED) {
96
System.out.println("TEST FAILED");
97
}
98
return testExitCode;
99
}
100
101
// ************************************************ test parameters
102
103
private String debuggeeName =
104
"nsk.jdi.ExceptionRequest.exception.exception001a";
105
106
//====================================================== test program
107
108
private int runThis (String argv[], PrintStream out) {
109
110
argsHandler = new ArgumentHandler(argv);
111
logHandler = new Log(out, argsHandler);
112
Binder binder = new Binder(argsHandler, logHandler);
113
114
waitTime = argsHandler.getWaitTime() * 60000;
115
116
try {
117
log2("launching a debuggee :");
118
log2(" " + debuggeeName);
119
if (argsHandler.verbose()) {
120
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
121
} else {
122
debuggee = binder.bindToDebugee(debuggeeName);
123
}
124
if (debuggee == null) {
125
log3("ERROR: no debuggee launched");
126
return FAILED;
127
}
128
log2("debuggee launched");
129
} catch ( Exception e ) {
130
log3("ERROR: Exception : " + e);
131
log2(" test cancelled");
132
return FAILED;
133
}
134
135
debuggee.redirectOutput(logHandler);
136
137
vm = debuggee.VM();
138
139
eventQueue = vm.eventQueue();
140
if (eventQueue == null) {
141
log3("ERROR: eventQueue == null : TEST ABORTED");
142
vm.exit(PASS_BASE);
143
return FAILED;
144
}
145
146
log2("invocation of the method runTest()");
147
switch (runTest()) {
148
149
case 0 : log2("test phase has finished normally");
150
log2(" waiting for the debuggee to finish ...");
151
debuggee.waitFor();
152
153
log2("......getting the debuggee's exit status");
154
int status = debuggee.getStatus();
155
if (status != PASS_BASE) {
156
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
157
status + " != PASS_BASE");
158
testExitCode = FAILED;
159
} else {
160
log2("......debuggee returned expected exit status: " +
161
status + " == PASS_BASE");
162
}
163
break;
164
165
default : log3("ERROR: runTest() returned unexpected value");
166
167
case 1 : log3("test phase has not finished normally: debuggee is still alive");
168
log2("......forcing: vm.exit();");
169
testExitCode = FAILED;
170
try {
171
vm.exit(PASS_BASE);
172
} catch ( Exception e ) {
173
log3("ERROR: Exception : " + e);
174
}
175
break;
176
177
case 2 : log3("test cancelled due to VMDisconnectedException");
178
log2("......trying: vm.process().destroy();");
179
testExitCode = FAILED;
180
try {
181
Process vmProcess = vm.process();
182
if (vmProcess != null) {
183
vmProcess.destroy();
184
}
185
} catch ( Exception e ) {
186
log3("ERROR: Exception : " + e);
187
}
188
break;
189
}
190
191
return testExitCode;
192
}
193
194
195
/*
196
* Return value: 0 - normal end of the test
197
* 1 - ubnormal end of the test
198
* 2 - VMDisconnectedException while test phase
199
*/
200
201
private int runTest() {
202
203
try {
204
testRun();
205
206
log2("waiting for VMDeathEvent");
207
getEventSet();
208
if (eventIterator.nextEvent() instanceof VMDeathEvent)
209
return 0;
210
211
log3("ERROR: last event is not the VMDeathEvent");
212
return 1;
213
} catch ( VMDisconnectedException e ) {
214
log3("ERROR: VMDisconnectedException : " + e);
215
return 2;
216
} catch ( Exception e ) {
217
log3("ERROR: Exception : " + e);
218
return 1;
219
}
220
221
}
222
223
private void testRun()
224
throws JDITestRuntimeException, Exception {
225
226
eventRManager = vm.eventRequestManager();
227
228
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
229
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
230
cpRequest.addClassFilter(debuggeeName);
231
232
cpRequest.enable();
233
vm.resume();
234
getEventSet();
235
cpRequest.disable();
236
237
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
238
debuggeeClass = event.referenceType();
239
240
if (!debuggeeClass.name().equals(debuggeeName))
241
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
242
243
log2(" received: ClassPrepareEvent for debuggeeClass");
244
245
String bPointMethod = "methodForCommunication";
246
String lineForComm = "lineForComm";
247
248
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
249
250
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
251
debuggeeClass,
252
bPointMethod, lineForComm, "zero");
253
bpRequest.enable();
254
vm.resume();
255
256
//------------------------------------------------------ testing section
257
258
log1(" TESTING BEGINS");
259
260
EventRequest eventRequest1 = null;
261
EventRequest eventRequest2 = null;
262
263
String fieldName = "obj";
264
Value value = null;
265
266
ReferenceType refObject = null;
267
ReferenceType exception = null;
268
269
for (int i = 0; ; i++) {
270
271
breakpointForCommunication();
272
273
int instruction = ((IntegerValue)
274
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
275
276
if (instruction == 0) {
277
vm.resume();
278
break;
279
}
280
281
log1(":::::: case: # " + i);
282
283
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
284
285
switch (i) {
286
287
case 0:
288
log2("......vm.resume();");
289
vm.resume();
290
291
log2("......getting: refObject = debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName));");
292
value = debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName));
293
log2(" getting: refObject = (ReferenceType) value.type();");
294
refObject = (ReferenceType) value.type();
295
296
log2("......setting up: eventRequest1 = setting25ExceptionRequest(refObject);");
297
eventRequest1 = setting25ExceptionRequest(refObject);
298
299
log2("......getting: exception = ((ExceptionRequest) eventRequest1).exception();");
300
exception = ((ExceptionRequest) eventRequest1).exception();
301
302
log2(" comparing ReferenceType objects");
303
if ( !exception.equals(refObject) ) {
304
testExitCode = FAILED;
305
log3("ERROR: objects are not equal : " + exception);
306
}
307
308
log2("......setting up: eventRequest2 = setting25ExceptionRequest(null);");
309
eventRequest2 = setting25ExceptionRequest(null);
310
311
log2("......getting: exception = ((ExceptionRequest) eventRequest2).exception();");
312
exception = ((ExceptionRequest) eventRequest2).exception();
313
314
log2(" comparing to null");
315
if ( exception != null ) {
316
testExitCode = FAILED;
317
log3("ERROR: exception is not the null : " + exception);
318
}
319
320
break;
321
322
default:
323
throw new JDITestRuntimeException("** default case 2 **");
324
}
325
326
327
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328
}
329
log1(" TESTING ENDS");
330
return;
331
}
332
333
// ============================== test's additional methods
334
335
private ExceptionRequest setting25ExceptionRequest ( ReferenceType refType )
336
throws JDITestRuntimeException {
337
try {
338
log2("......setting up ExceptionRequest:");
339
340
ExceptionRequest
341
excr = eventRManager.createExceptionRequest(refType, true, true);
342
343
log2(" ExceptionRequest has been set up");
344
return excr;
345
} catch ( Exception e ) {
346
log3("ERROR: ATTENTION: Exception within settingExceptionRequest() : " + e);
347
log3(" ExceptionRequest HAS NOT BEEN SET UP");
348
throw new JDITestRuntimeException("** FAILURE to set up ExceptionRequest **");
349
}
350
}
351
352
}
353
354