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/suspendpolicy012.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_EVENT_THREAD. <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 suspendpolicy012 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 suspendpolicy012().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.suspendpolicy012a";
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
try {
120
log2("launching a debuggee :");
121
log2(" " + debuggeeName);
122
if (argsHandler.verbose()) {
123
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
124
} else {
125
debuggee = binder.bindToDebugee(debuggeeName);
126
}
127
if (debuggee == null) {
128
log3("ERROR: no debuggee launched");
129
return FAILED;
130
}
131
log2("debuggee launched");
132
} catch ( Exception e ) {
133
log3("ERROR: Exception : " + e);
134
log2(" test cancelled");
135
return FAILED;
136
}
137
138
debuggee.redirectOutput(logHandler);
139
140
vm = debuggee.VM();
141
142
eventQueue = vm.eventQueue();
143
if (eventQueue == null) {
144
log3("ERROR: eventQueue == null : TEST ABORTED");
145
vm.exit(PASS_BASE);
146
return FAILED;
147
}
148
149
log2("invocation of the method runTest()");
150
switch (runTest()) {
151
152
case 0 : log2("test phase has finished normally");
153
log2(" waiting for the debuggee to finish ...");
154
debuggee.waitFor();
155
156
log2("......getting the debuggee's exit status");
157
int status = debuggee.getStatus();
158
if (status != PASS_BASE) {
159
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
160
status + " != PASS_BASE");
161
testExitCode = FAILED;
162
} else {
163
log2("......debuggee returned expected exit status: " +
164
status + " == PASS_BASE");
165
}
166
break;
167
168
default : log3("ERROR: runTest() returned unexpected value");
169
170
case 1 : log3("test phase has not finished normally: debuggee is still alive");
171
log2("......forcing: vm.exit();");
172
testExitCode = FAILED;
173
try {
174
vm.exit(PASS_BASE);
175
} catch ( Exception e ) {
176
log3("ERROR: Exception : e");
177
}
178
break;
179
180
case 2 : log3("test cancelled due to VMDisconnectedException");
181
log2("......trying: vm.process().destroy();");
182
testExitCode = FAILED;
183
try {
184
Process vmProcess = vm.process();
185
if (vmProcess != null) {
186
vmProcess.destroy();
187
}
188
} catch ( Exception e ) {
189
log3("ERROR: Exception : e");
190
}
191
break;
192
}
193
194
return testExitCode;
195
}
196
197
198
/*
199
* Return value: 0 - normal end of the test
200
* 1 - ubnormal end of the test
201
* 2 - VMDisconnectedException while test phase
202
*/
203
204
private int runTest() {
205
206
try {
207
testRun();
208
209
log2("waiting for VMDeathEvent");
210
getEventSet();
211
if ( !(eventIterator.nextEvent() instanceof VMDeathEvent) ) {
212
log3("ERROR: last event is not the VMDeathEvent");
213
return 1;
214
}
215
check();
216
217
log2("waiting for VMDisconnectEvent");
218
getEventSet();
219
if ( !(eventIterator.nextEvent() instanceof VMDisconnectEvent) ) {
220
log3("ERROR: last event is not the VMDisconnectEvent");
221
return 1;
222
}
223
224
return 0;
225
226
} catch ( VMDisconnectedException e ) {
227
log3("ERROR: VMDisconnectedException : " + e);
228
return 2;
229
} catch ( Exception e ) {
230
log3("ERROR: Exception : " + e);
231
return 1;
232
}
233
234
}
235
236
private void testRun()
237
throws JDITestRuntimeException, Exception {
238
239
if ( !vm.canRequestVMDeathEvent() ) {
240
log2("......vm.canRequestVMDeathEvent == false :: test cancelled");
241
vm.exit(PASS_BASE);
242
return;
243
}
244
245
246
eventRManager = vm.eventRequestManager();
247
248
log2("......getting ClassPrepareEvent for debuggee's class");
249
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
250
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
251
cpRequest.addClassFilter(debuggeeName);
252
cpRequest.enable();
253
vm.resume();
254
getEventSet();
255
cpRequest.disable();
256
257
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
258
debuggeeClass = event.referenceType();
259
260
if (!debuggeeClass.name().equals(debuggeeName))
261
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
262
log2(" received: ClassPrepareEvent for debuggeeClass");
263
264
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
265
266
String bPointMethod = "methodForCommunication";
267
String lineForComm = "lineForComm";
268
BreakpointRequest bpRequest;
269
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
270
bpRequest = settingBreakpoint(mainThread,
271
debuggeeClass,
272
bPointMethod, lineForComm, "zero");
273
bpRequest.enable();
274
275
vm.resume();
276
277
//------------------------------------------------------ testing section
278
279
log1(" TESTING BEGINS");
280
281
EventRequest eventRequest1 = null;
282
EventRequest eventRequest2 = null;
283
EventRequest eventRequest3 = null;
284
285
final int SUSPEND_POLICY = EventRequest.SUSPEND_NONE;
286
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
287
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
288
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
289
290
int policyExpected[] = { SUSPEND_NONE,
291
SUSPEND_THREAD,
292
SUSPEND_ALL,
293
SUSPEND_THREAD,
294
SUSPEND_ALL,
295
SUSPEND_ALL,
296
SUSPEND_ALL };
297
int policy = 0;
298
299
breakpointForCommunication();
300
301
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
302
303
eventRequest2 = settingVMDeathRequest ( SUSPEND_THREAD, "VMDeathRequest2");
304
eventRequest2.enable();
305
306
policyToCheck = policyExpected[1];
307
mainThread.resume();
308
309
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310
311
log1(" TESTING ENDS");
312
return;
313
}
314
315
// ============================== test's additional methods
316
317
private VMDeathRequest settingVMDeathRequest( int suspendPolicy,
318
String property )
319
throws JDITestRuntimeException {
320
try {
321
log2("......setting up VMDeathRequest:");
322
log2(" suspendPolicy: " + suspendPolicy + "; property: " + property);
323
324
VMDeathRequest
325
vmdr = eventRManager.createVMDeathRequest();
326
vmdr.putProperty("number", property);
327
vmdr.setSuspendPolicy(suspendPolicy);
328
329
return vmdr;
330
} catch ( Exception e ) {
331
log3("ERROR: ATTENTION: Exception within settingVMDeathRequest() : " + e);
332
log3(" VMDeathRequest HAS NOT BEEN SET UP");
333
throw new JDITestRuntimeException("** FAILURE to set up a VMDeathRequest **");
334
}
335
}
336
337
void check() {
338
log2("......checking up on eventSet.suspendPolicy()");
339
int policy = eventSet.suspendPolicy();
340
if (policy != policyToCheck) {
341
log3("ERROR: eventSet.suspendPolicy() != policyExpected");
342
log3(" eventSet.suspendPolicy() == " + policy);
343
log3(" policyExpected == " + policyToCheck);
344
testExitCode = FAILED;
345
}
346
vm.resume();
347
}
348
349
}
350
351