Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001.java
41161 views
1
/*
2
* Copyright (c) 2001, 2021, 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.ObjectReference.GetValues;
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: ObjectReference.GetValues.
34
*
35
* See getvalues001.README for description of test execution.
36
*
37
* Test is executed by invoking method runIt().
38
* JDWP command is tested in method testCommand().
39
*
40
* @see #runIt()
41
* @see #testCommand()
42
*/
43
public class getvalues001 {
44
45
// exit status constants
46
static final int JCK_STATUS_BASE = 95;
47
static final int PASSED = 0;
48
static final int FAILED = 2;
49
50
// communication signals constants
51
static final String READY = "ready";
52
static final String QUIT = "quit";
53
54
// package and classes names constants
55
static final String PACKAGE_NAME = "nsk.jdwp.ObjectReference.GetValues";
56
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "getvalues001";
57
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
58
59
// tested JDWP command constants
60
static final String JDWP_COMMAND_NAME = "ObjectReference.GetValues";
61
static final int JDWP_COMMAND_ID = JDWP.Command.ObjectReference.GetValues;
62
63
// tested class name and signature constants
64
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
65
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
66
67
// name of the static field in the tested class with the tested object value
68
static final String OBJECT_FIELD_NAME = getvalues001a.OBJECT_FIELD_NAME;
69
70
// names and expected values of the tested fields
71
static final Object fields [][] = {
72
{ "booleanValue", "boolean", Boolean.valueOf(true), "own"},
73
{ "byteValue", "byte", Byte.valueOf((byte)0x0F), "own"},
74
{ "charValue", "char", Character.valueOf('Z'), "own"},
75
{ "intValue", "int", Integer.valueOf(100), "own"},
76
{ "shortValue", "short", Short.valueOf((short)10), "own"},
77
{ "longValue", "long", Long.valueOf((long)1000000), "own"},
78
{ "floatValue", "float", Float.valueOf((float)3.14), "own"},
79
{ "doubleValue", "double", Double.valueOf((double)2.8e-12), "own"},
80
{ "objectValue", "objectID", Long.valueOf((long)0), "own"},
81
82
};
83
static final int FIELDS_COUNT = fields.length;
84
85
// usual scaffold objects
86
ArgumentHandler argumentHandler = null;
87
Log log = null;
88
Binder binder = null;
89
Debugee debugee = null;
90
Transport transport = null;
91
IOPipe pipe = null;
92
93
// test passed or not
94
boolean success = true;
95
96
// -------------------------------------------------------------------
97
98
/**
99
* Start test from command line.
100
*/
101
public static void main (String argv[]) {
102
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
103
}
104
105
/**
106
* Start JCK-compilant test.
107
*/
108
public static int run(String argv[], PrintStream out) {
109
return new getvalues001().runIt(argv, out);
110
}
111
112
// -------------------------------------------------------------------
113
114
/**
115
* Perform test execution.
116
*/
117
public int runIt(String argv[], PrintStream out) {
118
119
// make log for debugger messages
120
argumentHandler = new ArgumentHandler(argv);
121
log = new Log(out, argumentHandler);
122
123
// execute test and display results
124
try {
125
log.display("\n>>> Preparing debugee for testing \n");
126
127
// launch debugee
128
binder = new Binder(argumentHandler, log);
129
log.display("Launching debugee");
130
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
131
transport = debugee.getTransport();
132
pipe = debugee.createIOPipe();
133
134
// make debuggee ready for testing
135
prepareDebugee();
136
137
// work with prepared debugee
138
try {
139
log.display("\n>>> Obtaining requred data from debugee \n");
140
141
// query debugee for TypeID of tested class
142
log.display("Getting ReferenceTypeID by signature:\n"
143
+ " " + TESTED_CLASS_SIGNATURE);
144
long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
145
log.display(" got classID: " + classID);
146
147
// query debuggee for objectID value from static field
148
log.display("Getting objectID value from static field: "
149
+ OBJECT_FIELD_NAME);
150
long objectID = queryObjectID(classID,
151
OBJECT_FIELD_NAME, JDWP.Tag.OBJECT);
152
log.display(" got objectID: " + objectID);
153
154
// query debugee for fieldIDs of tested class static fields
155
log.display("Getting fieldIDs the tested class with the tested values");
156
long fieldIDs[] = queryClassFieldIDs(classID);
157
158
// perform testing JDWP command
159
log.display("\n>>> Testing JDWP command \n");
160
testCommand(objectID, fieldIDs);
161
162
} finally {
163
// quit debugee
164
log.display("\n>>> Finishing test \n");
165
quitDebugee();
166
}
167
168
} catch (Failure e) {
169
log.complain("TEST FAILED: " + e.getMessage());
170
e.printStackTrace(out);
171
success = false;
172
} catch (Exception e) {
173
log.complain("Caught unexpected exception:\n" + e);
174
e.printStackTrace(out);
175
success = false;
176
}
177
178
if (!success) {
179
log.complain("TEST FAILED");
180
return FAILED;
181
}
182
183
out.println("TEST PASSED");
184
return PASSED;
185
186
}
187
188
/**
189
* Prepare debugee for testing and waiting for ready signal.
190
*/
191
void prepareDebugee() {
192
// wait for VM_INIT event from debugee
193
log.display("Waiting for VM_INIT event");
194
debugee.waitForVMInit();
195
196
// query debugee for VM-dependent ID sizes
197
log.display("Querying for IDSizes");
198
debugee.queryForIDSizes();
199
200
// resume initially suspended debugee
201
log.display("Resuming debugee VM");
202
debugee.resume();
203
204
// wait for READY signal from debugee
205
log.display("Waiting for signal from debugee: " + READY);
206
String signal = pipe.readln();
207
log.display("Received signal from debugee: " + signal);
208
if (! signal.equals(READY)) {
209
throw new TestBug("Unexpected signal received form debugee: " + signal
210
+ " (expected: " + READY + ")");
211
}
212
}
213
214
/**
215
* Sending debugee signal to quit and waiting for it exits.
216
*/
217
void quitDebugee() {
218
// send debugee signal to quit
219
log.display("Sending signal to debugee: " + QUIT);
220
pipe.println(QUIT);
221
222
// wait for debugee exits
223
log.display("Waiting for debugee exits");
224
int code = debugee.waitFor();
225
226
// analize debugee exit status code
227
if (code == JCK_STATUS_BASE + PASSED) {
228
log.display("Debugee PASSED with exit code: " + code);
229
} else {
230
log.complain("Debugee FAILED with exit code: " + code);
231
success = false;
232
}
233
}
234
235
/**
236
* Query debuggee for objectID value of static class field.
237
*/
238
long queryObjectID(long classID, String fieldName, byte tag) {
239
// get fieledID for static field (declared in the class)
240
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
241
// get value of the field
242
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
243
244
// check that value has THREAD tag
245
if (value.getTag() != tag) {
246
throw new Failure("Wrong objectID tag received from field \"" + fieldName
247
+ "\": " + value.getTag() + " (expected: " + tag + ")");
248
}
249
250
// extract threadID from the value
251
long objectID = ((Long)value.getValue()).longValue();
252
return objectID;
253
}
254
255
/**
256
* Query debugee for fieldIDs and them into nested_classesIDs array.
257
*/
258
long[] queryClassFieldIDs(long typeID) {
259
// create array for expected filedIDs
260
long fieldIDs[] = new long[FIELDS_COUNT];
261
for (int i = 0; i < FIELDS_COUNT; i++) {
262
fieldIDs[i] = 0;
263
}
264
265
// obtain requested fieldIDs form debuggee
266
int count = 0;
267
try {
268
CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.Fields);
269
command.addReferenceTypeID(typeID);
270
command.setLength();
271
272
ReplyPacket reply = debugee.receiveReplyFor(command);
273
reply.resetPosition();
274
275
long declared = reply.getInt();
276
if (declared < FIELDS_COUNT) {
277
throw new Failure("Too few fields of the tested class returned: " + declared
278
+ " (expected: at least " + FIELDS_COUNT + ")");
279
}
280
281
for (int i = 0; i < declared; i++ ) {
282
long fieldID = reply.getFieldID();
283
String name = reply.getString();
284
String signature = reply.getString();
285
int modBits = reply.getInt();
286
287
for (int j = 0; j < FIELDS_COUNT; j++) {
288
if (fields[j][0].equals(name)) {
289
fieldIDs[j] = fieldID;
290
break;
291
}
292
}
293
}
294
295
if (!reply.isParsed()) {
296
throw new Failure("Extra trailing bytes found in the reply packet at: "
297
+ reply.currentPosition());
298
}
299
300
} catch (BoundException e) {
301
throw new Failure("Unable to extract field IDs from the reply packet:\n"
302
+ e.getMessage());
303
}
304
305
return fieldIDs;
306
}
307
308
/**
309
* Extract and check i-th value from the reply packet.
310
*/
311
void checkValue(int i, JDWP.Value value) {
312
if (!fields[i][2].equals(value.getValue())) {
313
log.complain("Unexpected value for " + i + " field received: " + value
314
+ " (expected: " + fields[i][2] + ")");
315
success = false;
316
}
317
}
318
319
/**
320
* Perform testing JDWP command for specified objectID.
321
*/
322
void testCommand(long objectID, long fieldIDs[]) {
323
int count = fieldIDs.length;
324
325
// create command packet
326
log.display("Create command packet:");
327
log.display("Command: " + JDWP_COMMAND_NAME);
328
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
329
330
// add out data to the command packet
331
log.display(" objectID: " + objectID);
332
command.addObjectID(objectID);
333
log.display(" fields: " + count);
334
command.addInt(count);
335
for (int i = 0; i < count; i++) {
336
log.display(" #" + i +": fieldID: " + fieldIDs[i]);
337
command.addFieldID(fieldIDs[i]);
338
}
339
command.setLength();
340
341
// send command packet to debugee
342
try {
343
log.display("Sending command packet:\n" + command);
344
transport.write(command);
345
} catch (IOException e) {
346
log.complain("Unable to send command packet:\n" + e);
347
success = false;
348
return;
349
}
350
351
ReplyPacket reply = new ReplyPacket();
352
353
// receive reply packet from debugee
354
try {
355
log.display("Waiting for reply packet");
356
transport.read(reply);
357
log.display("Reply packet received:\n" + reply);
358
} catch (IOException e) {
359
log.complain("Unable to read reply packet:\n" + e);
360
success = false;
361
return;
362
}
363
364
// check reply packet header
365
try{
366
log.display("Checking reply packet header");
367
reply.checkHeader(command.getPacketID());
368
} catch (BoundException e) {
369
log.complain("Bad header of reply packet: " + e.getMessage());
370
success = false;
371
}
372
373
// start parsing reply packet data
374
log.display("Parsing reply packet:");
375
reply.resetPosition();
376
377
// extract and check number of values
378
int values = 0;
379
try {
380
values = reply.getInt();
381
log.display(" values: " + values);
382
383
} catch (BoundException e) {
384
log.complain("Unable to extract number of values form reply packet:\n" + e.getMessage());
385
success = false;
386
}
387
388
// check if number of values are as expected
389
if (values < 0) {
390
log.complain("Negative number of values received:" + values
391
+ " (expected: " + count + ")");
392
success = false;
393
} else if (values != count) {
394
log.complain("Unexpected number of values received:" + values
395
+ " (expected: " + count + ")");
396
success = false;
397
}
398
399
// extract and check each value
400
for (int i = 0; i < values; i++ ) {
401
log.display(" value #" + i + " (field: " + fields[i][0] + ")");
402
403
// extract value
404
JDWP.Value value = null;
405
try {
406
value = reply.getValue();
407
log.display(" value: " + value);
408
} catch (BoundException e) {
409
log.complain("Unable to extract " + i + " value:\n" + e.getMessage());
410
success = false;
411
break;
412
}
413
414
// extract and check value by known type tag
415
checkValue(i, value);
416
}
417
418
// check for extra data in reply packet
419
if (! reply.isParsed()) {
420
log.complain("Extra trailing bytes found in reply packet at: "
421
+ "0x" + reply.toHexString(reply.currentDataPosition(), 4));
422
success = false;
423
}
424
}
425
426
}
427
428