Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/suspendPolicy/suspendpolicy002.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.EventSet.suspendPolicy;
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
* EventSet. <BR>
40
* <BR>
41
* The test checks that results of the method <BR>
42
* <code>com.sun.jdi.EventSet.suspendPolicy()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* The test checks that for an AccessWatchpointEvent set, <BR>
46
* the method returns values corresponding to one <BR>
47
* which suspends the most threads. <BR>
48
* The cases to check include event sets containing <BR>
49
* one to three threads with all possible combinations: <BR>
50
* NONE, THREAD, ALL, NONE+THREAD, NONE+ALL, <BR>
51
* THREAD+ALL, NONE+THREAD+ALL <BR>
52
* <BR>
53
* The test has three phases and works as follows. <BR>
54
* <BR>
55
* In first phase, <BR>
56
* upon launching debuggee's VM which will be suspended, <BR>
57
* a debugger waits for the VMStartEvent within a predefined <BR>
58
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
59
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
60
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
61
* and waits for the event within the predefined time interval. <BR>
62
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
63
* Upon getting the ClassPrepareEvent, <BR>
64
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
65
* within debuggee's special methodForCommunication(). <BR>
66
* <BR>
67
* In second phase to check the above, <BR>
68
* the debugger and the debuggee perform the following loop. <BR>
69
* - The debugger sets up a AccessWatchpointRequest, resumes <BR>
70
* the debuggee, and waits for the AccessWatchpointEvent. <BR>
71
* - The debuggee invokes the special method which makes access to <BR>
72
* a predefined variable to be resulting in the event. <BR>
73
* - Upon getting new event, the debugger <BR>
74
* performs the check corresponding to the event. <BR>
75
* <BR>
76
* Note. To inform each other of needed actions, the debugger and <BR>
77
* and the debuggee use debuggee's variable "instruction". <BR>
78
* In third phase, at the end, <BR>
79
* the debuggee changes the value of the "instruction" <BR>
80
* to inform the debugger of checks finished, and both end. <BR>
81
* <BR>
82
*/
83
84
public class suspendpolicy002 extends JDIBase {
85
86
public static void main (String argv[]) {
87
88
int result = run(argv, System.out);
89
90
System.exit(result + PASS_BASE);
91
}
92
93
public static int run (String argv[], PrintStream out) {
94
95
int exitCode = new suspendpolicy002().runThis(argv, out);
96
97
if (exitCode != PASSED) {
98
System.out.println("TEST FAILED");
99
}
100
return testExitCode;
101
}
102
// ************************************************ test parameters
103
104
private String debuggeeName =
105
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy002a";
106
107
private String testedClassName =
108
"nsk.jdi.EventSet.suspendPolicy.suspendpolicy002aTestClass";
109
110
//====================================================== test program
111
112
private int runThis (String argv[], PrintStream out) {
113
114
argsHandler = new ArgumentHandler(argv);
115
logHandler = new Log(out, argsHandler);
116
Binder binder = new Binder(argsHandler, logHandler);
117
118
waitTime = argsHandler.getWaitTime() * 60000;
119
120
try {
121
log2("launching a debuggee :");
122
log2(" " + debuggeeName);
123
if (argsHandler.verbose()) {
124
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
125
} else {
126
debuggee = binder.bindToDebugee(debuggeeName);
127
}
128
if (debuggee == null) {
129
log3("ERROR: no debuggee launched");
130
return FAILED;
131
}
132
log2("debuggee launched");
133
} catch ( Exception e ) {
134
log3("ERROR: Exception : " + e);
135
log2(" test cancelled");
136
return FAILED;
137
}
138
139
debuggee.redirectOutput(logHandler);
140
141
vm = debuggee.VM();
142
143
eventQueue = vm.eventQueue();
144
if (eventQueue == null) {
145
log3("ERROR: eventQueue == null : TEST ABORTED");
146
vm.exit(PASS_BASE);
147
return FAILED;
148
}
149
150
log2("invocation of the method runTest()");
151
switch (runTest()) {
152
153
case 0 : log2("test phase has finished normally");
154
log2(" waiting for the debuggee to finish ...");
155
debuggee.waitFor();
156
157
log2("......getting the debuggee's exit status");
158
int status = debuggee.getStatus();
159
if (status != PASS_BASE) {
160
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
161
status + " != PASS_BASE");
162
testExitCode = FAILED;
163
} else {
164
log2("......debuggee returned expected exit status: " +
165
status + " == PASS_BASE");
166
}
167
break;
168
169
default : log3("ERROR: runTest() returned unexpected value");
170
171
case 1 : log3("test phase has not finished normally: debuggee is still alive");
172
log2("......forcing: vm.exit();");
173
testExitCode = FAILED;
174
try {
175
vm.exit(PASS_BASE);
176
} catch ( Exception e ) {
177
log3("ERROR: Exception : e");
178
}
179
break;
180
181
case 2 : log3("test cancelled due to VMDisconnectedException");
182
log2("......trying: vm.process().destroy();");
183
testExitCode = FAILED;
184
try {
185
Process vmProcess = vm.process();
186
if (vmProcess != null) {
187
vmProcess.destroy();
188
}
189
} catch ( Exception e ) {
190
log3("ERROR: Exception : e");
191
}
192
break;
193
}
194
195
return testExitCode;
196
}
197
198
199
/*
200
* Return value: 0 - normal end of the test
201
* 1 - ubnormal end of the test
202
* 2 - VMDisconnectedException while test phase
203
*/
204
205
private int runTest() {
206
207
try {
208
testRun();
209
210
log2("waiting for VMDeathEvent");
211
getEventSet();
212
if ( !(eventIterator.nextEvent() instanceof VMDeathEvent) ) {
213
log3("ERROR: last event is not the VMDeathEvent");
214
return 1;
215
}
216
217
return 0;
218
219
} catch ( VMDisconnectedException e ) {
220
log3("ERROR: VMDisconnectedException : " + e);
221
return 2;
222
} catch ( Exception e ) {
223
log3("ERROR: Exception : " + e);
224
return 1;
225
}
226
227
}
228
229
private void testRun()
230
throws JDITestRuntimeException, Exception {
231
232
if ( !vm.canWatchFieldAccess() ) {
233
log2("......vm.canWatchFieldAccess == false :: test cancelled");
234
vm.exit(PASS_BASE);
235
return;
236
}
237
238
239
eventRManager = vm.eventRequestManager();
240
241
log2("......getting ClassPrepareEvent for debuggee's class");
242
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
243
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
244
cpRequest.addClassFilter(debuggeeName);
245
cpRequest.enable();
246
vm.resume();
247
getEventSet();
248
cpRequest.disable();
249
250
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
251
debuggeeClass = event.referenceType();
252
253
if (!debuggeeClass.name().equals(debuggeeName))
254
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
255
log2(" received: ClassPrepareEvent for debuggeeClass");
256
257
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
258
259
String bPointMethod = "methodForCommunication";
260
String lineForComm = "lineForComm";
261
BreakpointRequest bpRequest;
262
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
263
bpRequest = settingBreakpoint(mainThread,
264
debuggeeClass,
265
bPointMethod, lineForComm, "zero");
266
bpRequest.enable();
267
268
vm.resume();
269
270
//------------------------------------------------------ testing section
271
272
log1(" TESTING BEGINS");
273
274
EventRequest eventRequest1 = null;
275
EventRequest eventRequest2 = null;
276
EventRequest eventRequest3 = null;
277
278
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
279
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
280
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
281
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
282
283
int policyExpected[] = { SUSPEND_NONE,
284
SUSPEND_THREAD,
285
SUSPEND_ALL,
286
SUSPEND_THREAD,
287
SUSPEND_ALL,
288
SUSPEND_ALL,
289
SUSPEND_ALL };
290
int policy = 0;
291
292
ReferenceType testClassReference = null;
293
294
String fieldName = "var1";
295
296
297
for (int i = 0; ; i++) {
298
299
300
breakpointForCommunication();
301
302
int instruction = ((IntegerValue)
303
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
304
if (instruction == 0) {
305
vm.resume();
306
break;
307
}
308
309
310
log1(":::::: case: # " + i);
311
312
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
313
314
switch (i) {
315
316
case 0:
317
testClassReference =
318
(ReferenceType) vm.classesByName(testedClassName).get(0);
319
320
eventRequest1 = settingAccessWatchpointRequest (mainThread,
321
testClassReference, fieldName,
322
SUSPEND_NONE, "AccessWatchpointRequest1");
323
eventRequest1.enable();
324
break;
325
326
case 1:
327
eventRequest2 = settingAccessWatchpointRequest (mainThread,
328
testClassReference, fieldName,
329
SUSPEND_THREAD, "AccessWatchpointRequest2");
330
eventRequest2.enable();
331
break;
332
333
case 2:
334
eventRequest3 = settingAccessWatchpointRequest (mainThread,
335
testClassReference, fieldName,
336
SUSPEND_ALL, "AccessWatchpointRequest3");
337
eventRequest3.enable();
338
break;
339
340
case 3:
341
eventRequest1 = settingAccessWatchpointRequest (mainThread,
342
testClassReference, fieldName,
343
SUSPEND_NONE, "AccessWatchpointRequest4");
344
eventRequest1.enable();
345
eventRequest2 = settingAccessWatchpointRequest (mainThread,
346
testClassReference, fieldName,
347
SUSPEND_THREAD, "AccessWatchpointRequest5");
348
eventRequest2.enable();
349
break;
350
351
case 4:
352
eventRequest1 = settingAccessWatchpointRequest (mainThread,
353
testClassReference, fieldName,
354
SUSPEND_NONE, "AccessWatchpointRequest6");
355
eventRequest1.enable();
356
eventRequest3 = settingAccessWatchpointRequest (mainThread,
357
testClassReference, fieldName,
358
SUSPEND_ALL, "AccessWatchpointRequest7");
359
eventRequest3.enable();
360
break;
361
362
case 5:
363
eventRequest2 = settingAccessWatchpointRequest (mainThread,
364
testClassReference, fieldName,
365
SUSPEND_THREAD, "AccessWatchpointRequest8");
366
eventRequest2.enable();
367
eventRequest3 = settingAccessWatchpointRequest (mainThread,
368
testClassReference, fieldName,
369
SUSPEND_ALL, "AccessWatchpointRequest9");
370
eventRequest3.enable();
371
break;
372
373
case 6:
374
eventRequest1 = settingAccessWatchpointRequest (mainThread,
375
testClassReference, fieldName,
376
SUSPEND_NONE, "AccessWatchpointRequest10");
377
eventRequest1.enable();
378
eventRequest2 = settingAccessWatchpointRequest (mainThread,
379
testClassReference, fieldName,
380
SUSPEND_THREAD, "AccessWatchpointRequest11");
381
eventRequest2.enable();
382
eventRequest3 = settingAccessWatchpointRequest (mainThread,
383
testClassReference, fieldName,
384
SUSPEND_ALL, "AccessWatchpointRequest12");
385
eventRequest3.enable();
386
break;
387
388
389
default:
390
throw new JDITestRuntimeException("** default case 2 **");
391
}
392
393
log2("......waiting for new AccessWatchpointEvent : " + i);
394
mainThread.resume();
395
getEventSet();
396
397
Event newEvent = eventIterator.nextEvent();
398
log2(" got new Event with propety 'number' == " + newEvent.request().getProperty("number"));
399
if ( !( newEvent instanceof AccessWatchpointEvent)) {
400
log3("ERROR: new event is not AccessWatchpointEvent");
401
testExitCode = FAILED;
402
} else {
403
log2(" Event is instanceof AccessWatchpointEvent");
404
policy = eventSet.suspendPolicy();
405
if (policy != policyExpected[i]) {
406
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
407
log3(" eventSet.suspendPolicy() == " + policy);
408
log3(" policyExpected == " + policyExpected[i]);
409
testExitCode = FAILED;
410
}
411
}
412
413
switch (i) {
414
case 0: eventRequest1.disable(); break;
415
case 1: eventRequest2.disable(); break;
416
case 2: eventRequest3.disable(); break;
417
case 3: eventRequest1.disable(); eventRequest2.disable(); break;
418
case 4: eventRequest1.disable(); eventRequest3.disable(); break;
419
case 5: eventRequest2.disable(); eventRequest3.disable(); break;
420
case 6: eventRequest1.disable(); eventRequest2.disable();
421
eventRequest3.disable(); break;
422
}
423
424
switch (policy) {
425
case SUSPEND_NONE : break;
426
case SUSPEND_THREAD : mainThread.resume(); break;
427
case SUSPEND_ALL : vm.resume(); break;
428
default: throw new JDITestRuntimeException("** default case 3 **");
429
}
430
431
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
432
}
433
log1(" TESTING ENDS");
434
return;
435
}
436
437
// ============================== test's additional methods
438
439
private AccessWatchpointRequest settingAccessWatchpointRequest (
440
ThreadReference thread,
441
ReferenceType testedClass,
442
String fieldName,
443
int suspendPolicy,
444
String property )
445
throws JDITestRuntimeException {
446
try {
447
log2("......setting up AccessWatchpointRequest:");
448
log2(" thread: " + thread + "; class: " + testedClass + "; fieldName: " + fieldName);
449
Field field = testedClass.fieldByName(fieldName);
450
451
AccessWatchpointRequest
452
awr = eventRManager.createAccessWatchpointRequest(field);
453
awr.putProperty("number", property);
454
awr.addThreadFilter(thread);
455
awr.setSuspendPolicy(suspendPolicy);
456
457
log2(" AccessWatchpointRequest has been set up");
458
return awr;
459
} catch ( Exception e ) {
460
log3("ERROR: ATTENTION: Exception within settingAccessWatchpointRequest() : " + e);
461
log3(" AccessWatchpointRequest HAS NOT BEEN SET UP");
462
throw new JDITestRuntimeException("** FAILURE to set up AccessWatchpointRequest **");
463
}
464
}
465
466
}
467
468