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