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