Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createThreadStartRequest/tsreg001.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.createThreadStartRequest;
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.createThreadStartRequest()</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 ThreadDeathRequest. <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 tsreg001 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 tsreg001().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.createThreadStartRequest.tsreg001a";
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
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
return 0;
204
205
log3("ERROR: last event is not the VMDeathEvent");
206
return 1;
207
} catch ( VMDisconnectedException e ) {
208
log3("ERROR: VMDisconnectedException : " + e);
209
return 2;
210
} catch ( Exception e ) {
211
log3("ERROR: Exception : " + e);
212
return 1;
213
}
214
215
}
216
217
private void testRun()
218
throws JDITestRuntimeException, Exception {
219
220
eventRManager = vm.eventRequestManager();
221
222
ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();
223
cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);
224
cpRequest.addClassFilter(debuggeeName);
225
226
cpRequest.enable();
227
vm.resume();
228
getEventSet();
229
cpRequest.disable();
230
231
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
232
debuggeeClass = event.referenceType();
233
234
if (!debuggeeClass.name().equals(debuggeeName))
235
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
236
237
log2(" received: ClassPrepareEvent for debuggeeClass");
238
239
String bPointMethod = "methodForCommunication";
240
String lineForComm = "lineForComm";
241
242
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
243
244
BreakpointRequest bpRequest = settingBreakpoint(mainThread,
245
debuggeeClass,
246
bPointMethod, lineForComm, "zero");
247
bpRequest.enable();
248
249
//------------------------------------------------------ testing section
250
251
ThreadStartRequest tsRequest1 = null;
252
253
254
log1(" TESTING BEGINS");
255
256
for (int i = 0; ; i++) {
257
258
vm.resume();
259
breakpointForCommunication();
260
261
int instruction = ((IntegerValue)
262
(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();
263
264
if (instruction == 0) {
265
vm.resume();
266
break;
267
}
268
269
log1(":::::: case: # " + i);
270
271
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
272
273
log2("......creating: tsRequest1 = eventRManager.createThreadStartRequest();");
274
tsRequest1 = eventRManager.createThreadStartRequest();
275
log2(" checking up on if request is disabled");
276
if (tsRequest1.isEnabled()) {
277
testExitCode = FAILED;
278
log3("ERROR: request is not disabled");
279
}
280
281
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282
}
283
log1(" TESTING ENDS");
284
return;
285
}
286
287
}
288
289