Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001.java
41161 views
1
/*
2
* Copyright (c) 2004, 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.VariableTableWithGeneric;
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.VariableTableWithGeneric.
34
*
35
* See vartblwithgen001.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 vartblwithgen001 {
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.VariableTableWithGeneric";
57
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "vartblwithgen001";
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.VariableTableWithGeneric";
62
static final int JDWP_COMMAND_ID = JDWP.Command.Method.VariableTableWithGeneric;
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
static final String THIS_GENERIC_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + "<TT;TN;>" + ";";
68
69
// tested types signature conatants
70
static final String OBJECT_CLASS_SIGNATURE = "Ljava/lang/Object;";
71
static final String STRING_CLASS_SIGNATURE = "Ljava/lang/String;";
72
73
74
// tested method name constant
75
static final String TESTED_METHOD_NAME = "testedMethod";
76
77
// list of tested variables names and signatures
78
static final String variablesList[][] = {
79
80
// synthetic arguments
81
{"this", TESTED_CLASS_SIGNATURE, THIS_GENERIC_SIGNATURE},
82
83
// not generic arguments
84
{"arg11PrimBoolean", "Z", ""},
85
{"arg12PrimInt", "I", ""},
86
{"arg13Object", "Ljava/lang/Object;", ""},
87
{"arg14String", "Ljava/lang/String;", ""},
88
{"arg15PrimArrShort", "[S", ""},
89
{"arg16ObjArrObject", "[Ljava/lang/Object;", ""},
90
91
// generic arguments
92
{"arg21GenObject", "Ljava/lang/Object;", "TT;"},
93
{"arg22GenNumber", "Ljava/lang/Number;", "TN;"},
94
{"arg23GenObjectArr", "[Ljava/lang/Object;", "[TT;"},
95
{"arg24GenNumberArr", "[Ljava/lang/Number;", "[TN;"},
96
{"arg25GenObjectList", "Ljava/util/List;", "Ljava/util/List<TT;>;"},
97
{"arg26GenNumberList", "Ljava/util/List;", "Ljava/util/List<TN;>;"},
98
{"arg27GenObjectDerivedList", "Ljava/util/List;", "Ljava/util/List<+TT;>;"},
99
{"arg28GenNumberDerivedList", "Ljava/util/List;", "Ljava/util/List<+TN;>;"},
100
101
// not generic variables
102
{"var11PrimBoolean", "Z", ""},
103
{"var12PrimInt", "I", ""},
104
{"var13Object", "Ljava/lang/Object;", ""},
105
{"var14String", "Ljava/lang/String;", ""},
106
{"var15PrimArrShort", "[S", ""},
107
{"var16ObjArrObject", "[Ljava/lang/Object;", ""},
108
109
// generic variables
110
{"var21GenObject", "Ljava/lang/Object;", "TT;"},
111
{"var22GenNumber", "Ljava/lang/Number;", "TN;"},
112
{"var23GenObjectArr", "[Ljava/lang/Object;", "[TT;"},
113
{"var24GenNumberArr", "[Ljava/lang/Number;", "[TN;"},
114
{"var25GenObjectList", "Ljava/util/List;", "Ljava/util/List<TT;>;"},
115
{"var26GenNumberList", "Ljava/util/List;", "Ljava/util/List<TN;>;"},
116
{"var27GenObjectDerivedList", "Ljava/util/List;", "Ljava/util/List<+TT;>;"},
117
{"var28GenNumberDerivedList", "Ljava/util/List;", "Ljava/util/List<+TN;>;"},
118
119
};
120
static final int variablesCount = variablesList.length;
121
122
// usual scaffold objects
123
ArgumentHandler argumentHandler = null;
124
Log log = null;
125
Binder binder = null;
126
Debugee debugee = null;
127
Transport transport = null;
128
IOPipe pipe = null;
129
130
// test passed or not
131
boolean success = true;
132
133
// -------------------------------------------------------------------
134
135
/**
136
* Start test from command line.
137
*/
138
public static void main (String argv[]) {
139
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
140
}
141
142
/**
143
* Start JCK-compilant test.
144
*/
145
public static int run(String argv[], PrintStream out) {
146
return new vartblwithgen001().runIt(argv, out);
147
}
148
149
// -------------------------------------------------------------------
150
151
/**
152
* Perform test execution.
153
*/
154
public int runIt(String argv[], PrintStream out) {
155
156
// make log for debugger messages
157
argumentHandler = new ArgumentHandler(argv);
158
log = new Log(out, argumentHandler);
159
160
// execute test and display results
161
try {
162
log.display("\n>>> Preparing debugee for testing \n");
163
164
// launch debuggee
165
binder = new Binder(argumentHandler, log);
166
log.display("Launching debugee");
167
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
168
transport = debugee.getTransport();
169
pipe = debugee.createIOPipe();
170
171
// make debuggee ready for testing
172
prepareDebugee();
173
174
// work with prepared debuggee
175
try {
176
log.display("\n>>> Obtaining requred data from debugee \n");
177
178
// query debuggee for classID of tested class
179
log.display("Getting classID by signature:\n"
180
+ " " + TESTED_CLASS_SIGNATURE);
181
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
182
log.display(" got classID: " + classID);
183
184
// query debuggee for methodID of tested method (declared in the class)
185
log.display("Getting methodID by name: " + TESTED_METHOD_NAME);
186
long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);
187
log.display(" got methodID: " + methodID);
188
189
// perform testing JDWP command
190
log.display("\n>>> Testing JDWP command \n");
191
testCommand(classID, methodID);
192
193
} finally {
194
// quit debugee
195
log.display("\n>>> Finishing test \n");
196
quitDebugee();
197
}
198
199
} catch (Failure e) {
200
log.complain("TEST FAILED: " + e.getMessage());
201
success = false;
202
} catch (Exception e) {
203
e.printStackTrace(out);
204
log.complain("Caught unexpected exception while running the test:\n\t" + e);
205
success = false;
206
}
207
208
if (!success) {
209
log.complain("TEST FAILED");
210
return FAILED;
211
}
212
213
out.println("TEST PASSED");
214
return PASSED;
215
216
}
217
218
/**
219
* Prepare debugee for testing and waiting for ready signal.
220
*/
221
void prepareDebugee() {
222
// wait for VM_INIT event from debugee
223
log.display("Waiting for VM_INIT event");
224
debugee.waitForVMInit();
225
226
// query debugee for VM-dependent ID sizes
227
log.display("Querying for IDSizes");
228
debugee.queryForIDSizes();
229
230
// resume initially suspended debugee
231
log.display("Resuming debugee VM");
232
debugee.resume();
233
234
// wait for READY signal from debugee
235
log.display("Waiting for signal from debugee: " + READY);
236
String signal = pipe.readln();
237
log.display("Received signal from debugee: " + signal);
238
if (! signal.equals(READY)) {
239
throw new TestBug("Unexpected signal received from debugee: " + signal
240
+ " (expected: " + READY + ")");
241
}
242
}
243
244
/**
245
* Sending debugee signal to quit and waiting for it exits.
246
*/
247
void quitDebugee() {
248
// send debugee signal to quit
249
log.display("Sending signal to debugee: " + QUIT);
250
pipe.println(QUIT);
251
252
// wait for debugee exits
253
log.display("Waiting for debugee exits");
254
int code = debugee.waitFor();
255
256
// analize debugee exit status code
257
if (code == JCK_STATUS_BASE + PASSED) {
258
log.display("Debugee PASSED with exit code: " + code);
259
} else {
260
log.complain("Debugee FAILED with exit code: " + code);
261
success = false;
262
}
263
}
264
265
/**
266
* Perform testing JDWP command for specified TypeID.
267
*/
268
void testCommand(long classID, long methodID) {
269
// create command packet and fill requred out data
270
log.display("Create command packet:");
271
log.display("Command: " + JDWP_COMMAND_NAME);
272
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
273
log.display(" referenceTypeID: " + classID);
274
command.addReferenceTypeID(classID);
275
log.display(" methodID: " + methodID);
276
command.addMethodID(methodID);
277
command.setLength();
278
279
// send command packet to debugee
280
try {
281
log.display("Sending command packet:\n" + command);
282
transport.write(command);
283
} catch (IOException e) {
284
log.complain("Unable to send command packet:\n\t" + e);
285
success = false;
286
return;
287
}
288
289
ReplyPacket reply = new ReplyPacket();
290
291
// receive reply packet from debugee
292
try {
293
log.display("Waiting for reply packet");
294
transport.read(reply);
295
log.display("Reply packet received:\n" + reply);
296
} catch (IOException e) {
297
log.complain("Unable to read reply packet:\n\t" + e);
298
success = false;
299
return;
300
}
301
302
// check reply packet header
303
try{
304
log.display("Checking reply packet header");
305
reply.checkHeader(command.getPacketID());
306
} catch (BoundException e) {
307
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
308
success = false;
309
}
310
311
// start parsing reply packet data
312
log.display("Parsing reply packet:");
313
reply.resetPosition();
314
315
// clear list of found variables
316
int[] foundVariablesList = new int[variablesCount];
317
for (int i = 0; i < variablesCount; i++) {
318
foundVariablesList[i] = 0;
319
}
320
321
// extract and check reply data
322
323
// extract number of argumnets
324
int argCount = 0;
325
try {
326
argCount = reply.getInt();
327
log.display(" argCount: " + argCount);
328
} catch (BoundException e) {
329
log.complain("Unable to extract number of arguments from reply packet:\n\t"
330
+ e.getMessage());
331
success = false;
332
return;
333
}
334
335
// check that number of arguments is not negative
336
if (argCount < 0) {
337
log.complain("Negative of arguments in reply packet: " + argCount);
338
success = false;
339
}
340
341
// extract number of slots
342
int slots = 0;
343
try {
344
slots = reply.getInt();
345
log.display(" slots: " + slots);
346
} catch (BoundException e) {
347
log.complain("Unable to extract number of slots from reply packet:\n\t"
348
+ e.getMessage());
349
success = false;
350
return;
351
}
352
353
// check that number of slots is not negative
354
if (slots < 0) {
355
log.complain("Negative value of end code index in reply packet: " + slots);
356
success = false;
357
}
358
359
// check that start code is not less than expected
360
if (slots < variablesCount) {
361
log.complain("Number of slots (" + slots
362
+ ") is less than expected (" + variablesCount + ")");
363
success = false;
364
}
365
366
// extract and check each slot attributes
367
for (int i = 0; i < slots; i++) {
368
log.display(" slot #" + i + ":");
369
370
// extract code index of a slot
371
long codeIndex = 0;
372
try {
373
codeIndex = reply.getLong();
374
log.display(" codeIndex: " + codeIndex);
375
} catch (BoundException e) {
376
log.complain("Unable to extract code index of slot #" + i
377
+ " from reply packet:\n\t"
378
+ e.getMessage());
379
success = false;
380
return;
381
}
382
383
// check that code index is not negative
384
if (codeIndex < 0) {
385
log.complain("Negative code index of slot #" + i + ":" + codeIndex);
386
success = false;
387
}
388
389
// extract name of a slot
390
String name = null;
391
try {
392
name = reply.getString();
393
log.display(" name: " + name);
394
} catch (BoundException e) {
395
log.complain("Unable to extract name of slot #" + i
396
+ " from reply packet:\n\t"
397
+ e.getMessage());
398
success = false;
399
return;
400
}
401
402
// extract signature of a slot
403
String signature = null;
404
try {
405
signature = reply.getString();
406
log.display(" signature: " + signature);
407
} catch (BoundException e) {
408
log.complain("Unable to extract signature of slot #" + i
409
+ " from reply packet:\n\t"
410
+ e.getMessage());
411
success = false;
412
return;
413
}
414
415
// extract generic signature of a slot
416
String genericSignature = null;
417
try {
418
genericSignature = reply.getString();
419
log.display(" generic: " + genericSignature);
420
} catch (BoundException e) {
421
log.complain("Unable to extract generic signature of slot #" + i
422
+ " from reply packet:\n\t"
423
+ e.getMessage());
424
success = false;
425
return;
426
}
427
428
// extract code length
429
int length = 0;
430
try {
431
length = reply.getInt();
432
log.display(" length: " + length);
433
} catch (BoundException e) {
434
log.complain("Unable to extract code length for slot #" + i
435
+ " from reply packet:\n\t"
436
+ e.getMessage());
437
success = false;
438
return;
439
}
440
441
// extract code length
442
int slot = 0;
443
try {
444
slot = reply.getInt();
445
log.display(" slot: " + length);
446
} catch (BoundException e) {
447
log.complain("Unable to extract slot index of slot #" + i
448
+ " from reply packet:\n\t"
449
+ e.getMessage());
450
success = false;
451
return;
452
}
453
454
// find slot name into list of expected variables
455
int found = -1;
456
for (int j = 0; j < variablesCount; j++) {
457
if (variablesList[j][0].equals(name)) {
458
found = j;
459
break;
460
}
461
}
462
463
// check if slot is found and not duplicated
464
if (found >= 0) {
465
if (foundVariablesList[found] > 0) {
466
log.complain("Slot #" + i + " is duplicated "
467
+ foundVariablesList[found] + " times: "
468
+ name);
469
success = false;
470
/*
471
} else {
472
log.display("Found expected variable #" + found + ": "
473
+ variablesList[found][0]);
474
*/
475
}
476
foundVariablesList[found]++;
477
478
// check slot signature
479
if (!variablesList[found][1].equals(signature)) {
480
log.complain("Unexpected signature for slot #" + i + ": " + signature
481
+ " (expected: " + variablesList[found][1] + ")");
482
success = false;
483
}
484
485
// check slot generic signature
486
if (variablesList[found][2] == null && genericSignature != null) {
487
log.complain("Unexpected generic signature for slot #" + i + ": " + genericSignature
488
+ " (expected: " + variablesList[found][2] + ")");
489
success = false;
490
} else if (!variablesList[found][2].equals(genericSignature)) {
491
log.complain("Unexpected generic signature for slot #" + i + ": " + genericSignature
492
+ " (expected: " + variablesList[found][2] + ")");
493
success = false;
494
}
495
496
} else {
497
log.display("Unexpected slot #" + i + " (may be synthetic): " + name);
498
}
499
500
// check that code length is not negative
501
if (length < 0) {
502
log.complain("Code length for slot #" + i + " is negative: " + length);
503
success = false;
504
}
505
506
// check that slot index is not negative
507
if (slot < 0) {
508
log.complain("Index of slot #" + i + " is negative: " + slot);
509
success = false;
510
}
511
}
512
513
// check for extra data in reply packet
514
if (!reply.isParsed()) {
515
log.complain("Extra trailing bytes found in reply packet at: "
516
+ reply.offsetString());
517
success = false;
518
}
519
520
// check that all expected variables found
521
for (int i = 0; i < variablesCount; i++) {
522
if (foundVariablesList[i] <= 0) {
523
log.complain("No slot found in reply packet for variable: "
524
+ variablesList[i][0]);
525
success = false;
526
}
527
}
528
529
}
530
531
}
532
533