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