Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createExceptionRequest/crexreq009.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.EventRequestManager.createExceptionRequest;
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
* EventRequestManager. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequestManager.createExceptionRequest()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - Creates a new disabled ExceptionRequest. <BR>
47
* - A specific exception type and its subclasses <BR>
48
* can be selected for exception events. <BR>
49
* - Caught exceptions, uncaught exceptions, or both can be selected. <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 resumes the debuggee and waits for the BreakpointEvent.<BR>
68
* - The debuggee prepares new testcase and invokes <BR>
69
* the methodForCommunication to be suspended and <BR>
70
* to inform the debugger with the event. <BR>
71
* - Upon getting the BreakpointEvent, <BR>
72
* the debugger performs the checks required. <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 crexreq009 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 crexreq009().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.EventRequestManager.createExceptionRequest.crexreq009a";
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
String fieldName = "testField";
256
257
ExceptionRequest exRequest = null;
258
259
260
log1(" TESTING BEGINS");
261
262
for (int i = 0; ; i++) {
263
264
vm.resume();
265
breakpointForCommunication();
266
267
int instruction = ((IntegerValue)
268
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
269
270
if (instruction == 0) {
271
vm.resume();
272
break;
273
}
274
275
log1(":::::: case: # " + i);
276
277
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
278
279
ReferenceType refType = (ReferenceType)
280
debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName)).type();
281
282
log2("......creating: exRequest = eventRManager.createExceptionRequest(refType, false, true);");
283
exRequest = eventRManager.createExceptionRequest(refType, false, true);
284
log2(" check on if request is disabled");
285
if (exRequest.isEnabled()) {
286
log3("ERROR: request is enabled");
287
testExitCode = FAILED;
288
}
289
290
log2("......creating: exRequest = eventRManager.createExceptionRequest(null, true, false);");
291
exRequest = eventRManager.createExceptionRequest(null, true, false);
292
log2(" check on if request is disabled");
293
if (exRequest.isEnabled()) {
294
log3("ERROR: request is enabled");
295
testExitCode = FAILED;
296
}
297
298
log2("......creating: exRequest = eventRManager.createExceptionRequest(null, true, true);");
299
exRequest = eventRManager.createExceptionRequest(null, true, true);
300
log2(" check on if request is disabled");
301
if (exRequest.isEnabled()) {
302
log3("ERROR: request is enabled");
303
testExitCode = FAILED;
304
}
305
306
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307
}
308
log1(" TESTING ENDS");
309
return;
310
}
311
312
}
313
314