Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001.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.Frames;
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.Frames.
34
*
35
* See frames001.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 frames001 {
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.Frames";
58
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "frames001";
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.Frames";
63
static final int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.Frames;
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 = frames001a.FIELD_NAME;
71
static final String TESTED_THREAD_NAME = frames001a.THREAD_NAME;
72
73
// names of the methods with frames
74
static final String TESTED_METHOD_NAME = frames001a.METHOD_NAME;
75
static final String RUN_METHOD_NAME = "run";
76
77
// expected number of frames count
78
static final int START_FRAME_INDEX = 2;
79
static final int FRAMES_COUNT = frames001a.FRAMES_COUNT - START_FRAME_INDEX;
80
81
// usual scaffold objects
82
ArgumentHandler argumentHandler = null;
83
Log log = null;
84
Binder binder = null;
85
Debugee debugee = null;
86
Transport transport = null;
87
IOPipe pipe = null;
88
89
// test passed or not
90
boolean success = true;
91
92
// -------------------------------------------------------------------
93
94
/**
95
* Start test from command line.
96
*/
97
public static void main (String argv[]) {
98
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
99
}
100
101
/**
102
* Start JCK-compilant test.
103
*/
104
public static int run(String argv[], PrintStream out) {
105
return new frames001().runIt(argv, out);
106
}
107
108
// -------------------------------------------------------------------
109
110
/**
111
* Perform test execution.
112
*/
113
public int runIt(String argv[], PrintStream out) {
114
115
// make log for debugger messages
116
argumentHandler = new ArgumentHandler(argv);
117
log = new Log(out, argumentHandler);
118
119
// execute test and display results
120
try {
121
log.display("\n>>> Preparing debugee for testing \n");
122
123
// launch debuggee
124
binder = new Binder(argumentHandler, log);
125
log.display("Launching debugee");
126
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
127
transport = debugee.getTransport();
128
pipe = debugee.createIOPipe();
129
130
// make debuggee ready for testing
131
prepareDebugee();
132
133
// work with prepared debuggee
134
long threadID = 0;
135
try {
136
log.display("\n>>> Obtaining requred data from debugee \n");
137
138
// query debuggee for classID of tested class
139
log.display("Getting classID by signature:\n"
140
+ " " + TESTED_CLASS_SIGNATURE);
141
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
142
log.display(" got classID: " + classID);
143
144
// query debuggee for methodID of the recursive method
145
log.display("Getting methodID by name: " + TESTED_METHOD_NAME);
146
long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);
147
log.display(" got methodID: " + methodID);
148
149
// query debuggee for methodID of the run() method
150
log.display("Getting methodID by name: " + RUN_METHOD_NAME);
151
long runMethodID = debugee.getMethodID(classID, RUN_METHOD_NAME, true);
152
log.display(" got methodID: " + runMethodID);
153
154
// query debuggee for threadID value from a static field
155
log.display("Getting threadID value from static field: "
156
+ TESTED_CLASS_FIELD_NAME);
157
threadID = queryThreadID(classID, TESTED_CLASS_FIELD_NAME);
158
log.display(" got threadID: " + threadID);
159
160
// suspend tested thread into debyggee
161
log.display("Suspending thread into debuggee for threadID: " + threadID);
162
debugee.suspendThread(threadID);
163
log.display(" thread suspended");
164
165
// perform testing JDWP command
166
log.display("\n>>> Testing JDWP command \n");
167
testCommand(threadID, methodID, runMethodID, classID);
168
169
} finally {
170
log.display("\n>>> Finishing test \n");
171
172
// resume suspended thread
173
if (threadID != 0) {
174
log.display("Resuming suspended thread");
175
debugee.resumeThread(threadID);
176
}
177
178
// quit debugee
179
quitDebugee();
180
}
181
182
} catch (Failure e) {
183
log.complain("TEST FAILED: " + e.getMessage());
184
success = false;
185
} catch (Exception e) {
186
e.printStackTrace(out);
187
log.complain("Caught unexpected exception while running the test:\n\t" + e);
188
success = false;
189
}
190
191
if (!success) {
192
log.complain("TEST FAILED");
193
return FAILED;
194
}
195
196
out.println("TEST PASSED");
197
return PASSED;
198
199
}
200
201
/**
202
* Prepare debugee for testing and waiting for ready signal.
203
*/
204
void prepareDebugee() {
205
// wait for VM_INIT event from debugee
206
log.display("Waiting for VM_INIT event");
207
debugee.waitForVMInit();
208
209
// query debugee for VM-dependent ID sizes
210
log.display("Querying for IDSizes");
211
debugee.queryForIDSizes();
212
213
// resume initially suspended debugee
214
log.display("Resuming debugee VM");
215
debugee.resume();
216
217
// wait for READY signal from debugee
218
log.display("Waiting for signal from debugee: " + READY);
219
String signal = pipe.readln();
220
log.display("Received signal from debugee: " + signal);
221
if (signal == null) {
222
throw new TestBug("Null signal received from debugee: " + signal
223
+ " (expected: " + READY + ")");
224
} else if (signal.equals(ERROR)) {
225
throw new TestBug("Debugee was not able to start tested thread"
226
+ " (received signal: " + signal + ")");
227
} else if (!signal.equals(READY)) {
228
throw new TestBug("Unexpected signal received from debugee: " + signal
229
+ " (expected: " + READY + ")");
230
}
231
}
232
233
/**
234
* Sending debugee signal to quit and waiting for it exits.
235
*/
236
void quitDebugee() {
237
// send debugee signal to quit
238
log.display("Sending signal to debugee: " + QUIT);
239
pipe.println(QUIT);
240
241
// wait for debugee exits
242
log.display("Waiting for debugee exits");
243
int code = debugee.waitFor();
244
245
// analize debugee exit status code
246
if (code == JCK_STATUS_BASE + PASSED) {
247
log.display("Debugee PASSED with exit code: " + code);
248
} else {
249
log.complain("Debugee FAILED with exit code: " + code);
250
success = false;
251
}
252
}
253
254
/**
255
* Query debuggee for threadID value of statuic field of the class.
256
*/
257
long queryThreadID(long classID, String fieldName) {
258
// get fieledID for static field (declared in the class)
259
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
260
// get value of the field
261
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
262
263
// check that value has THREAD tag
264
if (value.getTag() != JDWP.Tag.THREAD) {
265
throw new Failure("Not threadID value returned from debuggee: " + value);
266
}
267
268
// extract threadID from the value
269
long threadID = ((Long)value.getValue()).longValue();
270
return threadID;
271
}
272
273
/**
274
* Perform testing JDWP command for specified threadID.
275
*/
276
void testCommand(long threadID, long methodID, long runMethodID, long classID) {
277
// create command packet and fill requred out data
278
log.display("Create command packet:");
279
log.display("Command: " + JDWP_COMMAND_NAME);
280
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
281
log.display(" threadID: " + threadID);
282
command.addObjectID(threadID);
283
log.display(" startFrame: " + START_FRAME_INDEX);
284
command.addInt(START_FRAME_INDEX);
285
log.display(" length: " + FRAMES_COUNT);
286
command.addInt(FRAMES_COUNT);
287
command.setLength();
288
289
// send command packet to debugee
290
try {
291
log.display("Sending command packet:\n" + command);
292
transport.write(command);
293
} catch (IOException e) {
294
log.complain("Unable to send command packet:\n\t" + e);
295
success = false;
296
return;
297
}
298
299
ReplyPacket reply = new ReplyPacket();
300
301
// receive reply packet from debugee
302
try {
303
log.display("Waiting for reply packet");
304
transport.read(reply);
305
log.display("Reply packet received:\n" + reply);
306
} catch (IOException e) {
307
log.complain("Unable to read reply packet:\n\t" + e);
308
success = false;
309
return;
310
}
311
312
// check reply packet header
313
try{
314
log.display("Checking reply packet header");
315
reply.checkHeader(command.getPacketID());
316
} catch (BoundException e) {
317
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
318
success = false;
319
return;
320
}
321
322
// start parsing reply packet data
323
log.display("Parsing reply packet:");
324
reply.resetPosition();
325
326
// extract number of frames
327
int frames = 0;
328
try {
329
frames = reply.getInt();
330
log.display(" frames: " + frames);
331
} catch (BoundException e) {
332
log.complain("Unable to extract number of frames from reply packet:\n\t"
333
+ e.getMessage());
334
success = false;
335
return;
336
}
337
338
// check that frames count is not negative
339
if (frames < 0) {
340
log.complain("Negative value of frames count in reply packet: "
341
+ frames);
342
success = false;
343
}
344
345
// check that thread has an expected state
346
if (frames != FRAMES_COUNT) {
347
log.complain("Unexpected number of frames returned: "
348
+ frames + " (expected: " + FRAMES_COUNT + ")");
349
success = false;
350
}
351
352
// use methodID of the recursive method to check all frames except the last one
353
long checkedMethodID = methodID;
354
355
// extarct frame IDs and locations
356
for (int i = 0; i < frames; i++) {
357
358
log.display(" frame #" + i + ":");
359
360
// extract frame ID
361
long frameID = 0;
362
try {
363
frameID = reply.getFrameID();
364
log.display(" frameID: " + frameID);
365
} catch (BoundException e) {
366
log.complain("Unable to extract " + i + " frameID from reply packet:\n\t"
367
+ e.getMessage());
368
success = false;
369
return;
370
}
371
372
// extract frame location
373
JDWP.Location location = null;
374
try {
375
location = reply.getLocation();
376
log.display(" location: " + location);
377
} catch (BoundException e) {
378
e.printStackTrace(log.getOutStream());
379
log.complain("Unable to extract " + i + " frame location from reply packet:\n\t"
380
+ e.getMessage());
381
success = false;
382
return;
383
}
384
385
// check that frameID is not negative integer
386
if (frameID < 0) {
387
log.complain("Negative value of " + i + " frameID: "
388
+ frameID);
389
success = false;
390
}
391
392
// check that type tag of location is CLASS tag
393
if (location.getTag() != JDWP.TypeTag.CLASS) {
394
log.complain("Unexpected type tag of " + i + " frame location: "
395
+ location.getTag() + "(expected: " + JDWP.TypeTag.CLASS + ")");
396
success = false;
397
}
398
399
// check that classID of location is equal to original classID
400
if (location.getClassID() != classID) {
401
log.complain("Unexpected classID of " + i + " frame location: "
402
+ location.getClassID() + "(expected: " + classID + ")");
403
success = false;
404
}
405
406
// use methodID of run() method for checking last frame
407
if (i == frames - 1) {
408
checkedMethodID = runMethodID;
409
}
410
411
// check that methodID of location is equal to one of original methodIDs
412
if (location.getMethodID() != checkedMethodID) {
413
log.complain("Unexpected methodID of " + i + " frame location: "
414
+ location.getMethodID() + "(expected: " + checkedMethodID + ")");
415
success = false;
416
}
417
418
// check that code index of location is not negative integer
419
if (location.getIndex() < 0) {
420
log.complain("Negative value of index of " + i + " frame location: "
421
+ location.getIndex());
422
success = false;
423
}
424
425
}
426
427
// check for extra data in reply packet
428
if (!reply.isParsed()) {
429
log.complain("Extra trailing bytes found in reply packet at: "
430
+ reply.offsetString());
431
success = false;
432
}
433
434
}
435
436
}
437
438