Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume011.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.resume;
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.resume()</code> <BR>
43
* complies with its spec. <BR>
44
* <BR>
45
* Test case includes SUSPEND_NONE for a VMDeathEvent set. <BR>
46
* <BR>
47
* The test has three phases and works as follows. <BR>
48
* <BR>
49
* Upon launching debuggee's VM which will be suspended, <BR>
50
* a debugger waits for the VMStartEvent within a predefined <BR>
51
* time interval. If no the VMStartEvent received, the test is FAILED. <BR>
52
* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>
53
* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>
54
* and waits for the event within the predefined time interval. <BR>
55
* If no the ClassPrepareEvent received, the test is FAILED. <BR>
56
* Upon getting the ClassPrepareEvent, <BR>
57
* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>
58
* within debuggee's special methodForCommunication(). <BR>
59
* <BR>
60
* Then to check the above, <BR>
61
* the debugger and the debuggee perform the following. <BR>
62
* - The debugger sets up a VMDeathRequest, resumes <BR>
63
* the debuggee, and waits for the VMDeathEvent. <BR>
64
* - The debuggee ends to be resulting in the VMDeathEvent. <BR>
65
* - Upon getting the event, the debugger performs the check. <BR>
66
* <BR>
67
* Note. To inform each other of needed actions, the debugger and <BR>
68
* and the debuggee use debuggee's variable "instruction". <BR>
69
* <BR>
70
*/
71
72
public class resume011 extends JDIBase {
73
74
public static void main (String argv[]) {
75
76
int result = run(argv, System.out);
77
78
System.exit(result + PASS_BASE);
79
}
80
81
public static int run (String argv[], PrintStream out) {
82
83
int exitCode = new resume011().runThis(argv, out);
84
85
if (exitCode != PASSED) {
86
System.out.println("TEST FAILED");
87
}
88
return testExitCode;
89
}
90
91
// ************************************************ test parameters
92
93
private String debuggeeName =
94
"nsk.jdi.EventSet.resume.resume011a";
95
96
private String testedClassName =
97
"nsk.jdi.EventSet.resume.TestClass";
98
99
//====================================================== test program
100
101
private int runThis (String argv[], PrintStream out) {
102
103
argsHandler = new ArgumentHandler(argv);
104
logHandler = new Log(out, argsHandler);
105
Binder binder = new Binder(argsHandler, logHandler);
106
107
waitTime = argsHandler.getWaitTime() * 60000;
108
109
try {
110
log2("launching a debuggee :");
111
log2(" " + debuggeeName);
112
if (argsHandler.verbose()) {
113
debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
114
} else {
115
debuggee = binder.bindToDebugee(debuggeeName);
116
}
117
if (debuggee == null) {
118
log3("ERROR: no debuggee launched");
119
return FAILED;
120
}
121
log2("debuggee launched");
122
} catch ( Exception e ) {
123
log3("ERROR: Exception : " + e);
124
log2(" test cancelled");
125
return FAILED;
126
}
127
128
debuggee.redirectOutput(logHandler);
129
130
vm = debuggee.VM();
131
132
eventQueue = vm.eventQueue();
133
if (eventQueue == null) {
134
log3("ERROR: eventQueue == null : TEST ABORTED");
135
vm.exit(PASS_BASE);
136
return FAILED;
137
}
138
139
log2("invocation of the method runTest()");
140
switch (runTest()) {
141
142
case 0 : log2("test phase has finished normally");
143
log2(" waiting for the debuggee to finish ...");
144
debuggee.waitFor();
145
146
log2("......getting the debuggee's exit status");
147
int status = debuggee.getStatus();
148
if (status != PASS_BASE) {
149
log3("ERROR: debuggee returned UNEXPECTED exit status: " +
150
status + " != PASS_BASE");
151
testExitCode = FAILED;
152
} else {
153
log2("......debuggee returned expected exit status: " +
154
status + " == PASS_BASE");
155
}
156
break;
157
158
default : log3("ERROR: runTest() returned unexpected value");
159
160
case 1 : log3("test phase has not finished normally: debuggee is still alive");
161
log2("......forcing: vm.exit();");
162
testExitCode = FAILED;
163
try {
164
vm.exit(PASS_BASE);
165
} catch ( Exception e ) {
166
log3("ERROR: Exception : e");
167
}
168
break;
169
170
case 2 : log3("test cancelled due to VMDisconnectedException");
171
log2("......trying: vm.process().destroy();");
172
testExitCode = FAILED;
173
try {
174
Process vmProcess = vm.process();
175
if (vmProcess != null) {
176
vmProcess.destroy();
177
}
178
} catch ( Exception e ) {
179
log3("ERROR: Exception : e");
180
}
181
break;
182
}
183
184
return testExitCode;
185
}
186
187
188
/*
189
* Return value: 0 - normal end of the test
190
* 1 - ubnormal end of the test
191
* 2 - VMDisconnectedException while test phase
192
*/
193
194
private int runTest() {
195
196
try {
197
testRun();
198
199
log2("waiting for VMDeathEvent");
200
getEventSet();
201
if ( !(eventIterator.nextEvent() instanceof VMDeathEvent) ) {
202
log3("ERROR: last event is not the VMDeathEvent");
203
return 1;
204
}
205
check();
206
207
log2("waiting for VMDisconnectEvent");
208
getEventSet();
209
if ( !(eventIterator.nextEvent() instanceof VMDisconnectEvent) ) {
210
log3("ERROR: last event is not the VMDisconnectEvent");
211
return 1;
212
}
213
214
return 0;
215
216
} catch ( VMDisconnectedException e ) {
217
log3("ERROR: VMDisconnectedException : " + e);
218
return 2;
219
} catch ( Exception e ) {
220
log3("ERROR: Exception : " + e);
221
return 1;
222
}
223
224
}
225
226
private void testRun()
227
throws JDITestRuntimeException, Exception {
228
229
if ( !vm.canRequestVMDeathEvent() ) {
230
log2("......vm.canRequestVMDeathEvent == false :: test cancelled");
231
vm.exit(PASS_BASE);
232
return;
233
}
234
235
236
eventRManager = vm.eventRequestManager();
237
238
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
239
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
240
cpRequest.addClassFilter(debuggeeName);
241
242
cpRequest.enable();
243
vm.resume();
244
getEventSet();
245
cpRequest.disable();
246
247
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
248
debuggeeClass = event.referenceType();
249
250
if (!debuggeeClass.name().equals(debuggeeName))
251
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
252
253
log2(" received: ClassPrepareEvent for debuggeeClass");
254
255
String bPointMethod = "methodForCommunication";
256
String lineForComm = "lineForComm";
257
BreakpointRequest bpRequest;
258
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
259
bpRequest = settingBreakpoint(mainThread,
260
debuggeeClass,
261
bPointMethod, lineForComm, "zero");
262
bpRequest.enable();
263
264
vm.resume();
265
266
//------------------------------------------------------ testing section
267
268
log1(" TESTING BEGINS");
269
270
EventRequest eventRequest1 = null;
271
// EventRequest eventRequest2 = null;
272
// EventRequest eventRequest3 = null;
273
274
final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
275
final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
276
final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
277
278
279
280
breakpointForCommunication();
281
282
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
283
284
eventRequest1 = settingVMDeathRequest ( SUSPEND_NONE, "VMDeathRequest1");
285
eventRequest1.enable();
286
287
mainThread.resume();
288
289
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290
291
log1(" TESTING ENDS");
292
return;
293
}
294
295
// ============================== test's additional methods
296
297
private VMDeathRequest settingVMDeathRequest( int suspendPolicy,
298
String property )
299
throws JDITestRuntimeException {
300
try {
301
log2("......setting up VMDeathRequest:");
302
log2(" suspendPolicy: " + suspendPolicy + "; property: " + property);
303
304
VMDeathRequest
305
vmdr = eventRManager.createVMDeathRequest();
306
vmdr.putProperty("number", property);
307
vmdr.setSuspendPolicy(suspendPolicy);
308
309
return vmdr;
310
} catch ( Exception e ) {
311
log3("ERROR: ATTENTION: Exception within settingVMDeathRequest() : " + e);
312
log3(" VMDeathRequest HAS NOT BEEN SET UP");
313
throw new JDITestRuntimeException("** FAILURE to set up a VMDeathRequest **");
314
}
315
}
316
317
void check() {
318
log2("......checking up on eventSet.resume()");
319
try {
320
log2(" eventSet.resume(); :: no Exception expected");
321
eventSet.resume();
322
} catch ( Exception e ) {
323
log3("ERROR: Exception : " + e);
324
testExitCode = FAILED;
325
}
326
}
327
328
}
329
330