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/suspendpolicy013.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 a VMDeathEvent 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 set containing one more <BR>
49
* VMDeathRequest with suspendPolicy SUSPEND_ALL. <BR>
50
* <BR>
51
* The test has three phases and works as follows. <BR>
52
* <BR>
53
* In first phase, <BR>
54
* upon launching debuggee's VM which will be suspended, <BR>
55
* a debugger waits for the VMStartEvent within a predefined <BR>
56
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
57
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
58
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
59
* and waits for the event within the predefined time interval. <BR>
60
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
61
* Upon getting the ClassPrepareEvent, <BR>
62
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
63
* within debuggee's special methodForCommunication(). <BR>
64
* <BR>
65
* In second phase to check the above, <BR>
66
* the debugger and the debuggee perform the following loop. <BR>
67
* - The debugger sets up a VMDeathRequest, resumes <BR>
68
* the debuggee, and waits for the VMDeathEvent. <BR>
69
* - The debuggee ends to be resulting in the event. <BR>
70
* - Upon getting new event, the debugger <BR>
71
* performs the check corresponding to the event. <BR>
72
* <BR>
73
* Note. To inform each other of needed actions, the debugger and <BR>
74
* and the debuggee use debuggee's variable "instruction". <BR>
75
* In third phase, at the end, <BR>
76
* the debuggee changes the value of the "instruction" <BR>
77
* to inform the debugger of checks finished, and both end. <BR>
78
* <BR>
79
*/
80
81
public class suspendpolicy013 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 suspendpolicy013().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.EventSet.suspendPolicy.suspendpolicy013a";
104
105
private String testedClassName =
106
"nsk.jdi.EventSet.suspendPolicy.TestClass";
107
108
//====================================================== test program
109
110
int policyToCheck = 0;
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
check();
217
218
log2("waiting for VMDisconnectEvent");
219
getEventSet();
220
if ( !(eventIterator.nextEvent() instanceof VMDisconnectEvent) ) {
221
log3("ERROR: last event is not the VMDisconnectEvent");
222
return 1;
223
}
224
225
return 0;
226
227
} catch ( VMDisconnectedException e ) {
228
log3("ERROR: VMDisconnectedException : " + e);
229
return 2;
230
} catch ( Exception e ) {
231
log3("ERROR: Exception : " + e);
232
return 1;
233
}
234
235
}
236
237
private void testRun()
238
throws JDITestRuntimeException, Exception {
239
240
if ( !vm.canRequestVMDeathEvent() ) {
241
log2("......vm.canRequestVMDeathEvent == false :: test cancelled");
242
vm.exit(PASS_BASE);
243
return;
244
}
245
246
247
eventRManager = vm.eventRequestManager();
248
249
log2("......getting ClassPrepareEvent for debuggee's class");
250
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
251
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
252
cpRequest.addClassFilter(debuggeeName);
253
cpRequest.enable();
254
vm.resume();
255
getEventSet();
256
cpRequest.disable();
257
258
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
259
debuggeeClass = event.referenceType();
260
261
if (!debuggeeClass.name().equals(debuggeeName))
262
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
263
log2(" received: ClassPrepareEvent for debuggeeClass");
264
265
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
266
267
String bPointMethod = "methodForCommunication";
268
String lineForComm = "lineForComm";
269
BreakpointRequest bpRequest;
270
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
271
bpRequest = settingBreakpoint(mainThread,
272
debuggeeClass,
273
bPointMethod, lineForComm, "zero");
274
bpRequest.enable();
275
276
vm.resume();
277
278
//------------------------------------------------------ testing section
279
280
log1(" TESTING BEGINS");
281
282
EventRequest eventRequest1 = null;
283
EventRequest eventRequest2 = null;
284
EventRequest eventRequest3 = null;
285
286
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
287
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
288
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
289
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
290
291
int policyExpected[] = { SUSPEND_NONE,
292
SUSPEND_THREAD,
293
SUSPEND_ALL,
294
SUSPEND_THREAD,
295
SUSPEND_ALL,
296
SUSPEND_ALL,
297
SUSPEND_ALL };
298
int policy = 0;
299
300
breakpointForCommunication();
301
302
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
303
304
eventRequest3 = settingVMDeathRequest ( SUSPEND_ALL, "VMDeathRequest3");
305
eventRequest3.enable();
306
307
policyToCheck = policyExpected[2];
308
mainThread.resume();
309
310
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311
312
log1(" TESTING ENDS");
313
return;
314
}
315
316
// ============================== test's additional methods
317
318
private VMDeathRequest settingVMDeathRequest( int suspendPolicy,
319
String property )
320
throws JDITestRuntimeException {
321
try {
322
log2("......setting up VMDeathRequest:");
323
log2(" suspendPolicy: " + suspendPolicy + "; property: " + property);
324
325
VMDeathRequest
326
vmdr = eventRManager.createVMDeathRequest();
327
vmdr.putProperty("number", property);
328
vmdr.setSuspendPolicy(suspendPolicy);
329
330
return vmdr;
331
} catch ( Exception e ) {
332
log3("ERROR: ATTENTION: Exception within settingVMDeathRequest() : " + e);
333
log3(" VMDeathRequest HAS NOT BEEN SET UP");
334
throw new JDITestRuntimeException("** FAILURE to set up a VMDeathRequest **");
335
}
336
}
337
338
void check() {
339
log2("......checking up on eventSet.suspendPolicy()");
340
int policy = eventSet.suspendPolicy();
341
if (policy != policyToCheck) {
342
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
343
log3(" eventSet.suspendPolicy() == " + policy);
344
log3(" policyExpected == " + policyToCheck);
345
testExitCode = FAILED;
346
}
347
vm.resume();
348
}
349
350
}
351
352