Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001.java
41162 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.StackFrame.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: StackFrame.SetValues.
34
*
35
* See setvalues001.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 setvalues001 {
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 RUN = "run";
54
static final String DONE = "done";
55
static final String ERROR = "error";
56
static final String QUIT = "quit";
57
58
// package and classes names constants
59
static final String PACKAGE_NAME = "nsk.jdwp.StackFrame.SetValues";
60
static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "setvalues001";
61
static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
62
63
// tested JDWP command constants
64
static final String JDWP_COMMAND_NAME = "StackFrame.SetValues";
65
static final int JDWP_COMMAND_ID = JDWP.Command.StackFrame.SetValues;
66
67
// tested class name and signature constants
68
static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + setvalues001a.OBJECT_CLASS_NAME;
69
static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";
70
71
// target values class name and signature constants
72
static final String TARGET_VALUES_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TargetValuesClass";
73
static final String TARGET_VALUES_CLASS_SIGNATURE = "L" + TARGET_VALUES_CLASS_NAME.replace('.', '/') + ";";
74
75
// names of the static fields with the tested thread and object values
76
static final String TESTED_THREAD_FIELD_NAME = setvalues001a.THREAD_FIELD_NAME;
77
static final String TESTED_OBJECT_FIELD_NAME = setvalues001a.OBJECT_FIELD_NAME;
78
static final String TESTED_OBJECT_METHOD_NAME = setvalues001a.OBJECT_METHOD_NAME;
79
80
// list of tested variables names and values
81
static final Object variables[] = {
82
"booleanValue",
83
"byteValue",
84
"charValue",
85
"intValue",
86
"shortValue",
87
"longValue",
88
"floatValue",
89
"doubleValue",
90
"stringValue",
91
"objectValue"
92
};
93
static final int VARIABLES_COUNT = variables.length;
94
95
// usual scaffold objects
96
ArgumentHandler argumentHandler = null;
97
Log log = null;
98
Binder binder = null;
99
Debugee debugee = null;
100
Transport transport = null;
101
IOPipe pipe = null;
102
103
// test passed or not
104
boolean success = true;
105
106
// -------------------------------------------------------------------
107
108
/**
109
* Start test from command line.
110
*/
111
public static void main (String argv[]) {
112
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
113
}
114
115
/**
116
* Start JCK-compilant test.
117
*/
118
public static int run(String argv[], PrintStream out) {
119
return new setvalues001().runIt(argv, out);
120
}
121
122
// -------------------------------------------------------------------
123
124
/**
125
* Perform test execution.
126
*/
127
public int runIt(String argv[], PrintStream out) {
128
129
// make log for debugger messages
130
argumentHandler = new ArgumentHandler(argv);
131
log = new Log(out, argumentHandler);
132
133
// execute test and display results
134
try {
135
log.display("\n>>> Preparing debugee for testing \n");
136
137
// launch debuggee
138
binder = new Binder(argumentHandler, log);
139
log.display("Launching debugee");
140
debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
141
transport = debugee.getTransport();
142
pipe = debugee.createIOPipe();
143
144
// make debuggee ready for testing
145
prepareDebugee();
146
147
// work with prepared debuggee
148
long threadID = 0;
149
try {
150
log.display("\n>>> Obtaining requred data from debugee \n");
151
152
// get target values from static fields
153
154
// query debugee for classID for the class with target values
155
log.display("Getting classID for class with target values by signature:\n"
156
+ " " + TARGET_VALUES_CLASS_SIGNATURE);
157
long targetValuesClassID =
158
debugee.getReferenceTypeID(TARGET_VALUES_CLASS_SIGNATURE);
159
log.display(" got classID: " + targetValuesClassID);
160
161
// query debugee for fieldIDs of the class static fields
162
log.display("Getting fieldIDs for static fields of the class");
163
long fieldIDs[] = queryClassFieldIDs(targetValuesClassID);
164
log.display(" got fields: " + fieldIDs.length);
165
166
// query debugee for values of the fields
167
log.display("Getting values of the static fields");
168
JDWP.Value values[] =
169
queryClassFieldValues(targetValuesClassID, fieldIDs);
170
log.display(" got values: " + values.length);
171
172
// get indexes of local variables
173
174
// query debugee for classID of the tested class
175
log.display("Getting tested classID by signature:\n"
176
+ " " + TESTED_CLASS_SIGNATURE);
177
long testedClassID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);
178
log.display(" got classID: " + testedClassID);
179
180
// query debuggee for tested methodID
181
log.display("Getting tested methodID by name: " + TESTED_OBJECT_METHOD_NAME);
182
long methodID = debugee.getMethodID(testedClassID, TESTED_OBJECT_METHOD_NAME, true);
183
log.display(" got methodID: " + methodID);
184
185
// query debugee for indexes of the method local variables
186
log.display("Getting indexes of the tested local variables for methodID: " + methodID);
187
int indexes[] = queryVariableIndexes(testedClassID, methodID);
188
log.display(" got indexes: " + indexes.length);
189
190
// get tested objectID and threadID from static fields
191
192
// query debuggee for tested objectID value from static field
193
log.display("Getting tested objectID value from static field: "
194
+ TESTED_OBJECT_FIELD_NAME);
195
long objectID = queryObjectID(testedClassID, TESTED_OBJECT_FIELD_NAME, JDWP.Tag.OBJECT);
196
log.display(" got objectID: " + objectID);
197
198
// query debuggee for tested threadID value from static field
199
log.display("Getting tested threadID value from static field: "
200
+ TESTED_THREAD_FIELD_NAME);
201
threadID = queryObjectID(testedClassID, TESTED_THREAD_FIELD_NAME, JDWP.Tag.THREAD);
202
log.display(" got threadID: " + threadID);
203
204
// suspend tested thread into debuggee
205
log.display("Suspending thread into debuggee for threadID: " + threadID);
206
debugee.suspendThread(threadID);
207
log.display(" thread suspended");
208
209
// get current frameID and test JDWP command
210
211
// query debuggee for current frameID of the tested thread
212
log.display("Getting current frameID for the threadID: "
213
+ threadID);
214
long frameID = debugee.getCurrentFrameID(threadID);
215
log.display(" got frameID: " + frameID);
216
217
// perform testing JDWP command
218
log.display("\n>>> Testing JDWP command \n");
219
testCommand(frameID, threadID, indexes, values);
220
221
// check confirmation from debuggee that values have been set correctly
222
log.display("\n>>> Checking that the values have been set correctly \n");
223
224
log.display("Resuming suspended thread");
225
debugee.resumeThread(threadID);
226
227
checkValuesChanged();
228
229
} finally {
230
log.display("\n>>> Finishing test \n");
231
232
// resume suspended thread
233
if (threadID != 0) {
234
log.display("Finally resuming potentially suspended thread");
235
debugee.resumeThread(threadID);
236
}
237
238
// quit debugee
239
quitDebugee();
240
}
241
242
} catch (Failure e) {
243
log.complain("TEST FAILED: " + e.getMessage());
244
success = false;
245
} catch (Exception e) {
246
e.printStackTrace(out);
247
log.complain("Caught unexpected exception while running the test:\n\t" + e);
248
success = false;
249
}
250
251
if (!success) {
252
log.complain("TEST FAILED");
253
return FAILED;
254
}
255
256
out.println("TEST PASSED");
257
return PASSED;
258
259
}
260
261
/**
262
* Prepare debugee for testing and waiting for ready signal.
263
*/
264
void prepareDebugee() {
265
// wait for VM_INIT event from debugee
266
log.display("Waiting for VM_INIT event");
267
debugee.waitForVMInit();
268
269
// query debugee for VM-dependent ID sizes
270
log.display("Querying for IDSizes");
271
debugee.queryForIDSizes();
272
273
// resume initially suspended debugee
274
log.display("Resuming debugee VM");
275
debugee.resume();
276
277
// wait for READY signal from debugee
278
log.display("Waiting for signal from debugee: " + READY);
279
String signal = pipe.readln();
280
log.display("Received signal from debugee: " + signal);
281
if (signal == null) {
282
throw new TestBug("Null signal received from debugee: " + signal
283
+ " (expected: " + READY + ")");
284
} else if (signal.equals(ERROR)) {
285
throw new TestBug("Debugee was not able to start tested thread"
286
+ " (received signal: " + signal + ")");
287
} else if (!signal.equals(READY)) {
288
throw new TestBug("Unexpected signal received from debugee: " + signal
289
+ " (expected: " + READY + ")");
290
}
291
}
292
293
/**
294
* Sending debugee signal to quit and waiting for it exits.
295
*/
296
void quitDebugee() {
297
// send debugee signal to quit
298
log.display("Sending signal to debugee: " + QUIT);
299
pipe.println(QUIT);
300
301
// wait for debugee exits
302
log.display("Waiting for debugee exits");
303
int code = debugee.waitFor();
304
305
// analize debugee exit status code
306
if (code == JCK_STATUS_BASE + PASSED) {
307
log.display("Debugee PASSED with exit code: " + code);
308
} else {
309
log.complain("Debugee FAILED with exit code: " + code);
310
success = false;
311
}
312
}
313
314
/**
315
* Query debuggee for objectID value of static field of the class.
316
*/
317
long queryObjectID(long classID, String fieldName, byte tag) {
318
// get fieledID for static field (declared in the class)
319
long fieldID = debugee.getClassFieldID(classID, fieldName, true);
320
// get value of the field
321
JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID);
322
323
// check that value has expected tag
324
if (value.getTag() != tag) {
325
throw new Failure("Unexpected tag for object value returned: "
326
+ value.getTag() + " (expected: " + tag + ")");
327
}
328
329
// extract objectID from the value
330
long objectID = ((Long)value.getValue()).longValue();
331
return objectID;
332
}
333
334
/**
335
* Query debugee for indexes of the local method variables.
336
*/
337
int[] queryVariableIndexes(long classID, long methodID) {
338
// create array for expected indexes
339
int indexes[] = new int[VARIABLES_COUNT];
340
for (int i = 0; i < VARIABLES_COUNT; i++) {
341
indexes[i] = 0;
342
}
343
344
// obtain variable indexes from debuggee
345
int count = 0;
346
try {
347
CommandPacket command = new CommandPacket(JDWP.Command.Method.VariableTable);
348
command.addReferenceTypeID(classID);
349
command.addMethodID(methodID);
350
command.setLength();
351
352
ReplyPacket reply = debugee.receiveReplyFor(command);
353
reply.resetPosition();
354
355
int argCount = reply.getInt();
356
long slots = reply.getInt();
357
358
for (int i = 0; i < slots; i++ ) {
359
long codeindex = reply.getLong();
360
String name = reply.getString();
361
String signature = reply.getString();
362
int length = reply.getInt();
363
int slot = reply.getInt();
364
365
for (int j = 0; j < VARIABLES_COUNT; j++) {
366
if (variables[j].equals(name)) {
367
indexes[j] = slot;
368
break;
369
}
370
}
371
}
372
373
} catch (BoundException e) {
374
log.complain("Unable to extract local variable indexes from the reply packet:\n\t"
375
+ e.getMessage());
376
throw new Failure("Error occured while getting local variable indexes for methodID:"
377
+ methodID);
378
}
379
380
// check that all expected fieldIDs received
381
int notfound = 0;
382
for (int i = 0; i < VARIABLES_COUNT; i++) {
383
if(indexes[i] == 0) {
384
log.complain("Not found index for local variable: " + variables[i]);
385
notfound++;
386
}
387
}
388
if (notfound > 0) {
389
throw new Failure("Unable to get indexes for " + notfound +
390
" local variables for methodID: " + methodID);
391
}
392
return indexes;
393
}
394
395
/**
396
* Query debugee for fieldID's of the class static fields.
397
*/
398
long[] queryClassFieldIDs(long classID) {
399
400
// create array of fieldID's corresponding to tested variables
401
long[] fieldIDs = new long[VARIABLES_COUNT];
402
for (int i = 0; i < VARIABLES_COUNT; i++) {
403
fieldIDs[i] = 0;
404
}
405
406
// compose ReferenceType.Fields command packet
407
CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.Fields);
408
command.addReferenceTypeID(classID);
409
command.setLength();
410
411
// send the command and receive reply
412
ReplyPacket reply = debugee.receiveReplyFor(command);
413
414
// extract fieldIDs from the reply packet
415
try {
416
reply.resetPosition();
417
418
int declared = reply.getInt();
419
420
for (int i = 0; i < declared; i++ ) {
421
long fieldID = reply.getFieldID();
422
String name = reply.getString();
423
String signature = reply.getString();
424
int modBits = reply.getInt();
425
426
// find variable with the same name
427
for (int j = 0; j < VARIABLES_COUNT; j++) {
428
if (variables[j].equals(name)) {
429
fieldIDs[j] = fieldID;
430
}
431
}
432
}
433
} catch (BoundException e) {
434
log.complain("Unable to parse reply packet for ReferenceType.Fields command:\n\t"
435
+ e);
436
log.complain("Received reply packet:\n"
437
+ reply);
438
throw new Failure("Error occured while getting static fieldIDs for classID: " + classID);
439
}
440
441
// check that all expected fieldIDs received
442
int notfound = 0;
443
for (int i = 0; i < VARIABLES_COUNT; i++) {
444
if(fieldIDs[i] == 0) {
445
log.complain("Not found fieldID for static field: " + variables[i]);
446
notfound++;
447
}
448
}
449
if (notfound > 0) {
450
throw new Failure("Unable to get fiedIDs for " + notfound +
451
" static fields for classID: " + classID);
452
}
453
return fieldIDs;
454
}
455
456
/**
457
* Query debugee for values of the class fields.
458
*/
459
JDWP.Value[] queryClassFieldValues(long classID, long fieldIDs[]) {
460
// compose ReferenceType.Fields command packet
461
int count = fieldIDs.length;
462
CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.GetValues);
463
command.addReferenceTypeID(classID);
464
command.addInt(count);
465
for (int i = 0; i < count; i++) {
466
command.addFieldID(fieldIDs[i]);
467
}
468
command.setLength();
469
470
// send the command and receive reply
471
ReplyPacket reply = debugee.receiveReplyFor(command);
472
473
// extract values from the reply packet
474
try {
475
reply.resetPosition();
476
477
int valuesCount = reply.getInt();
478
if (valuesCount != count) {
479
throw new Failure("Unexpected number of values of static fields returned: "
480
+ valuesCount + " (expected: " + count + ")");
481
}
482
483
JDWP.Value values[] = new JDWP.Value[valuesCount];
484
for (int i = 0; i < valuesCount; i++ ) {
485
JDWP.Value value = reply.getValue();
486
values[i] = value;
487
}
488
return values;
489
} catch (BoundException e) {
490
log.complain("Unable to parse reply packet for ReferenceType.SetValues command:\n\t"
491
+ e);
492
log.complain("Received reply packet:\n"
493
+ reply);
494
throw new Failure("Error occured while getting static fields values for classID: " + classID);
495
}
496
}
497
498
/**
499
* Perform testing JDWP command for specified frameID.
500
*/
501
void testCommand(long frameID, long threadID, int indexes[], JDWP.Value values[]) {
502
// create command packet and fill requred out data
503
log.display("Create command packet:");
504
log.display("Command: " + JDWP_COMMAND_NAME);
505
CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
506
log.display(" threadID: " + threadID);
507
command.addObjectID(threadID);
508
log.display(" frameID: " + frameID);
509
command.addFrameID(frameID);
510
log.display(" slotValues: " + VARIABLES_COUNT);
511
command.addInt(VARIABLES_COUNT);
512
513
// add indexes and new values of the tested variables
514
for (int i = 0; i < VARIABLES_COUNT; i++) {
515
log.display(" slot #" + i + ":");
516
log.display(" slot: " + indexes[i]);
517
command.addInt(indexes[i]);
518
log.display(" slotvalue: " + values[i]);
519
command.addValue(values[i]);
520
}
521
command.setLength();
522
523
// send command packet to debugee
524
try {
525
log.display("Sending command packet:\n" + command);
526
transport.write(command);
527
} catch (IOException e) {
528
log.complain("Unable to send command packet:\n\t" + e);
529
success = false;
530
return;
531
}
532
533
ReplyPacket reply = new ReplyPacket();
534
535
// receive reply packet from debugee
536
try {
537
log.display("Waiting for reply packet");
538
transport.read(reply);
539
log.display("Reply packet received:\n" + reply);
540
} catch (IOException e) {
541
log.complain("Unable to read reply packet:\n\t" + e);
542
success = false;
543
return;
544
}
545
546
// check reply packet header
547
try{
548
log.display("Checking reply packet header");
549
reply.checkHeader(command.getPacketID());
550
} catch (BoundException e) {
551
log.complain("Bad header of reply packet:\n\t" + e.getMessage());
552
success = false;
553
return;
554
}
555
556
// start parsing reply packet data
557
log.display("Parsing reply packet:");
558
reply.resetPosition();
559
560
// no data in the reply packet
561
562
// check for extra data in reply packet
563
if (!reply.isParsed()) {
564
log.complain("Extra trailing bytes found in reply packet at: "
565
+ reply.offsetString());
566
success = false;
567
}
568
569
}
570
571
/**
572
* Check confiramtion from debuggee that values are changed.
573
*/
574
void checkValuesChanged() {
575
// send debugee signal RUN
576
log.display("Sending signal to debugee: " + RUN);
577
pipe.println(RUN);
578
579
// wait for DONE signal from debugee
580
log.display("Waiting for signal from debugee: " + DONE);
581
String signal = pipe.readln();
582
log.display("Received signal from debugee: " + signal);
583
584
// check received signal
585
if (signal == null) {
586
throw new TestBug("<null> signal received from debugee: " + signal
587
+ " (expected: " + DONE + ")");
588
} else if (signal.equals(DONE)) {
589
log.display("All varaible values have been correctly set into debuggee VM");
590
} else if (signal.equals(ERROR)) {
591
log.complain("Not all variables values have been correctly set into debuggee VM");
592
success = false;
593
} else {
594
throw new TestBug("Unexpected signal received from debugee: " + signal
595
+ " (expected: " + DONE + ")");
596
}
597
}
598
599
}
600
601