Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/exceptionRequests/excreq001.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.EventRequestManager.exceptionRequests;
25
26
import com.sun.jdi.ReferenceType;
27
import com.sun.jdi.VirtualMachine;
28
import com.sun.jdi.request.ExceptionRequest;
29
import com.sun.jdi.request.EventRequestManager;
30
import com.sun.jdi.VMDisconnectedException;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.AbsentInformationException;
33
import com.sun.jdi.ObjectCollectedException;
34
35
import java.util.List;
36
import java.io.*;
37
38
import nsk.share.*;
39
import nsk.share.jpda.*;
40
import nsk.share.jdi.*;
41
42
/**
43
* The test checks that the JDI method
44
* <code>com.sun.jdi.request.EventRequestManager.exceptionRequests()</code>
45
* properly returns all previously created ExceptionRequest objects for the
46
* different kinds of methods in two debuggee's classes when:
47
* <li>event requests are disabled
48
* <li>event requests are enabled<br>
49
* The debuggee loads several dummy classes which ReferenceType
50
* objects are obtained by the debugger for exercising
51
* the <code>exceptionRequests()</code>.<br>
52
* EventHandler was added as workaround for the bug 4430096.
53
* This prevents the target VM from potential hangup.
54
*/
55
public class excreq001 {
56
public static final int PASSED = 0;
57
public static final int FAILED = 2;
58
public static final int JCK_STATUS_BASE = 95;
59
static final String PACK =
60
"nsk.jdi.EventRequestManager.exceptionRequests";
61
static final String COMMAND_READY = "ready";
62
static final String COMMAND_QUIT = "quit";
63
64
static final int EXC_NUM = 4;
65
// list of debuggee's loaded classes
66
static final String DEBUGGEE_CLS[][] = {
67
{PACK + ".excreq001t", "excreq001t.java"},
68
{PACK + ".excreq001a", "excreq001a.java"},
69
{PACK + ".excreq001b", "excreq001b.java"},
70
{PACK + ".excreq001c", "excreq001c.java"},
71
};
72
// caught/uncaught exception notifications
73
static final boolean DEBUGGEE_NTFS[][] = {
74
{true, true},
75
{true, false},
76
{false, false},
77
{false, true}
78
};
79
80
private Log log;
81
private IOPipe pipe;
82
private Debugee debuggee;
83
private VirtualMachine vm;
84
private EventListener elThread;
85
private volatile int tot_res = PASSED;
86
87
public static void main (String argv[]) {
88
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
89
}
90
91
public static int run(String argv[], PrintStream out) {
92
return new excreq001().runIt(argv, out);
93
}
94
95
private int runIt(String args[], PrintStream out) {
96
ArgumentHandler argHandler = new ArgumentHandler(args);
97
log = new Log(out, argHandler);
98
Binder binder = new Binder(argHandler, log);
99
ReferenceType rType;
100
ExceptionRequest excRequest[] = new ExceptionRequest[EXC_NUM];
101
String cmd;
102
103
debuggee = binder.bindToDebugee(DEBUGGEE_CLS[0][0]);
104
pipe = debuggee.createIOPipe();
105
debuggee.redirectStderr(log, "excreq001t.err> ");
106
vm = debuggee.VM();
107
EventRequestManager erManager = vm.eventRequestManager();
108
debuggee.resume();
109
cmd = pipe.readln();
110
if (!cmd.equals(COMMAND_READY)) {
111
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
112
tot_res = FAILED;
113
return quitDebuggee();
114
}
115
116
for (int i=0; i<EXC_NUM; i++) {
117
if ((rType = debuggee.classByName(DEBUGGEE_CLS[i][0])) == null) {
118
log.complain("TEST BUG: cannot find " + DEBUGGEE_CLS[i][0]);
119
tot_res = FAILED;
120
return quitDebuggee();
121
}
122
try {
123
log.display("\nCreating ExceptionRequest for the ReferenceType:\n\tname="
124
+ rType.name() + "\n\tsource=" + rType.sourceName()
125
+ "\n\tnotifications of caught/uncaught exception: ("
126
+ DEBUGGEE_NTFS[i][0] + "," + DEBUGGEE_NTFS[i][1] + ")");
127
} catch(AbsentInformationException e) {
128
log.complain("TEST FAILURE: ReferenceType.sourceName(): " + e);
129
tot_res = FAILED;
130
return quitDebuggee();
131
} catch(ObjectCollectedException e) {
132
log.complain("TEST FAILURE: caught " + e);
133
tot_res = FAILED;
134
return quitDebuggee();
135
}
136
try {
137
excRequest[i] = erManager.createExceptionRequest(rType,
138
DEBUGGEE_NTFS[i][0],DEBUGGEE_NTFS[i][1]);
139
} catch (Exception e) {
140
log.complain("TEST FAILURE: EventRequestManager.createExceptionRequest(): "
141
+ e);
142
tot_res = FAILED;
143
return quitDebuggee();
144
}
145
}
146
elThread = new EventListener();
147
elThread.start();
148
149
// Check Exception requests when event requests are disabled
150
log.display("\n1) Getting ExceptionRequest objects with disabled event requests...");
151
checkRequests(erManager, 1);
152
153
// Check Exception requests when event requests are enabled
154
for (int i=0; i<EXC_NUM; i++) {
155
excRequest[i].enable();
156
}
157
log.display("\n2) Getting ExceptionRequest objects with enabled event requests...");
158
checkRequests(erManager, 2);
159
160
// Finish the test
161
for (int i=0; i<EXC_NUM; i++) {
162
excRequest[i].disable();
163
}
164
return quitDebuggee();
165
}
166
167
private void checkRequests(EventRequestManager erManager, int t_case) {
168
List reqL = erManager.exceptionRequests();
169
if (reqL.size() != EXC_NUM) {
170
log.complain("\nTEST CASE #" + t_case + " FAILED: found " + reqL.size()
171
+ " ExceptionRequest objects\n\texpected: " + EXC_NUM);
172
tot_res = FAILED;
173
return;
174
}
175
for (int i=0; i<EXC_NUM; i++) {
176
ExceptionRequest excReq =
177
(ExceptionRequest) reqL.get(i);
178
ReferenceType refT = excReq.exception();
179
boolean notFound = true;
180
try {
181
for (int j=0; j<EXC_NUM; j++) {
182
if (refT.name().equals(DEBUGGEE_CLS[j][0])) {
183
if (refT.sourceName().equals(DEBUGGEE_CLS[j][1]) &&
184
excReq.notifyCaught() == DEBUGGEE_NTFS[j][0] &&
185
excReq.notifyUncaught() == DEBUGGEE_NTFS[j][1]) {
186
log.display("\nFound an expected ExceptionRequest object for the ReferenceType:\n\tname="
187
+ DEBUGGEE_CLS[j][0] + "\n\tsource=" + DEBUGGEE_CLS[j][1]
188
+ "\n\tnotifications of caught/uncaught exceptions: (" + DEBUGGEE_NTFS[j][0] + ","
189
+ DEBUGGEE_NTFS[j][1] + ")");
190
} else {
191
log.complain("\nTEST CASE #" + t_case
192
+ " FAILED: found an ExceptionRequest object for the ReferenceType:\n\tname="
193
+ refT.name() + "\n\tsource=" + refT.sourceName()
194
+ "\n\tnotifications of caught/uncaught exception: ("
195
+ excReq.notifyCaught() + "," + excReq.notifyUncaught() + ")"
196
+ "\n\tmismatched with the expected ReferenceType:\n\tname="
197
+ DEBUGGEE_CLS[j][0] + "\n\tsource=" + DEBUGGEE_CLS[j][1]
198
+ "\tnotifications of caught/uncaught exception: (" + DEBUGGEE_NTFS[j][0] + ","
199
+ DEBUGGEE_NTFS[j][1] + ")");
200
tot_res = FAILED;
201
}
202
notFound = false;
203
break;
204
}
205
}
206
if (notFound) {
207
log.complain("\nTEST CASE #" + t_case
208
+ " FAILED: found an ExceptionRequest object for the unexpected ReferenceType:\n\tname="
209
+ refT.name() + "\n\tsource=" + refT.sourceName()
210
+ "\n\tnotifications of caught/uncaught exception: ("
211
+ excReq.notifyCaught() + "," + excReq.notifyUncaught() + ")");
212
tot_res = FAILED;
213
}
214
} catch(AbsentInformationException e) {
215
log.complain("TEST FAILURE: checkRequests: caught: "
216
+ e);
217
tot_res = FAILED;
218
return;
219
}
220
}
221
}
222
223
private int quitDebuggee() {
224
if (elThread != null) {
225
elThread.isConnected = false;
226
try {
227
if (elThread.isAlive())
228
elThread.join();
229
} catch (InterruptedException e) {
230
log.complain("TEST INCOMPLETE: caught InterruptedException "
231
+ e);
232
tot_res = FAILED;
233
}
234
}
235
236
pipe.println(COMMAND_QUIT);
237
debuggee.waitFor();
238
int debStat = debuggee.getStatus();
239
if (debStat != (JCK_STATUS_BASE + PASSED)) {
240
log.complain("TEST FAILED: debuggee's process finished with status: "
241
+ debStat);
242
tot_res = FAILED;
243
} else
244
log.display("Debuggee's process finished with status: "
245
+ debStat);
246
247
return tot_res;
248
}
249
250
class EventListener extends Thread {
251
public volatile boolean isConnected = true;
252
253
public void run() {
254
try {
255
do {
256
EventSet eventSet = vm.eventQueue().remove(1000);
257
if (eventSet != null) { // there is not a timeout
258
EventIterator it = eventSet.eventIterator();
259
while (it.hasNext()) {
260
Event event = it.nextEvent();
261
if (event instanceof VMDeathEvent) {
262
tot_res = FAILED;
263
isConnected = false;
264
log.complain("TEST FAILED: unexpected VMDeathEvent");
265
} else if (event instanceof VMDisconnectEvent) {
266
tot_res = FAILED;
267
isConnected = false;
268
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
269
} else
270
log.display("EventListener: following JDI event occured: "
271
+ event.toString());
272
}
273
if (isConnected) {
274
eventSet.resume();
275
}
276
}
277
} while (isConnected);
278
} catch (InterruptedException e) {
279
tot_res = FAILED;
280
log.complain("FAILURE in EventListener: caught unexpected "
281
+ e);
282
} catch (VMDisconnectedException e) {
283
tot_res = FAILED;
284
log.complain("FAILURE in EventListener: caught unexpected "
285
+ e);
286
e.printStackTrace();
287
}
288
log.display("EventListener: exiting");
289
}
290
}
291
}
292
293