Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2018, 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.jdwp.ThreadReference.Resume;
25
26
import java.io.*;
27
28
import nsk.share.*;
29
import nsk.share.jpda.*;
30
import nsk.share.jdwp.*;
31
32
/**
33
* Test for JDWP command: ThreadReference.Resume.
34
*
35
* See resume001.README for description of test execution.
36
*
37
* This class represents debugger part of the test.
38
* Test is executed by invoking method runIt().
39
* JDWP command is tested in the method testCommand().
40
*
41
* @see #runIt()
42
* @see #testCommand()
43
*/
44
public class resume001 {
45
46
// exit status constants
47
static final int JCK_STATUS_BASE = 95;
48
static final int PASSED = 0;
49
static final int FAILED = 2;
50
51
// communication signals constants
52
static final String READY = "ready";
53
static final String ERROR = "error";
54
static final String QUIT = "quit";
55
56
// package and classes names constants
57
static final String PACKAGE_NAME = "nsk.jdwp.ThreadReference.Resume";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "resume001";
59
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
60
61
// tested JDWP command constants
62
static final String JDWP_COMMAND_NAME = "ThreadReference.Resume";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.Resume;
64
65
// tested class name and signature constants
66
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
67
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
68
69
// name of the tested thread and statioc field with thread value
70
static final String TESTED_CLASS_FIELD_NAME = resume001a.FIELD_NAME;
71
static final String TESTED_THREAD_NAME = resume001a.THREAD_NAME;
72
73
// usual scaffold objects
74
ArgumentHandler argumentHandler = null;
75
Log log = null;
76
Binder binder = null;
77
Debugee debugee = null;
78
Transport transport = null;
79
IOPipe pipe = null;
80
81
// test passed or not
82
boolean success = true;
83
84
// -------------------------------------------------------------------
85
86
/**
87
* Start test from command line.
88
*/
89
public static void main (String argv[]) {
90
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
91
}
92
93
/**
94
* Start JCK-compilant test.
95
*/
96
public static int run(String argv[], PrintStream out) {
97
return new resume001().runIt(argv, out);
98
}
99
100
// -------------------------------------------------------------------
101
102
/**
103
* Perform test execution.
104
*/
105
public int runIt(String argv[], PrintStream out) {
106
107
// make log for debugger messages
108
argumentHandler = new ArgumentHandler(argv);
109
log = new Log(out, argumentHandler);
110
111
// execute test and display results
112
try {
113
log.display("\n>>> Preparing debugee for testing \n");
114
115
// launch debuggee
116
binder = new Binder(argumentHandler, log);
117
log.display("Launching debugee");
118
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
119
transport = debugee.getTransport();
120
pipe = debugee.createIOPipe();
121
122
// make debuggee ready for testing
123
prepareDebugee();
124
125
long threadID = 0;
126
127
// work with prepared debuggee
128
try {
129
log.display("\n>>> Obtaining requred data from debugee \n");
130
131
// query debuggee for classID of tested class
132
log.display("Getting classID by signature:\n"
133
+ " " + TESTED_CLASS_SIGNATURE);
134
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
135
log.display(" got classID: " + classID);
136
137
// query debuggee for threadID value from a static field
138
log.display("Getting threadID value from static field: "
139
+ TESTED_CLASS_FIELD_NAME);
140
threadID = queryThreadID(classID, TESTED_CLASS_FIELD_NAME);
141
log.display(" got threadID: " + threadID);
142
143
// request debuggee to suspend tested thread
144
log.display("Suspendig thread into debuggee for threadID: " + threadID);
145
debugee.suspendThread(threadID);
146
147
// perform testing JDWP command
148
log.display("\n>>> Testing JDWP command \n");
149
testCommand(threadID);
150
151
} finally {
152
153
log.display("\n>>> Finishing test \n");
154
155
// resume suspended thread
156
if (threadID != 0) {
157
log.display("Resuming potentially suspended thread");
158
debugee.resumeThread(threadID);
159
}
160
161
// quit debugee
162
quitDebugee();
163
}
164
165
} catch (Failure e) {
166
log.complain("TEST FAILED: " + e.getMessage());
167
success = false;
168
} catch (Exception e) {
169
e.printStackTrace(out);
170
log.complain("Caught unexpected exception while running the test:\n\t" + e);
171
success = false;
172
}
173
174
if (!success) {
175
log.complain("TEST FAILED");
176
return FAILED;
177
}
178
179
out.println("TEST PASSED");
180
return PASSED;
181
182
}
183
184
/**
185
* Prepare debugee for testing and waiting for ready signal.
186
*/
187
void prepareDebugee() {
188
// wait for VM_INIT event from debugee
189
log.display("Waiting for VM_INIT event");
190
debugee.waitForVMInit();
191
192
// query debugee for VM-dependent ID sizes
193
log.display("Querying for IDSizes");
194
debugee.queryForIDSizes();
195
196
// resume initially suspended debugee
197
log.display("Resuming debugee VM");
198
debugee.resume();
199
200
// wait for READY signal from debugee
201
log.display("Waiting for signal from debugee: " + READY);
202
String signal = pipe.readln();
203
log.display("Received signal from debugee: " + signal);
204
if (signal == null) {
205
throw new TestBug("Null signal received from debugee: " + signal
206
+ " (expected: " + READY + ")");
207
} else if (signal.equals(ERROR)) {
208
throw new TestBug("Debugee was not able to start tested thread"
209
+ " (received signal: " + signal + ")");
210
} else if (!signal.equals(READY)) {
211
throw new TestBug("Unexpected signal received from debugee: " + signal
212
+ " (expected: " + READY + ")");
213
}
214
}
215
216
/**
217
* Sending debugee signal to quit and waiting for it exits.
218
*/
219
void quitDebugee() {
220
// send debugee signal to quit
221
log.display("Sending signal to debugee: " + QUIT);
222
pipe.println(QUIT);
223
224
// wait for debugee exits
225
log.display("Waiting for debugee exits");
226
int code = debugee.waitFor();
227
228
// analize debugee exit status code
229
if (code == JCK_STATUS_BASE + PASSED) {
230
log.display("Debugee PASSED with exit code: " + code);
231
} else {
232
log.complain("Debugee FAILED with exit code: " + code);
233
success = false;
234
}
235
}
236
237
/**
238
* Query debuggee for threadID value of statuic field of the class.
239
*/
240
long queryThreadID(long classID, String fieldName) {
241
// get fieledID for static field (declared in the class)
242
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
243
// get value of the field
244
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
245
246
// check that value has THREAD tag
247
if (value.getTag() != JDWP.Tag.THREAD) {
248
throw new Failure("Not threadID value returned from debuggee: " + value);
249
}
250
251
// extract threadID from the value
252
long threadID = ((Long)value.getValue()).longValue();
253
return threadID;
254
}
255
256
/**
257
* Query debuggee for suspend status of the thread.
258
*/
259
int querySuspendStatus(long threadID) {
260
log.display("Getting suspend status for threadID: " + threadID);
261
CommandPacket command = new CommandPacket(JDWP.Command.ThreadReference.Status);
262
command.addObjectID(threadID);
263
ReplyPacket reply = debugee.receiveReplyFor(command);
264
265
try {
266
reply.resetPosition();
267
268
int threadStatus = reply.getInt();
269
int suspendStatus = reply.getInt();
270
log.display(" got suspendStatus: " + suspendStatusString(suspendStatus));
271
return suspendStatus;
272
} catch (BoundException e) {
273
throw new Failure("Caught BoundException while parsing reply for ThreadReference.Status:\n\t"
274
+ e);
275
}
276
}
277
278
/**
279
* Perform testing JDWP command for specified threadID.
280
*/
281
void testCommand(long threadID) {
282
// check that tested thread is not suspended before command sent
283
int suspendStatus = querySuspendStatus(threadID);
284
if (suspendStatus != JDWP.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
285
throw new Failure("SuspendStatus reports thread is not suspended before sending Resume command: "
286
+ suspendStatusString(suspendStatus));
287
} else {
288
log.display("Thread is suspended");
289
}
290
291
// create command packet and fill requred out data
292
log.display("Create command packet:");
293
log.display("Command: " + JDWP_COMMAND_NAME);
294
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
295
log.display(" threadID: " + threadID);
296
command.addObjectID(threadID);
297
command.setLength();
298
299
// send command packet to debugee
300
try {
301
log.display("Sending command packet:\n" + command);
302
transport.write(command);
303
} catch (IOException e) {
304
log.complain("Unable to send command packet:\n\t" + e);
305
success = false;
306
return;
307
}
308
309
ReplyPacket reply = new ReplyPacket();
310
311
// receive reply packet from debugee
312
try {
313
log.display("Waiting for reply packet");
314
transport.read(reply);
315
log.display("Reply packet received:\n" + reply);
316
} catch (IOException e) {
317
log.complain("Unable to read reply packet:\n\t" + e);
318
success = false;
319
return;
320
}
321
322
// check reply packet header
323
try{
324
log.display("Checking reply packet header");
325
reply.checkHeader(command.getPacketID());
326
} catch (BoundException e) {
327
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
328
success = false;
329
return;
330
}
331
332
// start parsing reply packet data
333
log.display("Parsing reply packet:");
334
reply.resetPosition();
335
336
// check for extra data in reply packet
337
if (!reply.isParsed()) {
338
log.complain("Extra trailing bytes found in reply packet at: "
339
+ reply.offsetString());
340
success = false;
341
}
342
343
// check that tested thread is suspended after Resume command sent
344
suspendStatus = querySuspendStatus(threadID);
345
if ((suspendStatus & JDWP.SuspendStatus.SUSPEND_STATUS_SUSPENDED) != 0) {
346
log.complain("SuspendStatus reports thread is suspended after Resume command sent: "
347
+ suspendStatusString(suspendStatus));
348
} else {
349
log.display("Thread is not suspended");
350
}
351
352
}
353
354
/**
355
* Return string representation of thread suspend status.
356
*/
357
private static String suspendStatusString(int status) {
358
String s = null;
359
if ((status & JDWP.SuspendStatus.SUSPEND_STATUS_SUSPENDED) != 0) {
360
s = "SUSPEND_STATUS_SUSPENDED";
361
} else if (status == 0) {
362
s = "NONE";
363
} else {
364
s = "unknown";
365
}
366
return status + "=" + s;
367
}
368
}
369
370