Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createModificationWatchpointRequest/crmodwtchpreq003.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.createModificationWatchpointRequest;
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.createModificationWatchpointRequest()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* - Multiple watchpoints on the same field are permitted. <BR>
47
* - Creates a new disabled watchpoint. <BR>
48
* - The watchpoint watches modification of the specified field. <BR>
49
* - Throws: UnsupportedOperationException - <BR>
50
* if the target virtual machine does not support this operation. <BR>
51
* <BR>
52
* The test has three phases and works as follows. <BR>
53
* <BR>
54
* In first phase, <BR>
55
* upon launching debuggee's VM which will be suspended, <BR>
56
* a debugger waits for the VMStartEvent within a predefined <BR>
57
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
58
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
59
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
60
* and waits for the event within the predefined time interval. <BR>
61
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
62
* Upon getting the ClassPrepareEvent, <BR>
63
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
64
* within debuggee's special methodForCommunication(). <BR>
65
* <BR>
66
* In second phase to check the assertion, <BR>
67
* the debugger and the debuggee perform the following. <BR>
68
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
69
* - The debuggee prepares testcase and invokes <BR>
70
* the methodForCommunication to be suspended and <BR>
71
* to inform the debugger with the event. <BR>
72
* - Upon getting the BreakpointEvent, <BR>
73
* the debugger performs the checks required. <BR>
74
* <BR>
75
* In third phase, at the end of the test, the debuggee changes <BR>
76
* the value of the "instruction" which the debugger and debuggee <BR>
77
* use to inform each other of needed actions, and both end. <BR>
78
* <BR>
79
*/
80
81
public class crmodwtchpreq003 extends JDIBase {
82
83
public static void main (String argv[]) {
84
85
int result = run(argv, System.out);
86
87
System.exit(result + PASS_BASE);
88
}
89
90
public static int run (String argv[], PrintStream out) {
91
92
int exitCode = new crmodwtchpreq003().runThis(argv, out);
93
94
if (exitCode != PASSED) {
95
System.out.println("TEST FAILED");
96
}
97
return testExitCode;
98
}
99
100
// ************************************************ test parameters
101
102
private String debuggeeName =
103
"nsk.jdi.EventRequestManager.createModificationWatchpointRequest.crmodwtchpreq003a";
104
105
//====================================================== test program
106
107
private int runThis (String argv[], PrintStream out) {
108
109
argsHandler = new ArgumentHandler(argv);
110
logHandler = new Log(out, argsHandler);
111
Binder binder = new Binder(argsHandler, logHandler);
112
113
waitTime = argsHandler.getWaitTime() * 60000;
114
115
try {
116
log2("launching a debuggee :");
117
log2(" " + debuggeeName);
118
if (argsHandler.verbose()) {
119
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
120
} else {
121
debuggee = binder.bindToDebugee(debuggeeName);
122
}
123
if (debuggee == null) {
124
log3("ERROR: no debuggee launched");
125
return FAILED;
126
}
127
log2("debuggee launched");
128
} catch ( Exception e ) {
129
log3("ERROR: Exception : " + e);
130
log2(" test cancelled");
131
return FAILED;
132
}
133
134
debuggee.redirectOutput(logHandler);
135
136
vm = debuggee.VM();
137
138
eventQueue = vm.eventQueue();
139
if (eventQueue == null) {
140
log3("ERROR: eventQueue == null : TEST ABORTED");
141
vm.exit(PASS_BASE);
142
return FAILED;
143
}
144
145
log2("invocation of the method runTest()");
146
switch (runTest()) {
147
148
case 0 : log2("test phase has finished normally");
149
log2(" waiting for the debuggee to finish ...");
150
debuggee.waitFor();
151
152
log2("......getting the debuggee's exit status");
153
int status = debuggee.getStatus();
154
if (status != PASS_BASE) {
155
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
156
status + " != PASS_BASE");
157
testExitCode = FAILED;
158
} else {
159
log2("......debuggee returned expected exit status: " +
160
status + " == PASS_BASE");
161
}
162
break;
163
164
default : log3("ERROR: runTest() returned unexpected value");
165
166
case 1 : log3("test phase has not finished normally: debuggee is still alive");
167
log2("......forcing: vm.exit();");
168
testExitCode = FAILED;
169
try {
170
vm.exit(PASS_BASE);
171
} catch ( Exception e ) {
172
log3("ERROR: Exception : " + e);
173
}
174
break;
175
176
case 2 : log3("test cancelled due to VMDisconnectedException");
177
log2("......trying: vm.process().destroy();");
178
testExitCode = FAILED;
179
try {
180
Process vmProcess = vm.process();
181
if (vmProcess != null) {
182
vmProcess.destroy();
183
}
184
} catch ( Exception e ) {
185
log3("ERROR: Exception : " + e);
186
}
187
break;
188
}
189
190
return testExitCode;
191
}
192
193
194
/*
195
* Return value: 0 - normal end of the test
196
* 1 - ubnormal end of the test
197
* 2 - VMDisconnectedException while test phase
198
*/
199
200
private int runTest() {
201
202
try {
203
testRun();
204
205
log2("waiting for VMDeathEvent");
206
getEventSet();
207
if (eventIterator.nextEvent() instanceof VMDeathEvent)
208
return 0;
209
210
log3("ERROR: last event is not the VMDeathEvent");
211
return 1;
212
} catch ( VMDisconnectedException e ) {
213
log3("ERROR: VMDisconnectedException : " + e);
214
return 2;
215
} catch ( Exception e ) {
216
log3("ERROR: Exception : " + e);
217
return 1;
218
}
219
220
}
221
222
private void testRun()
223
throws JDITestRuntimeException, Exception {
224
225
eventRManager = vm.eventRequestManager();
226
227
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
228
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
229
cpRequest.addClassFilter(debuggeeName);
230
231
cpRequest.enable();
232
vm.resume();
233
getEventSet();
234
cpRequest.disable();
235
236
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
237
debuggeeClass = event.referenceType();
238
239
if (!debuggeeClass.name().equals(debuggeeName))
240
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
241
242
log2(" received: ClassPrepareEvent for debuggeeClass");
243
244
String bPointMethod = "methodForCommunication";
245
String lineForComm = "lineForComm";
246
247
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
248
249
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
250
debuggeeClass,
251
bPointMethod, lineForComm, "zero");
252
bpRequest.enable();
253
254
//------------------------------------------------------ testing section
255
256
String fieldName = "testField";
257
258
Field field = null;
259
260
List requests = null;
261
ListIterator li = null;
262
263
ModificationWatchpointRequest mwRequest1 = null;
264
ModificationWatchpointRequest mwRequest2 = null;
265
266
267
log1(" TESTING BEGINS");
268
269
for (int i = 0; ; i++) {
270
271
vm.resume();
272
breakpointForCommunication();
273
274
int instruction = ((IntegerValue)
275
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
276
277
if (instruction == 0) {
278
vm.resume();
279
break;
280
}
281
282
log1(":::::: case: # " + i);
283
284
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
285
286
field = debuggeeClass.fieldByName(fieldName);
287
288
if ( vm.canWatchFieldModification() ) {
289
log2("......vm.canWatchFieldModification == true");
290
log2(" creating two ModificationWatchpointRequests for 'field': mwRequest1 & mwRequest2");
291
292
mwRequest1 = eventRManager.createModificationWatchpointRequest(field);
293
mwRequest2 = eventRManager.createModificationWatchpointRequest(field);
294
295
log2(" checking up on: requests are disabled");
296
if (mwRequest1.isEnabled()) {
297
testExitCode = FAILED;
298
log3("ERROR: mwRequest1 is enabled");
299
}
300
if (mwRequest2.isEnabled()) {
301
testExitCode = FAILED;
302
log3("ERROR: mwRequest2 is enabled");
303
}
304
log2(" compareing field equality");
305
if ( !mwRequest1.field().equals(field) ) {
306
testExitCode = FAILED;
307
log3("ERROR: !mwRequest1.field().equals(field)");
308
}
309
if ( !mwRequest2.field().equals(field) ) {
310
testExitCode = FAILED;
311
log3("ERROR: !mwRequest2.field().equals(field)");
312
}
313
314
} else {
315
log2("......vm.canWatchFieldModification == false");
316
log2(" UnsupportedOperationException is expected");
317
try {
318
mwRequest1 = eventRManager.createModificationWatchpointRequest(field);
319
testExitCode = FAILED;
320
log3("ERROR: NO UnsupportedOperationException");
321
} catch ( UnsupportedOperationException e ) {
322
}
323
}
324
325
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326
}
327
log1(" TESTING ENDS");
328
return;
329
}
330
331
}
332
333