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