Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/modificationWatchpointRequests/modwtchpreq001.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.modificationWatchpointRequests;
25
26
import com.sun.jdi.Field;
27
import com.sun.jdi.ReferenceType;
28
import com.sun.jdi.VirtualMachine;
29
import com.sun.jdi.VMDisconnectedException;
30
import com.sun.jdi.request.ModificationWatchpointRequest;
31
import com.sun.jdi.request.EventRequestManager;
32
import com.sun.jdi.event.*;
33
34
import java.util.Iterator;
35
import java.util.List;
36
37
import java.io.*;
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.modificationWatchpointRequests()</code>
45
* properly returns all ModificationWatchpointRequest 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 target VM from potential hangup.
50
*/
51
public class modwtchpreq001 {
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.modificationWatchpointRequests.modwtchpreq001t";
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", "B"},
63
{"short", "shortFld", "S"},
64
{"int", "intFld", "I"},
65
{"long", "longFld", "J"},
66
{"float", "floatFld", "F"},
67
{"double", "doubleFld", "D"},
68
{"char", "charFld", "C"},
69
{"boolean", "booleanFld", "Z"},
70
{"java.lang.String", "strFld", "Ljava/lang/String;"},
71
{"short", "sFld", "S"},
72
{"byte", "prFld", "B"},
73
{"float", "pubFld", "F"},
74
{"double", "protFld", "D"},
75
{"int", "tFld", "I"},
76
{"long", "vFld", "J"},
77
{"char", "fFld", "C"}
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 modwtchpreq001().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
ModificationWatchpointRequest mwpRequest[] =
102
new ModificationWatchpointRequest[FLDS_NUM];
103
String cmd;
104
int i = 0;
105
106
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
107
pipe = debuggee.createIOPipe();
108
debuggee.redirectStderr(log, "modwtchpreq001t.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.canWatchFieldModification() ) {
120
log.display(" TEST CANCELLED due to: vm.canWatchFieldModification() == 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("\nCreating ModificationWatchpointRequest for the field:\n\t"
141
+ fld.typeName() + " " + fld.name()
142
+ " type_signature=" + fld.signature());
143
try {
144
mwpRequest[i++] = erManager.createModificationWatchpointRequest(fld);
145
} catch (Exception e) {
146
log.complain("TEST FAILURE: createModificationWatchpointRequest: " + e);
147
tot_res = FAILED;
148
return quitDebuggee();
149
}
150
}
151
elThread = new EventListener();
152
elThread.start();
153
154
// Check ModificationWatchpoint requests when event requests are disabled
155
log.display("\n1) Getting ModificationWatchpointRequest objects with disabled event requests...");
156
checkRequests(erManager, 1);
157
158
// Check ModificationWatchpoint requests when event requests are enabled
159
for (i=0; i<FLDS_NUM; i++) {
160
mwpRequest[i].enable();
161
}
162
log.display("\n2) Getting ModificationWatchpointRequest objects with enabled event requests...");
163
checkRequests(erManager, 2);
164
165
// Finish the test
166
for (i=0; i<FLDS_NUM; i++) {
167
mwpRequest[i].disable();
168
}
169
return quitDebuggee();
170
}
171
172
private void checkRequests(EventRequestManager erManager, int t_case) {
173
List reqL = erManager.modificationWatchpointRequests();
174
if (reqL.size() != FLDS_NUM) {
175
log.complain("TEST CASE #" + t_case + " FAILED: found " + reqL.size()
176
+ " ModificationWatchpoint requests\n\texpected: " + FLDS_NUM);
177
tot_res = FAILED;
178
return;
179
}
180
for (int i=0; i<FLDS_NUM; i++) {
181
ModificationWatchpointRequest mwpReq =
182
(ModificationWatchpointRequest) reqL.get(i);
183
Field fld = mwpReq.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
!fld.signature().equals(DEBUGGEE_FLDS[j][2])) {
189
log.complain("\nTEST CASE #" + t_case
190
+ " FAILED: found ModificationWatchpoint request for the field:\n\t"
191
+ fld.typeName() + " " + fld.name()
192
+ " type_signature=" + fld.signature()
193
+ "\n\texpected field: " + DEBUGGEE_FLDS[j][0]
194
+ " " + DEBUGGEE_FLDS[j][1] + " type_signature="
195
+ DEBUGGEE_FLDS[j][2]);
196
tot_res = FAILED;
197
} else {
198
log.display("\nFound expected ModificationWatchpoint request for the field:\n\t"
199
+ DEBUGGEE_FLDS[j][0] + " " + DEBUGGEE_FLDS[j][1]
200
+ " type_signature=" + DEBUGGEE_FLDS[j][2]);
201
}
202
notFound = false;
203
break;
204
}
205
}
206
if (notFound) {
207
log.complain("\nTEST CASE #" + t_case
208
+ " FAILED: found unexpected ModificationWatchpoint request for the field: "
209
+ fld.typeName() + " " + fld.name()
210
+ " type_signature=" + fld.signature());
211
tot_res = FAILED;
212
}
213
}
214
}
215
216
private int quitDebuggee() {
217
if (elThread != null) {
218
elThread.isConnected = false;
219
try {
220
if (elThread.isAlive())
221
elThread.join();
222
} catch (InterruptedException e) {
223
log.complain("TEST INCOMPLETE: caught InterruptedException "
224
+ e);
225
tot_res = FAILED;
226
}
227
}
228
229
pipe.println(COMMAND_QUIT);
230
debuggee.waitFor();
231
int debStat = debuggee.getStatus();
232
if (debStat != (JCK_STATUS_BASE + PASSED)) {
233
log.complain("TEST FAILED: debuggee's process finished with status: "
234
+ debStat);
235
tot_res = FAILED;
236
} else
237
log.display("Debuggee's process finished with status: "
238
+ debStat);
239
240
return tot_res;
241
}
242
243
class EventListener extends Thread {
244
public volatile boolean isConnected = true;
245
246
public void run() {
247
try {
248
do {
249
EventSet eventSet = vm.eventQueue().remove(1000);
250
if (eventSet != null) { // there is not a timeout
251
EventIterator it = eventSet.eventIterator();
252
while (it.hasNext()) {
253
Event event = it.nextEvent();
254
if (event instanceof VMDeathEvent) {
255
tot_res = FAILED;
256
isConnected = false;
257
log.complain("TEST FAILED: unexpected VMDeathEvent");
258
} else if (event instanceof VMDisconnectEvent) {
259
tot_res = FAILED;
260
isConnected = false;
261
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
262
} else
263
log.display("EventListener: following JDI event occured: "
264
+ event.toString());
265
}
266
if (isConnected) {
267
eventSet.resume();
268
}
269
}
270
} while (isConnected);
271
} catch (InterruptedException e) {
272
tot_res = FAILED;
273
log.complain("FAILURE in EventListener: caught unexpected "
274
+ e);
275
} catch (VMDisconnectedException e) {
276
tot_res = FAILED;
277
log.complain("FAILURE in EventListener: caught unexpected "
278
+ e);
279
e.printStackTrace();
280
}
281
log.display("EventListener: exiting");
282
}
283
}
284
}
285
286