Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/setEnabled/setenabled001.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.EventRequest.setEnabled;
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
* EventRequest. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventRequest.setEnabled()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on the following assertion: <BR>
46
* Enables or disables this event request. <BR>
47
* The cases to test include all sub-types of EventRequest. <BR>
48
* <BR>
49
* The test has three phases and works as follows. <BR>
50
* <BR>
51
* In first phase, <BR>
52
* upon launching debuggee's VM which will be suspended, <BR>
53
* a debugger waits for the VMStartEvent within a predefined <BR>
54
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
55
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
56
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
57
* and waits for the event within the predefined time interval. <BR>
58
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
59
* Upon getting the ClassPrepareEvent, <BR>
60
* the debugger sets up the breakpoint with SUSPEND_ALL <BR>
61
* within debuggee's special methodForCommunication(). <BR>
62
* <BR>
63
* In second phase to check the assertion, <BR>
64
* the debugger and the debuggee perform the following. <BR>
65
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
66
* - The debuggee prepares new check case and invokes <BR>
67
* the methodForCommunication to be suspended and <BR>
68
* to inform the debugger with the event. <BR>
69
* - Upon getting the BreakpointEvent, <BR>
70
* the debugger performs the check case required. <BR>
71
* <BR>
72
* In third phase, at the end of the test, the debuggee changes <BR>
73
* the value of the "instruction" which the debugger and debuggee <BR>
74
* use to inform each other of needed actions, and both end. <BR>
75
* <BR>
76
*/
77
78
public class setenabled001 extends JDIBase {
79
80
public static void main (String argv[]) {
81
82
int result = run(argv, System.out);
83
84
System.exit(result + PASS_BASE);
85
}
86
87
public static int run (String argv[], PrintStream out) {
88
89
int exitCode = new setenabled001().runThis(argv, out);
90
91
if (exitCode != PASSED) {
92
System.out.println("TEST FAILED");
93
}
94
return testExitCode;
95
}
96
97
// ************************************************ test parameters
98
99
private String debuggeeName =
100
"nsk.jdi.EventRequest.setEnabled.setenabled001a";
101
102
private String testedClassName =
103
"nsk.jdi.EventRequest.setEnabled.setenabled001aTestClass11";
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
257
EventRequest eventRequest1 = null;
258
259
String fieldName1 = "var101";
260
String fieldName2 = "excObj";
261
262
ThreadReference thread1 = null;
263
String threadName1 = "thread1";
264
265
ReferenceType testClassReference = null;
266
267
268
log1(" TESTING BEGINS");
269
270
for (int i = 0; ; i++) {
271
272
vm.resume();
273
breakpointForCommunication();
274
275
int instruction = ((IntegerValue)
276
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
277
278
if (instruction == 0) {
279
vm.resume();
280
break;
281
}
282
283
log1(":::::: case: # " + i);
284
285
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
286
287
288
switch (i) {
289
290
case 0:
291
thread1 = debuggee.threadByNameOrThrow(threadName1);
292
293
log2("......setting up StepRequest");
294
eventRequest1 = eventRManager.createStepRequest
295
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
296
break;
297
298
case 1:
299
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
300
301
log2("......setting up AccessWatchpointRequest");
302
eventRequest1 = eventRManager.createAccessWatchpointRequest
303
(testClassReference.fieldByName(fieldName1));
304
break;
305
306
case 2:
307
log2(".....setting up ModificationWatchpointRequest");
308
eventRequest1 = eventRManager.createModificationWatchpointRequest
309
(testClassReference.fieldByName(fieldName1));
310
break;
311
312
case 3:
313
log2(".....setting up ClassPrepareRequest");
314
eventRequest1 = eventRManager.createClassPrepareRequest();
315
break;
316
317
case 4:
318
log2(".....setting up ClassUnloadRequest");
319
eventRequest1 = eventRManager.createClassUnloadRequest();
320
break;
321
322
case 5:
323
log2(".....setting up MethodEntryRequest");
324
eventRequest1 = eventRManager.createMethodEntryRequest();
325
break;
326
327
case 6:
328
log2(".....setting up MethodExitRequest");
329
eventRequest1 = eventRManager.createMethodExitRequest();
330
break;
331
332
case 7:
333
log2(".....setting up ThreadDeathRequest");
334
eventRequest1 = eventRManager.createThreadDeathRequest();
335
break;
336
337
case 8:
338
log2(".....setting up ThreadStartRequest");
339
eventRequest1 = eventRManager.createThreadStartRequest();
340
break;
341
342
case 9:
343
log2(".....setting up VMDeathRequest");
344
eventRequest1 = eventRManager.createVMDeathRequest();
345
break;
346
347
case 10:
348
log2(".....setting up ExceptionRequest");
349
eventRequest1 = eventRManager.createExceptionRequest(
350
(ReferenceType)
351
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
352
true, true );
353
break;
354
355
case 11:
356
log2(".....setting up BreakpointRequest");
357
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
358
break;
359
360
361
default:
362
throw new JDITestRuntimeException("** default case 2 **");
363
}
364
365
vm.suspend();
366
log2("......eventRequest1.setEnable(true);");
367
eventRequest1.setEnabled(true);
368
log2(" checking up on eventRequest1");
369
if ( !eventRequest1.isEnabled() ) {
370
testExitCode = FAILED;
371
log3("ERROR: EventRequest is not enabled");
372
}
373
374
log2("......eventRequest1.setEnable(false);");
375
eventRequest1.setEnabled(false);
376
log2(" checking up on eventRequest1");
377
if ( eventRequest1.isEnabled() ) {
378
testExitCode = FAILED;
379
log3("ERROR: EventRequest is enabled");
380
}
381
vm.resume();
382
383
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
384
}
385
log1(" TESTING ENDS");
386
return;
387
}
388
389
}
390
391