Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/disable/disable001.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.EventRequest.disable;
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.disable()</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.disable(). <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_ALL <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 disable001 {
80
81
//----------------------------------------------------- templete section
82
static final int PASSED = 0;
83
static final int FAILED = 2;
84
static final int PASS_BASE = 95;
85
86
//----------------------------------------------------- templete parameters
87
static final String
88
sHeader1 = "\n==> nsk/jdi/EventRequest/disable/disable001 ",
89
sHeader2 = "--> debugger: ",
90
sHeader3 = "##> debugger: ";
91
92
//----------------------------------------------------- main method
93
94
public static void main (String argv[]) {
95
96
int result = run(argv, System.out);
97
98
System.exit(result + PASS_BASE);
99
}
100
101
public static int run (String argv[], PrintStream out) {
102
103
int exitCode = new disable001().runThis(argv, out);
104
105
if (exitCode != PASSED) {
106
System.out.println("TEST FAILED");
107
}
108
return testExitCode;
109
}
110
111
//-------------------------------------------------- log procedures
112
113
private static Log logHandler;
114
115
private static void log1(String message) {
116
logHandler.display(sHeader1 + message);
117
}
118
private static void log2(String message) {
119
logHandler.display(sHeader2 + message);
120
}
121
private static void log3(String message) {
122
logHandler.complain(sHeader3 + message);
123
}
124
125
// ************************************************ test parameters
126
127
private String debuggeeName =
128
"nsk.jdi.EventRequest.disable.disable001a";
129
130
private String testedClassName =
131
"nsk.jdi.EventRequest.disable.disable001aTestClass11";
132
133
Location location = null; // !!!!!!!!!!!!! see settingBreakpoint
134
135
//====================================================== test program
136
//------------------------------------------------------ common section
137
138
static Debugee debuggee;
139
static ArgumentHandler argsHandler;
140
141
static int waitTime;
142
143
static VirtualMachine vm = null;
144
static EventRequestManager eventRManager = null;
145
static EventQueue eventQueue = null;
146
static EventSet eventSet = null;
147
static EventIterator eventIterator = null;
148
149
static ReferenceType debuggeeClass = null;
150
151
static int testExitCode = PASSED;
152
153
154
//------------------------------------------------------ methods
155
156
private int runThis (String argv[], PrintStream out) {
157
158
argsHandler = new ArgumentHandler(argv);
159
logHandler = new Log(out, argsHandler);
160
Binder binder = new Binder(argsHandler, logHandler);
161
162
waitTime = argsHandler.getWaitTime() * 60000;
163
164
try {
165
log2("launching a debuggee :");
166
log2(" " + debuggeeName);
167
if (argsHandler.verbose()) {
168
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
169
} else {
170
debuggee = binder.bindToDebugee(debuggeeName);
171
}
172
if (debuggee == null) {
173
log3("ERROR: no debuggee launched");
174
return FAILED;
175
}
176
log2("debuggee launched");
177
} catch ( Exception e ) {
178
log3("ERROR: Exception : " + e);
179
log2(" test cancelled");
180
return FAILED;
181
}
182
183
debuggee.redirectOutput(logHandler);
184
185
vm = debuggee.VM();
186
187
eventQueue = vm.eventQueue();
188
if (eventQueue == null) {
189
log3("ERROR: eventQueue == null : TEST ABORTED");
190
vm.exit(PASS_BASE);
191
return FAILED;
192
}
193
194
log2("invocation of the method runTest()");
195
switch (runTest()) {
196
197
case 0 : log2("test phase has finished normally");
198
log2(" waiting for the debuggee to finish ...");
199
debuggee.waitFor();
200
201
log2("......getting the debuggee's exit status");
202
int status = debuggee.getStatus();
203
if (status != PASS_BASE) {
204
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
205
status + " != PASS_BASE");
206
testExitCode = FAILED;
207
} else {
208
log2("......debuggee returned expected exit status: " +
209
status + " == PASS_BASE");
210
}
211
break;
212
213
default : log3("ERROR: runTest() returned unexpected value");
214
215
case 1 : log3("test phase has not finished normally: debuggee is still alive");
216
log2("......forcing: vm.exit();");
217
testExitCode = FAILED;
218
try {
219
vm.exit(PASS_BASE);
220
} catch ( Exception e ) {
221
log3("ERROR: Exception : " + e);
222
}
223
break;
224
225
case 2 : log3("test cancelled due to VMDisconnectedException");
226
log2("......trying: vm.process().destroy();");
227
testExitCode = FAILED;
228
try {
229
Process vmProcess = vm.process();
230
if (vmProcess != null) {
231
vmProcess.destroy();
232
}
233
} catch ( Exception e ) {
234
log3("ERROR: Exception : " + e);
235
}
236
break;
237
}
238
239
return testExitCode;
240
}
241
242
243
/*
244
* Return value: 0 - normal end of the test
245
* 1 - ubnormal end of the test
246
* 2 - VMDisconnectedException while test phase
247
*/
248
249
private int runTest() {
250
251
try {
252
testRun();
253
254
log2("waiting for VMDeathEvent");
255
getEventSet();
256
if (eventIterator.nextEvent() instanceof VMDeathEvent)
257
return 0;
258
259
log3("ERROR: last event is not the VMDeathEvent");
260
return 1;
261
} catch ( VMDisconnectedException e ) {
262
log3("ERROR: VMDisconnectedException : " + e);
263
return 2;
264
} catch ( Exception e ) {
265
log3("ERROR: Exception : " + e);
266
return 1;
267
}
268
269
}
270
271
private void testRun()
272
throws JDITestRuntimeException, Exception {
273
274
eventRManager = vm.eventRequestManager();
275
276
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
277
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
278
cpRequest.addClassFilter(debuggeeName);
279
280
cpRequest.enable();
281
vm.resume();
282
getEventSet();
283
cpRequest.disable();
284
285
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
286
debuggeeClass = event.referenceType();
287
288
if (!debuggeeClass.name().equals(debuggeeName))
289
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
290
291
log2(" received: ClassPrepareEvent for debuggeeClass");
292
293
String bPointMethod = "methodForCommunication";
294
String lineForComm = "lineForComm";
295
296
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
297
298
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
299
debuggeeClass,
300
bPointMethod, lineForComm, "zero");
301
bpRequest.enable();
302
303
//------------------------------------------------------ testing section
304
305
306
EventRequest eventRequest1 = null;
307
308
String fieldName1 = "var101";
309
String fieldName2 = "excObj";
310
311
ThreadReference thread1 = null;
312
String threadName1 = "thread1";
313
314
ReferenceType testClassReference = null;
315
316
317
log1(" TESTING BEGINS");
318
319
for (int i = 0; ; i++) {
320
321
vm.resume();
322
breakpointForCommunication();
323
324
int instruction = ((IntegerValue)
325
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
326
327
if (instruction == 0) {
328
vm.resume();
329
break;
330
}
331
332
log1(":::::: case: # " + i);
333
334
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
335
336
337
switch (i) {
338
339
case 0:
340
thread1 = debuggee.threadByNameOrThrow(threadName1);
341
342
log2("......setting up StepRequest");
343
eventRequest1 = eventRManager.createStepRequest
344
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
345
break;
346
347
case 1:
348
testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);
349
350
log2("......setting up AccessWatchpointRequest");
351
eventRequest1 = eventRManager.createAccessWatchpointRequest
352
(testClassReference.fieldByName(fieldName1));
353
break;
354
355
case 2:
356
log2(".....setting up ModificationWatchpointRequest");
357
eventRequest1 = eventRManager.createModificationWatchpointRequest
358
(testClassReference.fieldByName(fieldName1));
359
break;
360
361
case 3:
362
log2(".....setting up ClassPrepareRequest");
363
eventRequest1 = eventRManager.createClassPrepareRequest();
364
break;
365
366
case 4:
367
log2(".....setting up ClassUnloadRequest");
368
eventRequest1 = eventRManager.createClassUnloadRequest();
369
break;
370
371
case 5:
372
log2(".....setting up MethodEntryRequest");
373
eventRequest1 = eventRManager.createMethodEntryRequest();
374
break;
375
376
case 6:
377
log2(".....setting up MethodExitRequest");
378
eventRequest1 = eventRManager.createMethodExitRequest();
379
break;
380
381
case 7:
382
log2(".....setting up ThreadDeathRequest");
383
eventRequest1 = eventRManager.createThreadDeathRequest();
384
break;
385
386
case 8:
387
log2(".....setting up ThreadStartRequest");
388
eventRequest1 = eventRManager.createThreadStartRequest();
389
break;
390
391
case 9:
392
log2(".....setting up VMDeathRequest");
393
eventRequest1 = eventRManager.createVMDeathRequest();
394
break;
395
396
case 10:
397
log2(".....setting up ExceptionRequest");
398
eventRequest1 = eventRManager.createExceptionRequest(
399
(ReferenceType)
400
(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),
401
true, true );
402
break;
403
404
case 11:
405
log2(".....setting up BreakpointRequest");
406
eventRequest1 = eventRManager.createBreakpointRequest(location);
407
break;
408
409
410
default:
411
throw new JDITestRuntimeException("** default case 2 **");
412
}
413
414
vm.suspend();
415
log2("......eventRequest1.setEnabled(true);");
416
eventRequest1.setEnabled(true);
417
418
log2("......eventRequest1.disable();");
419
eventRequest1.disable();
420
421
log2(" checking up on eventRequest1");
422
if ( eventRequest1.isEnabled() ) {
423
testExitCode = FAILED;
424
log3("ERROR: EventRequest is still enabled");
425
}
426
eventRequest1.setEnabled(false);
427
vm.resume();
428
429
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
430
}
431
log1(" TESTING ENDS");
432
return;
433
}
434
435
/*
436
* private BreakpointRequest settingBreakpoint(ThreadReference, ReferenceType,
437
* String, String, String)
438
*
439
* It sets up a breakpoint at given line number within a given method in a given class
440
* for a given thread.
441
*
442
* Return value: BreakpointRequest object in case of success
443
*
444
* JDITestRuntimeException in case of an Exception thrown within the method
445
*/
446
447
private BreakpointRequest settingBreakpoint ( ThreadReference thread,
448
ReferenceType testedClass,
449
String methodName,
450
String bpLine,
451
String property)
452
throws JDITestRuntimeException {
453
454
log2("......setting up a breakpoint:");
455
log2(" thread: " + thread + "; class: " + testedClass +
456
"; method: " + methodName + "; line: " + bpLine);
457
458
List alllineLocations = null;
459
Location lineLocation = null;
460
BreakpointRequest breakpRequest = null;
461
462
try {
463
Method method = (Method) testedClass.methodsByName(methodName).get(0);
464
465
alllineLocations = method.allLineLocations();
466
467
int n =
468
( (IntegerValue) testedClass.getValue(testedClass.fieldByName(bpLine) ) ).value();
469
if (n > alllineLocations.size()) {
470
log3("ERROR: TEST_ERROR_IN_settingBreakpoint(): number is out of bound of method's lines");
471
} else {
472
lineLocation = (Location) alllineLocations.get(n);
473
474
// this is only for this test to get Location object
475
location = lineLocation;
476
477
try {
478
breakpRequest = eventRManager.createBreakpointRequest(lineLocation);
479
breakpRequest.putProperty("number", property);
480
breakpRequest.addThreadFilter(thread);
481
breakpRequest.setSuspendPolicy( EventRequest.SUSPEND_ALL);
482
} catch ( Exception e1 ) {
483
log3("ERROR: inner Exception within settingBreakpoint() : " + e1);
484
breakpRequest = null;
485
}
486
}
487
} catch ( Exception e2 ) {
488
log3("ERROR: ATTENTION: outer Exception within settingBreakpoint() : " + e2);
489
breakpRequest = null;
490
}
491
492
if (breakpRequest == null) {
493
log2(" A BREAKPOINT HAS NOT BEEN SET UP");
494
throw new JDITestRuntimeException("**FAILURE to set up a breakpoint**");
495
}
496
497
log2(" a breakpoint has been set up");
498
return breakpRequest;
499
}
500
501
502
private void getEventSet()
503
throws JDITestRuntimeException {
504
try {
505
// log2(" eventSet = eventQueue.remove(waitTime);");
506
eventSet = eventQueue.remove(waitTime);
507
if (eventSet == null) {
508
throw new JDITestRuntimeException("** TIMEOUT while waiting for event **");
509
}
510
// log2(" eventIterator = eventSet.eventIterator;");
511
eventIterator = eventSet.eventIterator();
512
} catch ( Exception e ) {
513
throw new JDITestRuntimeException("** EXCEPTION while waiting for event ** : " + e);
514
}
515
}
516
517
518
private void breakpointForCommunication()
519
throws JDITestRuntimeException {
520
521
log2("breakpointForCommunication");
522
getEventSet();
523
524
if (eventIterator.nextEvent() instanceof BreakpointEvent)
525
return;
526
527
throw new JDITestRuntimeException("** event IS NOT a breakpoint **");
528
}
529
530
}
531
532