Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001.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.ObjectReference.SetValues;
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.SetValues.
34
*
35
* See setvalues001.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 setvalues001 {
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 RUN = "run";
53
static final String DONE = "done";
54
static final String ERROR = "error";
55
static final String QUIT = "quit";
56
57
// package and classes names constants
58
static final String PACKAGE_NAME = "nsk.jdwp.ObjectReference.SetValues";
59
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "setvalues001";
60
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
61
62
// tested JDWP command constants
63
static final String JDWP_COMMAND_NAME = "ObjectReference.SetValues";
64
static final int JDWP_COMMAND_ID = JDWP.Command.ObjectReference.SetValues;
65
66
// tested class name and signature constants
67
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";
68
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
69
70
// target values class name and signature constants
71
static final String TARGET_VALUES_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TargetValuesClass";
72
static final String TARGET_VALUES_CLASS_SIGNATURE = "L" + TARGET_VALUES_CLASS_NAME.replace('.', '/') + ";";
73
74
// name and siagnature of a class with static field with the tested object value
75
static final String OBJECT_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "ObjectClass";
76
static final String OBJECT_CLASS_SIGNATURE = "L" + OBJECT_CLASS_NAME.replace('.', '/') + ";";
77
78
// name of the static field in the tested class with the tested object value
79
static final String OBJECT_FIELD_NAME = setvalues001a.OBJECT_FIELD_NAME;
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 setvalues001().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 debugee
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 debugee
134
try {
135
log.display("\n>>> Obtaining requred data from debugee \n");
136
137
// query debugee for classID for the class with target values
138
log.display("Getting classID for class with target values by signature:\n"
139
+ " " + TARGET_VALUES_CLASS_SIGNATURE);
140
long targetValuesClassID =
141
debugee.getReferenceTypeID(TARGET_VALUES_CLASS_SIGNATURE);
142
log.display(" got classID: " + targetValuesClassID);
143
144
// query debugee for fieldIDs of the class static fields
145
log.display("Getting fieldIDs for static fields of the class");
146
long targetValuesFieldIDs[] = queryClassFieldIDs(targetValuesClassID);
147
log.display(" got fields: " + targetValuesFieldIDs.length);
148
int count = targetValuesFieldIDs.length;
149
150
// query debugee for values of the fields
151
log.display("Getting values of the static fields");
152
JDWP.Value targetValues[] =
153
queryClassFieldValues(targetValuesClassID, targetValuesFieldIDs);
154
log.display(" got values: " + targetValues.length);
155
if (targetValues.length != count) {
156
throw new Failure("Unexpected number of static fields values received: "
157
+ targetValues.length + "(expected: " + count + ")");
158
}
159
160
// query debugee for classID of the tested class
161
log.display("Getting tested classID by signature:\n"
162
+ " " + TESTED_CLASS_SIGNATURE);
163
long testedClassID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
164
log.display(" got classID: " + testedClassID);
165
166
// query debugee for fieldIDs of tested class fields
167
log.display("Getting fieldIDs for tested fields of the tested class");
168
long testedFieldIDs[] = queryClassFieldIDs(testedClassID);
169
log.display(" got fields: " + testedFieldIDs.length);
170
if (testedFieldIDs.length != count) {
171
throw new Failure("Unexpected number of fields of tested class received: "
172
+ testedFieldIDs.length + "(expected: " + count + ")");
173
}
174
175
// query debugee for classID of the object class
176
log.display("Getting object classID by signature:\n"
177
+ " " + OBJECT_CLASS_SIGNATURE);
178
long classID = debugee.getReferenceTypeID(OBJECT_CLASS_SIGNATURE);
179
log.display(" got classID: " + classID);
180
181
// query debuggee for objectID value from static field
182
log.display("Getting objectID value from static field: "
183
+ OBJECT_FIELD_NAME);
184
long objectID = queryObjectID(classID,
185
OBJECT_FIELD_NAME, JDWP.Tag.OBJECT);
186
log.display(" got objectID: " + objectID);
187
188
// perform testing JDWP command
189
log.display("\n>>> Testing JDWP command \n");
190
testCommand(objectID, testedFieldIDs, targetValues);
191
192
// check confirmation from debuggee that values have been set properly
193
log.display("\n>>> Checking that the values have been set properly \n");
194
checkValuesChanged();
195
196
} finally {
197
// quit debugee
198
log.display("\n>>> Finishing test \n");
199
quitDebugee();
200
}
201
202
} catch (Failure e) {
203
log.complain("TEST FAILED: " + e.getMessage());
204
e.printStackTrace(out);
205
success = false;
206
} catch (Exception e) {
207
log.complain("Caught unexpected exception:\n" + e);
208
e.printStackTrace(out);
209
success = false;
210
}
211
212
if (!success) {
213
log.complain("TEST FAILED");
214
return FAILED;
215
}
216
217
out.println("TEST PASSED");
218
return PASSED;
219
220
}
221
222
/**
223
* Prepare debugee for testing and waiting for ready signal.
224
*/
225
void prepareDebugee() {
226
// wait for VM_INIT event from debugee
227
log.display("Waiting for VM_INIT event");
228
debugee.waitForVMInit();
229
230
// query debugee for VM-dependent ID sizes
231
log.display("Querying for IDSizes");
232
debugee.queryForIDSizes();
233
234
// resume initially suspended debugee
235
log.display("Resuming debugee VM");
236
debugee.resume();
237
238
// wait for READY signal from debugee
239
log.display("Waiting for signal from debugee: " + READY);
240
String signal = pipe.readln();
241
log.display("Received signal from debugee: " + signal);
242
if (! signal.equals(READY)) {
243
throw new TestBug("Unexpected signal received form debugee: " + signal
244
+ " (expected: " + READY + ")");
245
}
246
}
247
248
/**
249
* Sending debugee signal to quit and waiting for it exits.
250
*/
251
void quitDebugee() {
252
// send debugee signal to quit
253
log.display("Sending signal to debugee: " + QUIT);
254
pipe.println(QUIT);
255
256
// wait for debugee exits
257
log.display("Waiting for debugee exits");
258
int code = debugee.waitFor();
259
260
// analize debugee exit status code
261
if (code == JCK_STATUS_BASE + PASSED) {
262
log.display("Debugee PASSED with exit code: " + code);
263
} else {
264
log.complain("Debugee FAILED with exit code: " + code);
265
success = false;
266
}
267
}
268
269
/**
270
* Query debugee for fieldID's of the class static fields.
271
*/
272
long[] queryClassFieldIDs(long classID) {
273
// compose ReferenceType.Fields command packet
274
CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.Fields);
275
command.addReferenceTypeID(classID);
276
command.setLength();
277
278
// send the command and receive reply
279
ReplyPacket reply = debugee.receiveReplyFor(command);
280
281
// extract fieldIDs from the reply packet
282
try {
283
reply.resetPosition();
284
285
int declared = reply.getInt();
286
long[] fieldIDs = new long[declared];
287
288
int j = 0;
289
for (int i = 0; i < declared; i++ ) {
290
long fieldID = reply.getFieldID();
291
String name = reply.getString();
292
String signature = reply.getString();
293
int modBits = reply.getInt();
294
295
fieldIDs[i] = fieldID;
296
}
297
return fieldIDs;
298
} catch (BoundException e) {
299
log.complain("Unable to parse reply packet for ReferenceType.Fields command:\n\t"
300
+ e);
301
log.complain("Received reply packet:\n"
302
+ reply);
303
throw new Failure("Error occured while getting static fieldIDs for classID: " + classID);
304
}
305
}
306
307
/**
308
* Query debugee for values of the class fields.
309
*/
310
JDWP.Value[] queryClassFieldValues(long classID, long fieldIDs[]) {
311
// compose ReferenceType.Fields command packet
312
int count = fieldIDs.length;
313
CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.GetValues);
314
command.addReferenceTypeID(classID);
315
command.addInt(count);
316
for (int i = 0; i < count; i++) {
317
command.addFieldID(fieldIDs[i]);
318
}
319
command.setLength();
320
321
// send the command and receive reply
322
ReplyPacket reply = debugee.receiveReplyFor(command);
323
324
// extract values from the reply packet
325
try {
326
reply.resetPosition();
327
328
int valuesCount = reply.getInt();
329
JDWP.Value values[] = new JDWP.Value[valuesCount];
330
for (int i = 0; i < valuesCount; i++ ) {
331
JDWP.Value value = reply.getValue();
332
values[i] = value;
333
}
334
return values;
335
} catch (BoundException e) {
336
log.complain("Unable to parse reply packet for ReferenceType.GetValues command:\n\t"
337
+ e);
338
log.complain("Received reply packet:\n"
339
+ reply);
340
throw new Failure("Error occured while getting static fields values for classID: " + classID);
341
}
342
}
343
344
/**
345
* Query debuggee for objectID value of static class field.
346
*/
347
long queryObjectID(long classID, String fieldName, byte tag) {
348
// get fieledID for static field (declared in the class)
349
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
350
// get value of the field
351
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
352
353
// check that value has THREAD tag
354
if (value.getTag() != tag) {
355
throw new Failure("Wrong objectID tag received from field \"" + fieldName
356
+ "\": " + value.getTag() + " (expected: " + tag + ")");
357
}
358
359
// extract threadID from the value
360
long objectID = ((Long)value.getValue()).longValue();
361
return objectID;
362
}
363
364
/**
365
* Perform testing JDWP command for specified classID.
366
*/
367
void testCommand(long objectID, long fieldIDs[], JDWP.Value values[]) {
368
int count = fieldIDs.length;
369
370
// create command packet
371
log.display("Create command packet:");
372
log.display("Command: " + JDWP_COMMAND_NAME);
373
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
374
375
// add out data to the command packet
376
log.display(" objectID: " + objectID);
377
command.addObjectID(objectID);
378
log.display(" values: " + count);
379
command.addInt(count);
380
for (int i = 0; i < count; i++) {
381
log.display(" field #" + i +":");
382
log.display(" fieldID: " + fieldIDs[i]);
383
command.addFieldID(fieldIDs[i]);
384
385
JDWP.Value value = values[i];
386
JDWP.UntaggedValue untaggedValue =
387
new JDWP.UntaggedValue(value.getValue());
388
log.display(" untagged_value: " + untaggedValue.getValue());
389
command.addUntaggedValue(untaggedValue, value.getTag());
390
}
391
command.setLength();
392
393
// send command packet to debugee
394
try {
395
log.display("Sending command packet:\n" + command);
396
transport.write(command);
397
} catch (IOException e) {
398
log.complain("Unable to send command packet:\n" + e);
399
success = false;
400
return;
401
}
402
403
ReplyPacket reply = new ReplyPacket();
404
405
// receive reply packet from debugee
406
try {
407
log.display("Waiting for reply packet");
408
transport.read(reply);
409
log.display("Reply packet received:\n" + reply);
410
} catch (IOException e) {
411
log.complain("Unable to read reply packet:\n" + e);
412
success = false;
413
return;
414
}
415
416
// check reply packet header
417
try{
418
log.display("Checking reply packet header");
419
reply.checkHeader(command.getPacketID());
420
} catch (BoundException e) {
421
log.complain("Bad header of reply packet: " + e.getMessage());
422
success = false;
423
}
424
425
// start parsing reply packet data
426
log.display("Parsing reply packet:");
427
reply.resetPosition();
428
429
// no data to extract
430
431
// check for extra data in reply packet
432
if (! reply.isParsed()) {
433
log.complain("Extra trailing bytes found in reply packet at: "
434
+ "0x" + reply.toHexString(reply.currentDataPosition(), 4));
435
success = false;
436
}
437
}
438
439
/**
440
* Check confiramtion from debuggee that values are changed.
441
*/
442
void checkValuesChanged() {
443
// send debugee signal RUN
444
log.display("Sending signal to debugee: " + RUN);
445
pipe.println(RUN);
446
447
// wait for DONE signal from debugee
448
log.display("Waiting for signal from debugee: " + DONE);
449
String signal = pipe.readln();
450
log.display("Received signal from debugee: " + signal);
451
452
// check received signal
453
if (signal == null) {
454
throw new TestBug("<null> signal received from debugee: " + signal
455
+ " (expected: " + DONE + ")");
456
} else if (signal.equals(DONE)) {
457
log.display("All fields values have been correctly set into debuggee VM");
458
} else if (signal.equals(ERROR)) {
459
log.complain("Not all fields values have been correctly set into debuggee VM");
460
success = false;
461
} else {
462
throw new TestBug("Unexpected signal received from debugee: " + signal
463
+ " (expected: " + DONE + ")");
464
}
465
}
466
467
}
468
469