Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/isEnabled/isenabled001.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.isEnabled;
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.isEnabled()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks up on if a value returned by the method <BR>
46
* EventRequest.isEnabled() matchs a value set up with <BR>
47
* the method EventRequest.setEnabled(). <BR>
48
* The cases to test include all sub-types of EventRequest. <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 loop. <BR>
66
* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>
67
* - The debuggee prepares new check case (as if) 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 performs the check case required. <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 isenabled001 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 isenabled001().runThis(argv, out);
91
92
if (exitCode != PASSED) {
93
System.out.println("TEST FAILED");
94
}
95
return testExitCode;
96
}
97
98
// ************************************************ test parameters
99
100
private String debuggeeName =
101
"nsk.jdi.EventRequest.isEnabled.isenabled001a";
102
103
private String testedClassName =
104
"nsk.jdi.EventRequest.isEnabled.TestClass11";
105
106
//====================================================== test program
107
108
private int runThis (String argv[], PrintStream out) {
109
110
argsHandler = new ArgumentHandler(argv);
111
logHandler = new Log(out, argsHandler);
112
Binder binder = new Binder(argsHandler, logHandler);
113
114
waitTime = argsHandler.getWaitTime() * 60000;
115
116
117
try {
118
log2("launching a debuggee :");
119
log2(" " + debuggeeName);
120
if (argsHandler.verbose()) {
121
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
122
} else {
123
debuggee = binder.bindToDebugee(debuggeeName);
124
}
125
if (debuggee == null) {
126
log3("ERROR: no debuggee launched");
127
return FAILED;
128
}
129
log2("debuggee launched");
130
} catch ( Exception e ) {
131
log3("ERROR: Exception : " + e);
132
log2(" test cancelled");
133
return FAILED;
134
}
135
136
debuggee.redirectOutput(logHandler);
137
138
vm = debuggee.VM();
139
140
eventQueue = vm.eventQueue();
141
if (eventQueue == null) {
142
log3("ERROR: eventQueue == null : TEST ABORTED");
143
vm.exit(PASS_BASE);
144
return FAILED;
145
}
146
147
log2("invocation of the method runTest()");
148
switch (runTest()) {
149
150
case 0 : log2("test phase has finished normally");
151
log2(" waiting for the debuggee to finish ...");
152
debuggee.waitFor();
153
154
log2("......getting the debuggee's exit status");
155
int status = debuggee.getStatus();
156
if (status != PASS_BASE) {
157
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
158
status + " != PASS_BASE");
159
testExitCode = FAILED;
160
} else {
161
log2("......debuggee returned expected exit status: " +
162
status + " == PASS_BASE");
163
}
164
break;
165
166
default : log3("ERROR: runTest() returned unexpected value");
167
168
case 1 : log3("test phase has not finished normally: debuggee is still alive");
169
log2("......forcing: vm.exit();");
170
testExitCode = FAILED;
171
try {
172
vm.exit(PASS_BASE);
173
} catch ( Exception e ) {
174
log3("ERROR: Exception : " + e);
175
}
176
break;
177
178
case 2 : log3("test cancelled due to VMDisconnectedException");
179
log2("......trying: vm.process().destroy();");
180
testExitCode = FAILED;
181
try {
182
Process vmProcess = vm.process();
183
if (vmProcess != null) {
184
vmProcess.destroy();
185
}
186
} catch ( Exception e ) {
187
log3("ERROR: Exception : " + e);
188
}
189
break;
190
}
191
192
return testExitCode;
193
}
194
195
196
/*
197
* Return value: 0 - normal end of the test
198
* 1 - ubnormal end of the test
199
* 2 - VMDisconnectedException while test phase
200
*/
201
202
private int runTest() {
203
204
try {
205
testRun();
206
207
log2("waiting for VMDeathEvent");
208
getEventSet();
209
if (eventIterator.nextEvent() instanceof VMDeathEvent)
210
return 0;
211
212
log3("ERROR: last event is not the VMDeathEvent");
213
return 1;
214
} catch ( VMDisconnectedException e ) {
215
log3("ERROR: VMDisconnectedException : " + e);
216
return 2;
217
} catch ( Exception e ) {
218
log3("ERROR: Exception : " + e);
219
return 1;
220
}
221
222
}
223
224
private void testRun()
225
throws JDITestRuntimeException, Exception {
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
259
EventRequest eventRequest1 = null;
260
261
String fieldName1 = "var101";
262
String fieldName2 = "excObj";
263
264
ThreadReference thread1 = null;
265
String threadName1 = "thread1";
266
267
ReferenceType testClassReference = null;
268
269
270
log1(" TESTING BEGINS");
271
272
for (int i = 0; ; i++) {
273
274
vm.resume();
275
breakpointForCommunication();
276
277
int instruction = ((IntegerValue)
278
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
279
280
if (instruction == 0) {
281
vm.resume();
282
break;
283
}
284
285
log1(":::::: case: # " + i);
286
287
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
288
289
290
switch (i) {
291
292
case 0:
293
thread1 = debuggee.threadByNameOrThrow(threadName1);
294
295
log2("......setting up StepRequest");
296
eventRequest1 = eventRManager.createStepRequest
297
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
298
break;
299
300
case 1:
301
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
302
303
log2("......setting up AccessWatchpointRequest");
304
eventRequest1 = eventRManager.createAccessWatchpointRequest
305
(testClassReference.fieldByName(fieldName1));
306
break;
307
308
case 2:
309
log2(".....setting up ModificationWatchpointRequest");
310
eventRequest1 = eventRManager.createModificationWatchpointRequest
311
(testClassReference.fieldByName(fieldName1));
312
break;
313
314
case 3:
315
log2(".....setting up ClassPrepareRequest");
316
eventRequest1 = eventRManager.createClassPrepareRequest();
317
break;
318
319
case 4:
320
log2(".....setting up ClassUnloadRequest");
321
eventRequest1 = eventRManager.createClassUnloadRequest();
322
break;
323
324
case 5:
325
log2(".....setting up MethodEntryRequest");
326
eventRequest1 = eventRManager.createMethodEntryRequest();
327
break;
328
329
case 6:
330
log2(".....setting up MethodExitRequest");
331
eventRequest1 = eventRManager.createMethodExitRequest();
332
break;
333
334
case 7:
335
log2(".....setting up ThreadDeathRequest");
336
eventRequest1 = eventRManager.createThreadDeathRequest();
337
break;
338
339
case 8:
340
log2(".....setting up ThreadStartRequest");
341
eventRequest1 = eventRManager.createThreadStartRequest();
342
break;
343
344
case 9:
345
log2(".....setting up VMDeathRequest");
346
eventRequest1 = eventRManager.createVMDeathRequest();
347
break;
348
349
case 10:
350
log2(".....setting up ExceptionRequest");
351
eventRequest1 = eventRManager.createExceptionRequest(
352
(ReferenceType)
353
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
354
true, true );
355
break;
356
357
case 11:
358
log2(".....setting up BreakpointRequest");
359
eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);
360
break;
361
362
363
default:
364
throw new JDITestRuntimeException("** default case 2 **");
365
}
366
367
vm.suspend();
368
log2("......eventRequest1.setEnabled(true);");
369
eventRequest1.setEnabled(true);
370
log2(" checking up on eventRequest1");
371
if ( !eventRequest1.isEnabled() ) {
372
testExitCode = FAILED;
373
log3("ERROR: EventRequest is not enabled");
374
}
375
376
log2("......eventRequest1.setEnabled(false);");
377
eventRequest1.setEnabled(false);
378
log2(" checking up on eventRequest1");
379
if ( eventRequest1.isEnabled() ) {
380
testExitCode = FAILED;
381
log3("ERROR: EventRequest is enabled");
382
}
383
vm.resume();
384
385
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386
}
387
log1(" TESTING ENDS");
388
return;
389
}
390
391
}
392
393