Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/methodEntryRequests/methentreq001.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.methodEntryRequests;
25
26
import com.sun.jdi.request.MethodEntryRequest;
27
import com.sun.jdi.request.EventRequestManager;
28
import com.sun.jdi.VirtualMachine;
29
import com.sun.jdi.VMDisconnectedException;
30
import com.sun.jdi.event.*;
31
32
import java.util.List;
33
import java.io.*;
34
35
import nsk.share.*;
36
import nsk.share.jpda.*;
37
import nsk.share.jdi.*;
38
39
/**
40
* The test checks that the JDI method
41
* <code>com.sun.jdi.request.EventRequestManager.methodEntryRequests()</code>
42
* properly returns all MethodEntryRequest objects when:
43
* <li>event requests are disabled
44
* <li>event requests are enabled.<br>
45
* The MethodEntryRequest objects are distinguished by the different
46
* <code>EventRequest</code>'s properties.<br>
47
* EventHandler was added as workaround for the bug 4430096.
48
* This prevents the target VM from potential hangup.
49
*/
50
public class methentreq001 {
51
public static final int PASSED = 0;
52
public static final int FAILED = 2;
53
public static final int JCK_STATUS_BASE = 95;
54
static final int TIMEOUT_DELTA = 1000; // in milliseconds
55
static final String DEBUGGEE_CLASS =
56
"nsk.jdi.EventRequestManager.methodEntryRequests.methentreq001t";
57
static final String COMMAND_READY = "ready";
58
static final String COMMAND_QUIT = "quit";
59
60
static final int MENTRS_NUM = 7;
61
static final String PROPS[][] = {
62
{"first", "a quick"},
63
{"second", "brown"},
64
{"third", "fox"},
65
{"fourth", "jumps"},
66
{"fifth", "over"},
67
{"sixth", "the lazy"},
68
{"seventh", "dog"}
69
};
70
71
private Log log;
72
private IOPipe pipe;
73
private Debugee debuggee;
74
private VirtualMachine vm;
75
private EventListener elThread;
76
private volatile int tot_res = PASSED;
77
78
public static void main (String argv[]) {
79
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
80
}
81
82
public static int run(String argv[], PrintStream out) {
83
return new methentreq001().runIt(argv, out);
84
}
85
86
private int runIt(String args[], PrintStream out) {
87
ArgumentHandler argHandler = new ArgumentHandler(args);
88
log = new Log(out, argHandler);
89
Binder binder = new Binder(argHandler, log);
90
MethodEntryRequest mentrRequest[] = new MethodEntryRequest[MENTRS_NUM];
91
String cmd;
92
93
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
94
pipe = debuggee.createIOPipe();
95
debuggee.redirectStderr(log, "methentreq001t.err> ");
96
vm = debuggee.VM();
97
EventRequestManager erManager = vm.eventRequestManager();
98
debuggee.resume();
99
cmd = pipe.readln();
100
if (!cmd.equals(COMMAND_READY)) {
101
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
102
tot_res = FAILED;
103
return quitDebuggee();
104
}
105
106
for (int i=0; i<MENTRS_NUM; i++) {
107
log.display("Creating MethodEntryRequest #" + i
108
+ " with the property ("
109
+ PROPS[i][0] + "," + PROPS[i][1] + ")...");
110
mentrRequest[i] = erManager.createMethodEntryRequest();
111
mentrRequest[i].putProperty(PROPS[i][0], PROPS[i][1]);
112
}
113
elThread = new EventListener();
114
elThread.start();
115
116
// Check MethodEntry requests when event requests are disabled
117
log.display("\n1) Getting MethodEntryRequest objects with disabled event requests...");
118
checkRequests(erManager, 1);
119
120
// Check MethodEntry requests when event requests are enabled
121
for (int i=0; i<MENTRS_NUM; i++) {
122
mentrRequest[i].enable();
123
}
124
log.display("\n2) Getting MethodEntryRequest objects with enabled event requests...");
125
checkRequests(erManager, 2);
126
127
// Finish the test
128
for (int i=0; i<MENTRS_NUM; i++) {
129
mentrRequest[i].disable();
130
}
131
return quitDebuggee();
132
}
133
134
private void checkRequests(EventRequestManager erManager, int t_case) {
135
List reqL = erManager.methodEntryRequests();
136
if (reqL.size() != MENTRS_NUM) {
137
log.complain("TEST CASE #" + t_case + " FAILED: found " + reqL.size()
138
+ " MethodEntryRequest objects\n\texpected: " + MENTRS_NUM);
139
tot_res = FAILED;
140
return;
141
}
142
for (int i=0; i<MENTRS_NUM; i++) {
143
MethodEntryRequest meReq =
144
(MethodEntryRequest) reqL.get(i);
145
boolean notFound = true;
146
for (int j=0; j<MENTRS_NUM; j++) {
147
String propKey = (String) meReq.getProperty(PROPS[j][0]);
148
if (propKey != null) {
149
if (propKey.equals(PROPS[j][1])) {
150
log.display("Found expected MethodEntryRequest object with the property: ("
151
+ PROPS[j][0] + "," + propKey + ")");
152
} else {
153
log.complain("TEST CASE #" + t_case
154
+ " FAILED: found MethodEntryRequest object with the unexpected property: ("
155
+ PROPS[j][0] + "," + propKey + ")");
156
tot_res = FAILED;
157
}
158
notFound = false;
159
break;
160
}
161
}
162
if (notFound) {
163
log.complain("\nTEST CASE #" + t_case
164
+ " FAILED: found unexpected MethodEntryRequest object");
165
tot_res = FAILED;
166
}
167
}
168
}
169
170
private int quitDebuggee() {
171
if (elThread != null) {
172
elThread.isConnected = false;
173
try {
174
if (elThread.isAlive())
175
elThread.join();
176
} catch (InterruptedException e) {
177
log.complain("TEST INCOMPLETE: caught InterruptedException "
178
+ e);
179
tot_res = FAILED;
180
}
181
}
182
183
log.display("Sending the command \"" + COMMAND_QUIT
184
+ "\" to the debuggee");
185
pipe.println(COMMAND_QUIT);
186
debuggee.waitFor();
187
int debStat = debuggee.getStatus();
188
if (debStat != (JCK_STATUS_BASE + PASSED)) {
189
log.complain("TEST FAILED: debuggee's process finished with status: "
190
+ debStat);
191
tot_res = FAILED;
192
} else
193
log.display("Debuggee's process finished with status: "
194
+ debStat);
195
196
return tot_res;
197
}
198
199
class EventListener extends Thread {
200
public volatile boolean isConnected = true;
201
EventSet eventSet;
202
203
public void run() {
204
try {
205
do {
206
eventSet = vm.eventQueue().remove(TIMEOUT_DELTA);
207
if (eventSet != null) { // there is not a timeout
208
EventIterator it = eventSet.eventIterator();
209
while (it.hasNext()) {
210
Event event = it.nextEvent();
211
if (event instanceof VMDeathEvent) {
212
tot_res = FAILED;
213
isConnected = false;
214
log.complain("TEST FAILED: unexpected VMDeathEvent");
215
} else if (event instanceof VMDisconnectEvent) {
216
tot_res = FAILED;
217
isConnected = false;
218
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
219
} else
220
log.display("EventListener: following JDI event occured: "
221
+ event.toString());
222
}
223
log.display("EventListener: resuming debuggee VM");
224
eventSet.resume();
225
}
226
} while (isConnected);
227
228
// clean up JDI event queue
229
log.display("EventListener: cleaning up JDI event queue");
230
eventSet = vm.eventQueue().remove(TIMEOUT_DELTA);
231
if (eventSet == null)
232
log.display("EventListener: no more events");
233
else {
234
log.display("EventListener: final resuming of debuggee VM");
235
eventSet.resume();
236
}
237
} catch (InterruptedException e) {
238
tot_res = FAILED;
239
log.complain("FAILURE in EventListener: caught unexpected "
240
+ e);
241
} catch (VMDisconnectedException e) {
242
if (isConnected) {
243
tot_res = FAILED;
244
log.complain("FAILURE in EventListener: caught unexpected "
245
+ e);
246
e.printStackTrace();
247
}
248
}
249
log.display("EventListener: exiting");
250
}
251
}
252
}
253
254