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