Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Name/name001.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.Name;
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.Name.
34
*
35
* See name001.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 name001 {
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.Name";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "name001";
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.Name";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.Name;
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 = name001a.FIELD_NAME;
71
static final String TESTED_THREAD_NAME = name001a.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 name001().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
// work with prepared debuggee
126
try {
127
log.display("\n>>> Obtaining requred data from debugee \n");
128
129
// query debuggee for classID of tested class
130
log.display("Getting classID by signature:\n"
131
+ " " + TESTED_CLASS_SIGNATURE);
132
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
133
log.display(" got classID: " + classID);
134
135
// query debuggee for threadID value from a static field
136
log.display("Getting threadID value from static field: "
137
+ TESTED_CLASS_FIELD_NAME);
138
long threadID = queryThreadID(classID, TESTED_CLASS_FIELD_NAME);
139
log.display(" got threadID: " + threadID);
140
141
// perform testing JDWP command
142
log.display("\n>>> Testing JDWP command \n");
143
testCommand(threadID);
144
145
} finally {
146
// quit debugee
147
log.display("\n>>> Finishing test \n");
148
quitDebugee();
149
}
150
151
} catch (Failure e) {
152
log.complain("TEST FAILED: " + e.getMessage());
153
success = false;
154
} catch (Exception e) {
155
e.printStackTrace(out);
156
log.complain("Caught unexpected exception while running the test:\n\t" + e);
157
success = false;
158
}
159
160
if (!success) {
161
log.complain("TEST FAILED");
162
return FAILED;
163
}
164
165
out.println("TEST PASSED");
166
return PASSED;
167
168
}
169
170
/**
171
* Prepare debugee for testing and waiting for ready signal.
172
*/
173
void prepareDebugee() {
174
// wait for VM_INIT event from debugee
175
log.display("Waiting for VM_INIT event");
176
debugee.waitForVMInit();
177
178
// query debugee for VM-dependent ID sizes
179
log.display("Querying for IDSizes");
180
debugee.queryForIDSizes();
181
182
// resume initially suspended debugee
183
log.display("Resuming debugee VM");
184
debugee.resume();
185
186
// wait for READY signal from debugee
187
log.display("Waiting for signal from debugee: " + READY);
188
String signal = pipe.readln();
189
log.display("Received signal from debugee: " + signal);
190
if (signal == null) {
191
throw new TestBug("Null signal received from debugee: " + signal
192
+ " (expected: " + READY + ")");
193
} else if (signal.equals(ERROR)) {
194
throw new TestBug("Debugee was not able to start tested thread"
195
+ " (received signal: " + signal + ")");
196
} else if (!signal.equals(READY)) {
197
throw new TestBug("Unexpected signal received from debugee: " + signal
198
+ " (expected: " + READY + ")");
199
}
200
}
201
202
/**
203
* Sending debugee signal to quit and waiting for it exits.
204
*/
205
void quitDebugee() {
206
// send debugee signal to quit
207
log.display("Sending signal to debugee: " + QUIT);
208
pipe.println(QUIT);
209
210
// wait for debugee exits
211
log.display("Waiting for debugee exits");
212
int code = debugee.waitFor();
213
214
// analize debugee exit status code
215
if (code == JCK_STATUS_BASE + PASSED) {
216
log.display("Debugee PASSED with exit code: " + code);
217
} else {
218
log.complain("Debugee FAILED with exit code: " + code);
219
success = false;
220
}
221
}
222
223
/**
224
* Query debuggee for threadID value of statuic field of the class.
225
*/
226
long queryThreadID(long classID, String fieldName) {
227
// get fieledID for static field (declared in the class)
228
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
229
// get value of the field
230
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
231
232
// check that value has THREAD tag
233
if (value.getTag() != JDWP.Tag.THREAD) {
234
throw new Failure("Not threadID value returned from debuggee: " + value);
235
}
236
237
// extract threadID from the value
238
long threadID = ((Long)value.getValue()).longValue();
239
return threadID;
240
}
241
242
/**
243
* Perform testing JDWP command for specified threadID.
244
*/
245
void testCommand(long threadID) {
246
// create command packet and fill requred out data
247
log.display("Create command packet:");
248
log.display("Command: " + JDWP_COMMAND_NAME);
249
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
250
log.display(" threadID: " + threadID);
251
command.addObjectID(threadID);
252
command.setLength();
253
254
// send command packet to debugee
255
try {
256
log.display("Sending command packet:\n" + command);
257
transport.write(command);
258
} catch (IOException e) {
259
log.complain("Unable to send command packet:\n\t" + e);
260
success = false;
261
return;
262
}
263
264
ReplyPacket reply = new ReplyPacket();
265
266
// receive reply packet from debugee
267
try {
268
log.display("Waiting for reply packet");
269
transport.read(reply);
270
log.display("Reply packet received:\n" + reply);
271
} catch (IOException e) {
272
log.complain("Unable to read reply packet:\n\t" + e);
273
success = false;
274
return;
275
}
276
277
// check reply packet header
278
try{
279
log.display("Checking reply packet header");
280
reply.checkHeader(command.getPacketID());
281
} catch (BoundException e) {
282
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
283
success = false;
284
return;
285
}
286
287
// start parsing reply packet data
288
log.display("Parsing reply packet:");
289
reply.resetPosition();
290
291
// extract thread name
292
String threadName = null;
293
try {
294
threadName = reply.getString();
295
log.display(" threadName: " + threadName);
296
} catch (BoundException e) {
297
log.complain("Unable to extract thread name from reply packet:\n\t"
298
+ e.getMessage());
299
success = false;
300
return;
301
}
302
303
// check that thread name is equal to the expected one
304
if (!threadName.equals(TESTED_THREAD_NAME)) {
305
log.complain("Unexpected thread name returned in the reply packet: "
306
+ threadName + " (expected: " + TESTED_THREAD_NAME + ")");
307
success = false;
308
}
309
310
// check for extra data in reply packet
311
if (!reply.isParsed()) {
312
log.complain("Extra trailing bytes found in reply packet at: "
313
+ reply.offsetString());
314
success = false;
315
}
316
}
317
318
}
319
320