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