Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/accessWatchpointRequests/accwtchpreq001.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.accessWatchpointRequests;
25
26
import com.sun.jdi.Field;
27
import com.sun.jdi.ReferenceType;
28
import com.sun.jdi.request.AccessWatchpointRequest;
29
import com.sun.jdi.request.EventRequestManager;
30
import com.sun.jdi.VirtualMachine;
31
import com.sun.jdi.VMDisconnectedException;
32
import com.sun.jdi.event.*;
33
34
import java.util.Iterator;
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.accessWatchpointRequests()</code>
45
* properly returns all AccessWatchpointRequest objects when:
46
* <li>event requests are disabled
47
* <li>event requests are enabled<br>
48
* EventHandler was added as workaround for the bug 4430096.
49
* This prevents the debugged VM from potential hangup.
50
*/
51
public class accwtchpreq001 {
52
public static final int PASSED = 0;
53
public static final int FAILED = 2;
54
public static final int JCK_STATUS_BASE = 95;
55
static final String DEBUGGEE_CLASS =
56
"nsk.jdi.EventRequestManager.accessWatchpointRequests.accwtchpreq001t";
57
static final String COMMAND_READY = "ready";
58
static final String COMMAND_QUIT = "quit";
59
60
static final int FLDS_NUM = 16;
61
static final String DEBUGGEE_FLDS[][] = {
62
{"byte", "byteFld"},
63
{"short", "shortFld"},
64
{"int", "intFld"},
65
{"long", "longFld"},
66
{"float", "floatFld"},
67
{"double", "doubleFld"},
68
{"char", "charFld"},
69
{"boolean", "booleanFld"},
70
{"java.lang.String", "strFld"},
71
{"short", "sFld"},
72
{"byte", "prFld"},
73
{"float", "pubFld"},
74
{"double", "protFld"},
75
{"int", "tFld"},
76
{"long", "vFld"},
77
{"char", "fFld"}
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 accwtchpreq001().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
List fields;
101
AccessWatchpointRequest awpRequest[] =
102
new AccessWatchpointRequest[FLDS_NUM];
103
String cmd;
104
int i = 0;
105
106
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
107
pipe = debuggee.createIOPipe();
108
debuggee.redirectStderr(log, "accwtchpreq001t.err> ");
109
vm = debuggee.VM();
110
EventRequestManager erManager = vm.eventRequestManager();
111
debuggee.resume();
112
cmd = pipe.readln();
113
if (!cmd.equals(COMMAND_READY)) {
114
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
115
tot_res = FAILED;
116
return quitDebuggee();
117
}
118
119
if ( !vm.canWatchFieldAccess() ) {
120
log.display(" TEST CANCELLED due to: vm.canWatchFieldAccess() == false");
121
return quitDebuggee();
122
}
123
124
if ((rType = debuggee.classByName(DEBUGGEE_CLASS)) == null) {
125
log.complain("TEST FAILURE: Method Debugee.classByName() returned null");
126
tot_res = FAILED;
127
return quitDebuggee();
128
}
129
130
try {
131
fields = rType.allFields();
132
} catch (Exception e) {
133
log.complain("TEST FAILURE: allFields: " + e);
134
tot_res = FAILED;
135
return quitDebuggee();
136
}
137
Iterator iter = fields.iterator();
138
while (iter.hasNext()) {
139
Field fld = (Field) iter.next();
140
log.display("Creating AccessWatchpointRequest for the field "
141
+ fld.typeName() + " " + fld.name());
142
try {
143
awpRequest[i++] = erManager.createAccessWatchpointRequest(fld);
144
} catch (Exception e) {
145
log.complain("TEST FAILURE: createAccessWatchpointRequest: " + e);
146
tot_res = FAILED;
147
return quitDebuggee();
148
}
149
}
150
elThread = new EventListener();
151
elThread.start();
152
153
// Check AccessWatchpoint requests when event requests are disabled
154
log.display("\n1) Getting AccessWatchpointRequest objects with disabled event requests...");
155
checkRequests(erManager, 1);
156
157
// Check AccessWatchpoint requests when event requests are enabled
158
for (i=0; i<FLDS_NUM; i++) {
159
awpRequest[i].enable();
160
}
161
log.display("\n2) Getting AccessWatchpointRequest objects with enabled event requests...");
162
checkRequests(erManager, 2);
163
164
// Finish the test
165
for (i=0; i<FLDS_NUM; i++) {
166
awpRequest[i].disable();
167
}
168
return quitDebuggee();
169
}
170
171
private void checkRequests(EventRequestManager erManager, int t_case) {
172
List reqL = erManager.accessWatchpointRequests();
173
if (reqL.size() != FLDS_NUM) {
174
log.complain("TEST CASE #" + t_case + " FAILED: found "
175
+ reqL.size()
176
+ " AccessWatchpoint requests\n\texpected: " + FLDS_NUM);
177
tot_res = FAILED;
178
return;
179
}
180
for (int i=0; i<FLDS_NUM; i++) {
181
AccessWatchpointRequest awpReq =
182
(AccessWatchpointRequest) reqL.get(i);
183
Field fld = awpReq.field();
184
boolean notFound = true;
185
for (int j=0; j<FLDS_NUM; j++) {
186
if (fld.name().equals(DEBUGGEE_FLDS[j][1])) {
187
if (!fld.typeName().equals(DEBUGGEE_FLDS[j][0])) {
188
log.complain("TEST CASE #" + t_case
189
+ " FAILED: found AccessWatchpoint request for the field "
190
+ fld.typeName() + " " + DEBUGGEE_FLDS[j][1]
191
+ "\n\texpected field: " + DEBUGGEE_FLDS[j][0]);
192
tot_res = FAILED;
193
} else {
194
log.display("Found expected AccessWatchpoint request for the field "
195
+ DEBUGGEE_FLDS[j][0] + " " + DEBUGGEE_FLDS[j][1]);
196
}
197
notFound = false;
198
break;
199
}
200
}
201
if (notFound) {
202
log.complain("TEST CASE #" + t_case
203
+ " FAILED: found unexpected AccessWatchpoint request for the field "
204
+ fld.typeName() + " " + fld.name());
205
tot_res = FAILED;
206
}
207
}
208
}
209
210
private int quitDebuggee() {
211
if (elThread != null) {
212
elThread.isConnected = false;
213
try {
214
if (elThread.isAlive())
215
elThread.join();
216
} catch (InterruptedException e) {
217
log.complain("TEST INCOMPLETE: caught InterruptedException "
218
+ e);
219
tot_res = FAILED;
220
}
221
}
222
223
pipe.println(COMMAND_QUIT);
224
debuggee.waitFor();
225
int debStat = debuggee.getStatus();
226
if (debStat != (JCK_STATUS_BASE + PASSED)) {
227
log.complain("TEST FAILED: debuggee's process finished with status: "
228
+ debStat);
229
tot_res = FAILED;
230
} else
231
log.display("Debuggee's process finished with status: "
232
+ debStat);
233
234
return tot_res;
235
}
236
237
class EventListener extends Thread {
238
public volatile boolean isConnected = true;
239
240
public void run() {
241
try {
242
do {
243
EventSet eventSet = vm.eventQueue().remove(1000);
244
if (eventSet != null) { // there is not a timeout
245
EventIterator it = eventSet.eventIterator();
246
while (it.hasNext()) {
247
Event event = it.nextEvent();
248
if (event instanceof VMDeathEvent) {
249
tot_res = FAILED;
250
isConnected = false;
251
log.complain("TEST FAILED: unexpected VMDeathEvent");
252
} else if (event instanceof VMDisconnectEvent) {
253
tot_res = FAILED;
254
isConnected = false;
255
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
256
} else
257
log.display("EventListener: following JDI event occured: "
258
+ event.toString());
259
}
260
if (isConnected) {
261
eventSet.resume();
262
}
263
}
264
} while (isConnected);
265
} catch (InterruptedException e) {
266
tot_res = FAILED;
267
log.complain("FAILURE in EventListener: caught unexpected "
268
+ e);
269
} catch (VMDisconnectedException e) {
270
tot_res = FAILED;
271
log.complain("FAILURE in EventListener: caught unexpected "
272
+ e);
273
e.printStackTrace();
274
}
275
log.display("EventListener: exiting");
276
}
277
}
278
}
279
280