Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTable/vartable001.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.Method.VariableTable;
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: Method.VariableTable.
34
*
35
* See vartable001.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 vartable001 {
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 QUIT = "quit";
54
55
// package and classes names constants
56
static final String PACKAGE_NAME = "nsk.jdwp.Method.VariableTable";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "vartable001";
58
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
59
60
// tested JDWP command constants
61
static final String JDWP_COMMAND_NAME = "Method.VariableTable";
62
static final int JDWP_COMMAND_ID = JDWP.Command.Method.VariableTable;
63
64
// tested class name and signature constants
65
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
66
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
67
68
// tested types signature conatants
69
static final String OBJECT_CLASS_SIGNATURE = "Ljava/lang/Object;";
70
static final String STRING_CLASS_SIGNATURE = "Ljava/lang/String;";
71
72
73
// tested method name constant
74
static final String TESTED_METHOD_NAME = "testedMethod";
75
76
// list of tested variables names and signatures
77
static final String variablesList[][] = {
78
// synthetic method arguments
79
{"this", TESTED_CLASS_SIGNATURE},
80
// method arguments
81
{"booleanArgument", "Z"},
82
{"byteArgument", "B"},
83
{"charArgument", "C"},
84
{"shortArgument", "S"},
85
{"intArgument", "I"},
86
{"longArgument", "J"},
87
{"floatArgument", "F"},
88
{"doubleArgument", "D"},
89
{"objectArgument", OBJECT_CLASS_SIGNATURE},
90
{"stringArgument", STRING_CLASS_SIGNATURE},
91
// local variables
92
{"booleanLocal", "Z"},
93
{"byteLocal", "B"},
94
{"charLocal", "C"},
95
{"shortLocal", "S"},
96
{"intLocal", "I"},
97
{"longLocal", "J"},
98
{"floatLocal", "F"},
99
{"doubleLocal", "D"},
100
{"objectLocal", OBJECT_CLASS_SIGNATURE},
101
{"stringLocal", STRING_CLASS_SIGNATURE}
102
};
103
static final int variablesCount = variablesList.length;
104
105
// usual scaffold objects
106
ArgumentHandler argumentHandler = null;
107
Log log = null;
108
Binder binder = null;
109
Debugee debugee = null;
110
Transport transport = null;
111
IOPipe pipe = null;
112
113
// test passed or not
114
boolean success = true;
115
116
// -------------------------------------------------------------------
117
118
/**
119
* Start test from command line.
120
*/
121
public static void main (String argv[]) {
122
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
123
}
124
125
/**
126
* Start JCK-compilant test.
127
*/
128
public static int run(String argv[], PrintStream out) {
129
return new vartable001().runIt(argv, out);
130
}
131
132
// -------------------------------------------------------------------
133
134
/**
135
* Perform test execution.
136
*/
137
public int runIt(String argv[], PrintStream out) {
138
139
// make log for debugger messages
140
argumentHandler = new ArgumentHandler(argv);
141
log = new Log(out, argumentHandler);
142
143
// execute test and display results
144
try {
145
log.display("\n>>> Preparing debugee for testing \n");
146
147
// launch debuggee
148
binder = new Binder(argumentHandler, log);
149
log.display("Launching debugee");
150
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
151
transport = debugee.getTransport();
152
pipe = debugee.createIOPipe();
153
154
// make debuggee ready for testing
155
prepareDebugee();
156
157
// work with prepared debuggee
158
try {
159
log.display("\n>>> Obtaining requred data from debugee \n");
160
161
// query debuggee for classID of tested class
162
log.display("Getting classID by signature:\n"
163
+ " " + TESTED_CLASS_SIGNATURE);
164
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
165
log.display(" got classID: " + classID);
166
167
// query debuggee for methodID of tested method (declared in the class)
168
log.display("Getting methodID by name: " + TESTED_METHOD_NAME);
169
long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);
170
log.display(" got methodID: " + methodID);
171
172
// perform testing JDWP command
173
log.display("\n>>> Testing JDWP command \n");
174
testCommand(classID, methodID);
175
176
} finally {
177
// quit debugee
178
log.display("\n>>> Finishing test \n");
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.equals(READY)) {
222
throw new TestBug("Unexpected signal received from debugee: " + signal
223
+ " (expected: " + READY + ")");
224
}
225
}
226
227
/**
228
* Sending debugee signal to quit and waiting for it exits.
229
*/
230
void quitDebugee() {
231
// send debugee signal to quit
232
log.display("Sending signal to debugee: " + QUIT);
233
pipe.println(QUIT);
234
235
// wait for debugee exits
236
log.display("Waiting for debugee exits");
237
int code = debugee.waitFor();
238
239
// analize debugee exit status code
240
if (code == JCK_STATUS_BASE + PASSED) {
241
log.display("Debugee PASSED with exit code: " + code);
242
} else {
243
log.complain("Debugee FAILED with exit code: " + code);
244
success = false;
245
}
246
}
247
248
/**
249
* Perform testing JDWP command for specified TypeID.
250
*/
251
void testCommand(long classID, long methodID) {
252
// create command packet and fill requred out data
253
log.display("Create command packet:");
254
log.display("Command: " + JDWP_COMMAND_NAME);
255
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
256
log.display(" referenceTypeID: " + classID);
257
command.addReferenceTypeID(classID);
258
log.display(" methodID: " + methodID);
259
command.addMethodID(methodID);
260
command.setLength();
261
262
// send command packet to debugee
263
try {
264
log.display("Sending command packet:\n" + command);
265
transport.write(command);
266
} catch (IOException e) {
267
log.complain("Unable to send command packet:\n\t" + e);
268
success = false;
269
return;
270
}
271
272
ReplyPacket reply = new ReplyPacket();
273
274
// receive reply packet from debugee
275
try {
276
log.display("Waiting for reply packet");
277
transport.read(reply);
278
log.display("Reply packet received:\n" + reply);
279
} catch (IOException e) {
280
log.complain("Unable to read reply packet:\n\t" + e);
281
success = false;
282
return;
283
}
284
285
// check reply packet header
286
try{
287
log.display("Checking reply packet header");
288
reply.checkHeader(command.getPacketID());
289
} catch (BoundException e) {
290
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
291
success = false;
292
}
293
294
// start parsing reply packet data
295
log.display("Parsing reply packet:");
296
reply.resetPosition();
297
298
// clear list of found variables
299
int[] foundVariablesList = new int[variablesCount];
300
for (int i = 0; i < variablesCount; i++) {
301
foundVariablesList[i] = 0;
302
}
303
304
// extract and check reply data
305
306
// extract number of argumnets
307
int argCount = 0;
308
try {
309
argCount = reply.getInt();
310
log.display(" argCount: " + argCount);
311
} catch (BoundException e) {
312
log.complain("Unable to extract number of arguments from reply packet:\n\t"
313
+ e.getMessage());
314
success = false;
315
return;
316
}
317
318
// check that number of arguments is not negative
319
if (argCount < 0) {
320
log.complain("Negative of arguments in reply packet: " + argCount);
321
success = false;
322
}
323
324
// extract number of slots
325
int slots = 0;
326
try {
327
slots = reply.getInt();
328
log.display(" slots: " + slots);
329
} catch (BoundException e) {
330
log.complain("Unable to extract number of slots from reply packet:\n\t"
331
+ e.getMessage());
332
success = false;
333
return;
334
}
335
336
// check that number of slots is not negative
337
if (slots < 0) {
338
log.complain("Negative value of end code index in reply packet: " + slots);
339
success = false;
340
}
341
342
// check that start code is not less than expected
343
if (slots < variablesCount) {
344
log.complain("Number of slots (" + slots
345
+ ") is less than expected (" + variablesCount + ")");
346
success = false;
347
}
348
349
// extract and check each slot attributes
350
for (int i = 0; i < slots; i++) {
351
log.display(" slot #" + i + ":");
352
353
// extract code index of a slot
354
long codeIndex = 0;
355
try {
356
codeIndex = reply.getLong();
357
log.display(" codeIndex: " + codeIndex);
358
} catch (BoundException e) {
359
log.complain("Unable to extract code index of slot #" + i
360
+ " from reply packet:\n\t"
361
+ e.getMessage());
362
success = false;
363
return;
364
}
365
366
// check that code index is not negative
367
if (codeIndex < 0) {
368
log.complain("Negative code index of slot #" + i + ":" + codeIndex);
369
success = false;
370
}
371
372
// extract name of a slot
373
String name = null;
374
try {
375
name = reply.getString();
376
log.display(" name: " + name);
377
} catch (BoundException e) {
378
log.complain("Unable to extract name of slot #" + i
379
+ " from reply packet:\n\t"
380
+ e.getMessage());
381
success = false;
382
return;
383
}
384
385
// extract signature of a slot
386
String signature = null;
387
try {
388
signature = reply.getString();
389
log.display(" signature: " + signature);
390
} catch (BoundException e) {
391
log.complain("Unable to extract signature of slot #" + i
392
+ " from reply packet:\n\t"
393
+ e.getMessage());
394
success = false;
395
return;
396
}
397
398
// extract code length
399
int length = 0;
400
try {
401
length = reply.getInt();
402
log.display(" length: " + length);
403
} catch (BoundException e) {
404
log.complain("Unable to extract code length for slot #" + i
405
+ " from reply packet:\n\t"
406
+ e.getMessage());
407
success = false;
408
return;
409
}
410
411
// extract code length
412
int slot = 0;
413
try {
414
slot = reply.getInt();
415
log.display(" slot: " + length);
416
} catch (BoundException e) {
417
log.complain("Unable to extract slot index of slot #" + i
418
+ " from reply packet:\n\t"
419
+ e.getMessage());
420
success = false;
421
return;
422
}
423
424
// find slot name into list of expected variables
425
int found = -1;
426
for (int j = 0; j < variablesCount; j++) {
427
if (variablesList[j][0].equals(name)) {
428
found = j;
429
break;
430
}
431
}
432
433
// check if slot is found and not duplicated
434
if (found >= 0) {
435
if (foundVariablesList[found] > 0) {
436
log.complain("Slot #" + i + " is duplicated "
437
+ foundVariablesList[found] + " times: "
438
+ name);
439
success = false;
440
/*
441
} else {
442
log.display("Found expected variable #" + found + ": "
443
+ variablesList[found][0]);
444
*/
445
}
446
foundVariablesList[found]++;
447
448
// check slot signature
449
if (!variablesList[found][1].equals(signature)) {
450
log.complain("Unexpected signature for slot #" + i + ": " + signature
451
+ " (expected: " + variablesList[found][1] + ")");
452
success = false;
453
}
454
} else {
455
log.display("Unexpected slot #" + i + " (may be synthetic): " + name);
456
}
457
458
// check that code length is not negative
459
if (length < 0) {
460
log.complain("Code length for slot #" + i + " is negative: " + length);
461
success = false;
462
}
463
464
// check that slot index is not negative
465
if (slot < 0) {
466
log.complain("Index of slot #" + i + " is negative: " + slot);
467
success = false;
468
}
469
}
470
471
// check for extra data in reply packet
472
if (!reply.isParsed()) {
473
log.complain("Extra trailing bytes found in reply packet at: "
474
+ reply.offsetString());
475
success = false;
476
}
477
478
// check that all expected variables found
479
for (int i = 0; i < variablesCount; i++) {
480
if (foundVariablesList[i] <= 0) {
481
log.complain("No slot found in reply packet for variable: "
482
+ variablesList[i][0]);
483
success = false;
484
}
485
}
486
487
}
488
489
}
490
491