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/accwtchpreq002.java
41161 views
1
/*
2
* Copyright (c) 2001, 2020, 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 nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import com.sun.jdi.event.*;
32
import com.sun.jdi.request.*;
33
34
import java.util.*;
35
import java.io.*;
36
37
/**
38
* The test for the implementation of an object of the type <BR>
39
* EventRequestManager. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequestManager.accessWatchpointRequests()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - The list is unmodifiable. <BR>
47
* - The list of the enabled and disabled access watchpoint requests. <BR>
48
* - This list is changes as requests are added and deleted. <BR>
49
* <BR>
50
* The test has three phases and works as follows. <BR>
51
* <BR>
52
* In first phase, <BR>
53
* upon launching debuggee's VM which will be suspended, <BR>
54
* a debugger waits for the VMStartEvent within a predefined <BR>
55
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
56
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
57
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
58
* and waits for the event within the predefined time interval. <BR>
59
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
60
* Upon getting the ClassPrepareEvent, <BR>
61
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
62
* within debuggee's special methodForCommunication(). <BR>
63
* <BR>
64
* In second phase to check the assertion, <BR>
65
* the debugger and the debuggee perform the following. <BR>
66
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
67
* - The debuggee prepares the check case and invokes <BR>
68
* the methodForCommunication to be suspended and <BR>
69
* to inform the debugger with the event. <BR>
70
* - Upon getting the BreakpointEvent, <BR>
71
* the debugger checking up on assertions. <BR>
72
* <BR>
73
* In third phase, at the end of the test, the debuggee changes <BR>
74
* the value of the "instruction" which the debugger and debuggee <BR>
75
* use to inform each other of needed actions, and both end. <BR>
76
* <BR>
77
*/
78
79
public class accwtchpreq002 extends JDIBase {
80
81
public static void main (String argv[]) {
82
83
int result = run(argv, System.out);
84
85
System.exit(result + PASS_BASE);
86
}
87
88
public static int run (String argv[], PrintStream out) {
89
90
int exitCode = new accwtchpreq002().runThis(argv, out);
91
92
if (exitCode != PASSED) {
93
System.out.println("TEST FAILED");
94
}
95
return testExitCode;
96
}
97
98
private String debuggeeName =
99
"nsk.jdi.EventRequestManager.accessWatchpointRequests.accwtchpreq002a";
100
101
//====================================================== test program
102
103
private int runThis (String argv[], PrintStream out) {
104
105
argsHandler = new ArgumentHandler(argv);
106
logHandler = new Log(out, argsHandler);
107
Binder binder = new Binder(argsHandler, logHandler);
108
109
waitTime = argsHandler.getWaitTime() * 60000;
110
111
try {
112
log2("launching a debuggee :");
113
log2(" " + debuggeeName);
114
if (argsHandler.verbose()) {
115
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
116
} else {
117
debuggee = binder.bindToDebugee(debuggeeName);
118
}
119
if (debuggee == null) {
120
log3("ERROR: no debuggee launched");
121
return FAILED;
122
}
123
log2("debuggee launched");
124
} catch ( Exception e ) {
125
log3("ERROR: Exception : " + e);
126
log2(" test cancelled");
127
return FAILED;
128
}
129
130
debuggee.redirectOutput(logHandler);
131
132
vm = debuggee.VM();
133
134
eventQueue = vm.eventQueue();
135
if (eventQueue == null) {
136
log3("ERROR: eventQueue == null : TEST ABORTED");
137
vm.exit(PASS_BASE);
138
return FAILED;
139
}
140
141
log2("invocation of the method runTest()");
142
switch (runTest()) {
143
144
case 0 : log2("test phase has finished normally");
145
log2(" waiting for the debuggee to finish ...");
146
debuggee.waitFor();
147
148
log2("......getting the debuggee's exit status");
149
int status = debuggee.getStatus();
150
if (status != PASS_BASE) {
151
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
152
status + " != PASS_BASE");
153
testExitCode = FAILED;
154
} else {
155
log2("......debuggee returned expected exit status: " +
156
status + " == PASS_BASE");
157
}
158
break;
159
160
default : log3("ERROR: runTest() returned unexpected value");
161
162
case 1 : log3("test phase has not finished normally: debuggee is still alive");
163
log2("......forcing: vm.exit();");
164
testExitCode = FAILED;
165
try {
166
vm.exit(PASS_BASE);
167
} catch ( Exception e ) {
168
log3("ERROR: Exception : " + e);
169
}
170
break;
171
172
case 2 : log3("test cancelled due to VMDisconnectedException");
173
log2("......trying: vm.process().destroy();");
174
testExitCode = FAILED;
175
try {
176
Process vmProcess = vm.process();
177
if (vmProcess != null) {
178
vmProcess.destroy();
179
}
180
} catch ( Exception e ) {
181
log3("ERROR: Exception : " + e);
182
}
183
break;
184
}
185
186
return testExitCode;
187
}
188
189
190
/*
191
* Return value: 0 - normal end of the test
192
* 1 - ubnormal end of the test
193
* 2 - VMDisconnectedException while test phase
194
*/
195
196
private int runTest() {
197
198
try {
199
testRun();
200
201
log2("waiting for VMDeathEvent");
202
getEventSet();
203
if (eventIterator.nextEvent() instanceof VMDeathEvent)
204
return 0;
205
206
log3("ERROR: last event is not the VMDeathEvent");
207
return 1;
208
} catch ( VMDisconnectedException e ) {
209
log3("ERROR: VMDisconnectedException : " + e);
210
return 2;
211
} catch ( Exception e ) {
212
log3("ERROR: Exception : " + e);
213
return 1;
214
}
215
216
}
217
218
private void testRun()
219
throws JDITestRuntimeException, Exception {
220
221
if ( !vm.canWatchFieldAccess() ) {
222
log2("......vm.canWatchFieldAccess == false :: test cancelled");
223
vm.exit(PASS_BASE);
224
return;
225
}
226
227
eventRManager = vm.eventRequestManager();
228
229
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
230
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
231
cpRequest.addClassFilter(debuggeeName);
232
233
cpRequest.enable();
234
vm.resume();
235
getEventSet();
236
cpRequest.disable();
237
238
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
239
debuggeeClass = event.referenceType();
240
241
if (!debuggeeClass.name().equals(debuggeeName))
242
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
243
244
log2(" received: ClassPrepareEvent for debuggeeClass");
245
246
String bPointMethod = "methodForCommunication";
247
String lineForComm = "lineForComm";
248
249
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
250
251
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
252
debuggeeClass,
253
bPointMethod, lineForComm, "zero");
254
bpRequest.enable();
255
256
//------------------------------------------------------ testing section
257
258
String fieldName = "testField";
259
260
Field field = null;
261
262
List requests = null;
263
ListIterator li = null;
264
265
AccessWatchpointRequest request = null;
266
AccessWatchpointRequest awRequests[] = { null, null, null, null, null,
267
null, null, null, null, null };
268
int listSize;
269
int flag;
270
271
272
log1(" TESTING BEGINS");
273
274
for (int i = 0; ; i++) {
275
276
vm.resume();
277
breakpointForCommunication();
278
279
int instruction = ((IntegerValue)
280
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
281
282
if (instruction == 0) {
283
vm.resume();
284
break;
285
}
286
287
log1(":::::: case: # " + i);
288
289
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
290
291
field = debuggeeClass.fieldByName(fieldName);
292
293
log2("......creating AccessWatchpointRequests");
294
for (int i1 = 0; i1 < awRequests.length; i1++) {
295
awRequests[i1] = eventRManager.createAccessWatchpointRequest(field);
296
awRequests[i1].putProperty("number", String.valueOf(i1));
297
298
log2("......checking up on returned List after creating new AccessWatchpointRequest");
299
requests = eventRManager.accessWatchpointRequests();
300
listSize = requests.size();
301
if ( listSize != (i1 + 1) ) {
302
testExitCode = FAILED;
303
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + (i1 + 1));
304
}
305
flag = 0;
306
li = requests.listIterator();
307
while (li.hasNext()) {
308
request = (AccessWatchpointRequest) li.next();
309
if ( !request.isEnabled() ) {
310
flag++;
311
if (flag > 1) {
312
testExitCode = FAILED;
313
log3("ERROR: # of disabled requests > 1 : " + flag);
314
}
315
if ( !request.getProperty("number").equals(String.valueOf(i1)) ) {
316
testExitCode = FAILED;
317
log3("ERROR: in the List, disabled is request expected to be enabled : # == " + i1);
318
}
319
} else {
320
if ( request.getProperty("number").equals(String.valueOf(i1)) ) {
321
testExitCode = FAILED;
322
log3("ERROR: in the List, enabled is newly created disabled request : # == " + i1);
323
}
324
}
325
}
326
327
log2(" enabling created AccessWatchpointRequest");
328
awRequests[i1].enable();
329
requests = eventRManager.accessWatchpointRequests();
330
listSize = requests.size();
331
if ( listSize != (i1 + 1) ) {
332
testExitCode = FAILED;
333
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + (i1 + 1));
334
}
335
336
li = requests.listIterator();
337
while (li.hasNext()) {
338
request = (AccessWatchpointRequest) li.next();
339
if ( !request.isEnabled() ) {
340
testExitCode = FAILED;
341
log3("ERROR: returned List contains disabled request : " + request);
342
}
343
}
344
345
log2(" removing item from the List; UnsupportedOperationException is expected");
346
try {
347
requests.remove(i1);
348
testExitCode = FAILED;
349
log3("ERROR: NO exception");
350
} catch ( UnsupportedOperationException e ) {
351
log2(" UnsupportedOperationException ");
352
}
353
}
354
355
log2("......deleting AccessWatchpointRequests");
356
for (int i2 = awRequests.length -1; i2 >= 0; i2--) {
357
eventRManager.deleteEventRequest(awRequests[i2]);
358
requests = eventRManager.accessWatchpointRequests();
359
listSize = requests.size();
360
if ( listSize != i2 ) {
361
testExitCode = FAILED;
362
log3("ERROR: size of returned List is not equal to expected : " + listSize + " != " + i2);
363
}
364
log2(" removing item from the List; UnsupportedOperationException is expected");
365
try {
366
requests.remove(i2);
367
testExitCode = FAILED;
368
log3("ERROR: NO exception");
369
} catch ( UnsupportedOperationException e ) {
370
log2(" UnsupportedOperationException ");
371
}
372
}
373
374
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
375
}
376
log1(" TESTING ENDS");
377
return;
378
}
379
380
}
381
382