Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/setValue/setvalue001.java
41162 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
25
package nsk.jdi.ArrayReference.setValue;
26
27
import nsk.share.*;
28
import nsk.share.jpda.*;
29
import nsk.share.jdi.*;
30
31
import com.sun.jdi.*;
32
import java.io.*;
33
34
public class setvalue001 {
35
final static int HALF = 9;
36
final static String FIELD_NAME[][] = {
37
{"z1", "boolean"},
38
{"b1", "byte"},
39
{"c1", "char"},
40
{"d1", "double"},
41
{"f1", "float"},
42
{"i1", "int"},
43
{"l1", "long"},
44
{"r1", "short"},
45
46
{"lF1", "long"},
47
{"lP1", "long"},
48
{"lU1", "long"},
49
{"lR1", "long"},
50
{"lT1", "long"},
51
{"lV1", "long"}
52
};
53
54
private static Log log;
55
private final static String prefix = "nsk.jdi.ArrayReference.setValue.";
56
private final static String className = "setvalue001";
57
private final static String debugerName = prefix + className;
58
private final static String debugeeName = debugerName + "a";
59
private final static String classToCheckName = prefix + "setvalue001aClassToCheck";
60
61
public static void main(String argv[]) {
62
System.exit(95 + run(argv, System.out));
63
}
64
65
public static int run(String argv[], PrintStream out) {
66
ArgumentHandler argHandler = new ArgumentHandler(argv);
67
log = new Log(out, argHandler);
68
Binder binder = new Binder(argHandler, log);
69
Debugee debugee = binder.bindToDebugee(debugeeName
70
+ (argHandler.verbose() ? " -verbose" : ""));
71
IOPipe pipe = debugee.createIOPipe();
72
boolean testFailed = false;
73
74
// Connect with debugee and resume it
75
debugee.redirectStderr(out);
76
debugee.resume();
77
String line = pipe.readln();
78
if (line == null) {
79
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");
80
return 2;
81
}
82
if (!line.equals("ready")) {
83
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "
84
+ line);
85
return 2;
86
}
87
else {
88
log.display("debuger> debugee's \"ready\" signal recieved.");
89
}
90
91
ReferenceType refType = debugee.classByName(classToCheckName);
92
if (refType == null) {
93
log.complain("debuger FAILURE> Class " + classToCheckName
94
+ " not found.");
95
return 2;
96
}
97
log.display("debuger> Total fields in debugee read: "
98
+ refType.allFields().size() + " total fields in debuger: "
99
+ FIELD_NAME.length + "\n");
100
101
// Check all array fields from debugee
102
for (int i = 0; i < FIELD_NAME.length; i++) {
103
Field field;
104
String name = FIELD_NAME[i][0];
105
String realType = FIELD_NAME[i][1];
106
Value value;
107
ArrayReference arrayRef;
108
109
// Get field from debuggee by name
110
try {
111
field = refType.fieldByName(name);
112
} catch (ClassNotPreparedException e) {
113
log.complain("debuger FAILURE 1> Can't get field by name "
114
+ name);
115
log.complain("debuger FAILURE 1> Exception: " + e);
116
testFailed = true;
117
continue;
118
} catch (ObjectCollectedException e) {
119
log.complain("debuger FAILURE 1> Can't get field by name "
120
+ name);
121
log.complain("debuger FAILURE 1> Exception: " + e);
122
testFailed = true;
123
continue;
124
}
125
log.display("debuger> " + i + " field " + field + " read.");
126
127
// Get field's value
128
try {
129
value = refType.getValue(field);
130
} catch (IllegalArgumentException e) {
131
log.complain("debuger FAILURE 2> Cannot get value for field "
132
+ name);
133
log.complain("debuger FAILURE 2> Exception: " + e);
134
testFailed = true;
135
continue;
136
} catch (ObjectCollectedException e) {
137
log.complain("debuger FAILURE 2> Cannot get value for field "
138
+ name);
139
log.complain("debuger FAILURE 2> Exception: " + e);
140
testFailed = true;
141
continue;
142
}
143
log.display("debuger> " + i + " field value is " + value);
144
145
// Cast to ArrayReference. All fields in debugee are
146
// arrays, so ClassCastException should not be thrown
147
try {
148
arrayRef = (ArrayReference)value;
149
} catch (ClassCastException e) {
150
log.complain("debuger FAILURE 3> Cannot cast value for field "
151
+ name + " to ArrayReference.");
152
log.complain("debuger FAILURE 3> Exception: " + e);
153
testFailed = true;
154
continue;
155
}
156
157
for (int j = 0; j < HALF; j++) {
158
int indexSample = j + HALF;
159
Value sample;
160
Value valueNew;
161
162
// Get Value from sample-area (9..17 elements)
163
try {
164
sample = arrayRef.getValue(indexSample);
165
} catch (ObjectCollectedException e) {
166
log.complain("debuger FAILURE 4> Cannot get " + indexSample
167
+ " value from field " + name);
168
log.complain("debuger FAILURE 4> Exception: " + e);
169
testFailed = true;
170
continue;
171
} catch (IndexOutOfBoundsException e) {
172
log.complain("debuger FAILURE 4> Cannot get " + indexSample
173
+ " value from field " + name);
174
log.complain("debuger FAILURE 4> Exception: " + e);
175
testFailed = true;
176
continue;
177
}
178
log.display("debuger> " + i + " field: sample from index "
179
+ indexSample + " is " + sample);
180
181
// Set the Sample to the correspondent index
182
// Any exception means that the test fails
183
try {
184
arrayRef.setValue(j, sample);
185
} catch (ObjectCollectedException e) {
186
log.complain("debuger FAILURE 5> Cannot set value " + sample
187
+ " to " + j + " index of field " + name);
188
log.complain("debuger FAILURE 5> Exception: " + e);
189
testFailed = true;
190
continue;
191
} catch (IndexOutOfBoundsException e) {
192
log.complain("debuger FAILURE 5> Cannot set value " + sample
193
+ " to " + j + " index of field " + name);
194
log.complain("debuger FAILURE 5> Exception: " + e);
195
testFailed = true;
196
continue;
197
} catch (InvalidTypeException e) {
198
log.complain("debuger FAILURE 5> Cannot set value " + sample
199
+ " to " + j + " index of field " + name);
200
log.complain("debuger FAILURE 5> Exception: " + e);
201
testFailed = true;
202
continue;
203
} catch (ClassNotLoadedException e) {
204
log.complain("debuger FAILURE 5> Cannot set value " + sample
205
+ " to " + j + " index of field " + name);
206
log.complain("debuger FAILURE 5> Exception: " + e);
207
testFailed = true;
208
continue;
209
} catch (VMMismatchException e) {
210
log.complain("debuger FAILURE 5> Cannot set value " + sample
211
+ " to " + j + " index of field " + name);
212
log.complain("debuger FAILURE 5> Exception: " + e);
213
testFailed = true;
214
continue;
215
}
216
log.display("debuger> " + i + " field: sample " + sample
217
+ " has been set to index " + j);
218
219
220
// Get the Value from the correspondent index
221
try {
222
valueNew = arrayRef.getValue(j);
223
} catch (ObjectCollectedException e) {
224
log.complain("debuger FAILURE 6> Cannot get " + j + " value"
225
+ " from field " + name);
226
log.complain("debuger FAILURE 6> Exception: " + e);
227
testFailed = true;
228
continue;
229
} catch (IndexOutOfBoundsException e) {
230
log.complain("debuger FAILURE 6> Cannot get " + j + " value"
231
+ " from field " + name);
232
log.complain("debuger FAILURE 6> Exception: " + e);
233
testFailed = true;
234
continue;
235
}
236
log.display("debuger> " + i + " field: element from index " + j
237
+ " is " + valueNew);
238
239
// Check the Value that has been read with the sample
240
if (realType.equals("boolean")) {
241
242
///////////////////// Check boolean[] /////////////////////
243
BooleanValue boolValue;
244
boolean boolSample;
245
boolean boolNew;
246
247
// Cast sample and read Value to primitive type
248
try {
249
boolValue = (BooleanValue)sample;
250
} catch (ClassCastException e) {
251
log.complain("debuger FAILURE Z1> Cannot cast to "
252
+ "boolean sample.");
253
log.complain("debuger FAILURE Z1> Exception: " + e);
254
testFailed = true;
255
continue;
256
}
257
boolSample = boolValue.value();
258
try {
259
boolValue = (BooleanValue)valueNew;
260
} catch (ClassCastException e) {
261
log.complain("debuger FAILURE Z2> Cannot cast to "
262
+ "boolean read value.");
263
log.complain("debuger FAILURE Z2> Exception: " + e);
264
testFailed = true;
265
continue;
266
}
267
boolNew = boolValue.value();
268
269
// Check two primitive values
270
if (boolNew != boolSample) {
271
log.complain("debuger FAILURE Z3> " + j + " element "
272
+ "of array " + name + " was expected "
273
+ boolSample + ", but returned " + boolNew);
274
testFailed = true;
275
} else {
276
log.display("debuger> " + i + " field: primitive "
277
+ "sample is " + boolSample + ", primitive "
278
+ " read value is " + boolNew);
279
}
280
} else if (realType.equals("byte")) {
281
282
///////////////////// Check byte[] /////////////////////
283
ByteValue byteValue;
284
byte byteSample;
285
byte byteNew;
286
287
// Cast sample and read Value to primitive type
288
try {
289
byteValue = (ByteValue)sample;
290
} catch (ClassCastException e) {
291
log.complain("debuger FAILURE B1> Cannot cast to "
292
+ "byte sample.");
293
log.complain("debuger FAILURE B1> Exception: " + e);
294
testFailed = true;
295
continue;
296
}
297
byteSample = byteValue.value();
298
try {
299
byteValue = (ByteValue)valueNew;
300
} catch (ClassCastException e) {
301
log.complain("debuger FAILURE B2> Cannot cast to "
302
+ "byte read value.");
303
log.complain("debuger FAILURE B2> Exception: " + e);
304
testFailed = true;
305
continue;
306
}
307
byteNew = byteValue.value();
308
309
// Check two primitive values
310
if (byteNew != byteSample) {
311
log.complain("debuger FAILURE B3> " + j + " element "
312
+ "of array " + name + " was expected "
313
+ byteSample + ", but returned " + byteNew);
314
testFailed = true;
315
} else {
316
log.display("debuger> " + i + " field: primitive "
317
+ "sample is " + byteSample + ", primitive "
318
+ "read value is " + byteNew);
319
}
320
} else if (realType.equals("char")) {
321
322
///////////////////// Check char[] /////////////////////
323
CharValue charValue;
324
char charSample;
325
char charNew;
326
327
// Cast sample and read Value to primitive type
328
try {
329
charValue = (CharValue)sample;
330
} catch (ClassCastException e) {
331
log.complain("debuger FAILURE C1> Cannot cast to "
332
+ "char sample.");
333
log.complain("debuger FAILURE C1> Exception: " + e);
334
testFailed = true;
335
continue;
336
}
337
charSample = charValue.value();
338
try {
339
charValue = (CharValue)valueNew;
340
} catch (ClassCastException e) {
341
log.complain("debuger FAILURE C2> Cannot cast to "
342
+ "char read value.");
343
log.complain("debuger FAILURE C2> Exception: " + e);
344
testFailed = true;
345
continue;
346
}
347
charNew = charValue.value();
348
349
// Check two primitive values
350
if (charNew != charSample) {
351
log.complain("debuger FAILURE C3> " + j + " element "
352
+ "of array " + name + " was expected "
353
+ charSample + ", but returned " + charNew);
354
testFailed = true;
355
} else {
356
log.display("debuger> " + i + " field: primitive "
357
+ "sample is " + charSample + ", primitive "
358
+ "read value is " + charNew);
359
}
360
} else if (realType.equals("int")) {
361
362
///////////////////// Check int[] /////////////////////
363
IntegerValue intValue;
364
int intSample;
365
int intNew;
366
367
// Cast sample and read Value to primitive type
368
try {
369
intValue = (IntegerValue)sample;
370
} catch (ClassCastException e) {
371
log.complain("debuger FAILURE I1> Cannot cast to "
372
+ "int sample.");
373
log.complain("debuger FAILURE I1> Exception: " + e);
374
testFailed = true;
375
continue;
376
}
377
intSample = intValue.value();
378
try {
379
intValue = (IntegerValue)valueNew;
380
} catch (ClassCastException e) {
381
log.complain("debuger FAILURE I2> Cannot cast to "
382
+ "int read value.");
383
log.complain("debuger FAILURE I2> Exception: " + e);
384
testFailed = true;
385
continue;
386
}
387
intNew = intValue.value();
388
389
// Check two primitive values
390
if (intNew != intSample) {
391
log.complain("debuger FAILURE I3> " + j + " element "
392
+ "of array " + name + " was expected "
393
+ intSample + ", but returned " + intNew);
394
testFailed = true;
395
} else {
396
log.display("debuger> " + i + " field: primitive "
397
+ "sample is " + intSample + ", primitive "
398
+ "read value is " + intNew);
399
}
400
} else if (realType.equals("long")) {
401
402
///////////////////// Check long[] /////////////////////
403
LongValue longValue;
404
long longSample;
405
long longNew;
406
407
// Cast sample and read Value to primitive type
408
try {
409
longValue = (LongValue)sample;
410
} catch (ClassCastException e) {
411
log.complain("debuger FAILURE L1> Cannot cast to "
412
+ "long sample.");
413
log.complain("debuger FAILURE L1> Exception: " + e);
414
testFailed = true;
415
continue;
416
}
417
longSample = longValue.value();
418
try {
419
longValue = (LongValue)valueNew;
420
} catch (ClassCastException e) {
421
log.complain("debuger FAILURE L2> Cannot cast to "
422
+ "long read value.");
423
log.complain("debuger FAILURE L2> Exception: " + e);
424
testFailed = true;
425
continue;
426
}
427
longNew = longValue.value();
428
429
// Check two primitive values
430
if (longNew != longSample) {
431
log.complain("debuger FAILURE L3> " + j + " element "
432
+ "of array " + name + " was expected "
433
+ longSample + ", but returned " + longNew);
434
testFailed = true;
435
} else {
436
log.display("debuger> " + i + " field: primitive "
437
+ "sample is " + longSample + ", primitive "
438
+ "read value is " + longNew);
439
}
440
} else if (realType.equals("short")) {
441
442
///////////////////// Check short[] /////////////////////
443
ShortValue shortValue;
444
short shortSample;
445
short shortNew;
446
447
// Cast sample and read Value to primitive type
448
try {
449
shortValue = (ShortValue)sample;
450
} catch (ClassCastException e) {
451
log.complain("debuger FAILURE R1> Cannot cast to "
452
+ "short sample.");
453
log.complain("debuger FAILURE R1> Exception: " + e);
454
testFailed = true;
455
continue;
456
}
457
shortSample = shortValue.value();
458
try {
459
shortValue = (ShortValue)valueNew;
460
} catch (ClassCastException e) {
461
log.complain("debuger FAILURE R2> Cannot cast to "
462
+ "short read value.");
463
log.complain("debuger FAILURE R2> Exception: " + e);
464
testFailed = true;
465
continue;
466
}
467
shortNew = shortValue.value();
468
469
// Check two primitive values
470
if (shortNew != shortSample) {
471
log.complain("debuger FAILURE R3> " + j + " element "
472
+ "of array " + name + " was expected "
473
+ shortSample + ", but returned "
474
+ shortNew);
475
testFailed = true;
476
} else {
477
log.display("debuger> " + i + " field: primitive "
478
+ "sample is " + shortSample + ", primitive "
479
+ "read value is " + shortNew);
480
}
481
} else if (realType.equals("double")) {
482
483
///////////////////// Check double[] /////////////////////
484
DoubleValue dblValue;
485
Double dblSample;
486
Double dblNew;
487
488
// Cast sample and read Value to primitive type
489
try {
490
dblValue = (DoubleValue)sample;
491
} catch (ClassCastException e) {
492
log.complain("debuger FAILURE D1> Cannot cast to "
493
+ "double sample.");
494
log.complain("debuger FAILURE D1> Exception: " + e);
495
testFailed = true;
496
continue;
497
}
498
dblSample = Double.valueOf(dblValue.value());
499
try {
500
dblValue = (DoubleValue)valueNew;
501
} catch (ClassCastException e) {
502
log.complain("debuger FAILURE D2> Cannot cast to "
503
+ "double read value.");
504
log.complain("debuger FAILURE D2> Exception: " + e);
505
testFailed = true;
506
continue;
507
}
508
dblNew = Double.valueOf(dblValue.value());
509
510
// Check two primitive values
511
if (!dblNew.equals(dblSample)) {
512
log.complain("debuger FAILURE D3> " + j + " element "
513
+ "of array " + name + " was expected "
514
+ dblSample + ", but returned " + dblNew);
515
testFailed = true;
516
} else {
517
log.display("debuger> " + i + " field: primitive "
518
+ "sample is " + dblSample + ", primitive "
519
+ "read value is " + dblNew);
520
}
521
} else if (realType.equals("float")) {
522
523
///////////////////// Check float[] /////////////////////
524
FloatValue fltValue;
525
Float fltSample;
526
Float fltNew;
527
528
// Cast sample and read Value to primitive type
529
try {
530
fltValue = (FloatValue)sample;
531
} catch (ClassCastException e) {
532
log.complain("debuger FAILURE F1> Cannot cast to "
533
+ "float sample.");
534
log.complain("debuger FAILURE F1> Exception: " + e);
535
testFailed = true;
536
continue;
537
}
538
fltSample = Float.valueOf(fltValue.value());
539
try {
540
fltValue = (FloatValue)valueNew;
541
} catch (ClassCastException e) {
542
log.complain("debuger FAILURE F2> Cannot cast to "
543
+ "float read value.");
544
log.complain("debuger FAILURE F2> Exception: " + e);
545
testFailed = true;
546
continue;
547
}
548
fltNew = Float.valueOf(fltValue.value());
549
550
// Check two primitive values
551
if (!fltNew.equals(fltSample)) {
552
log.complain("debuger FAILURE F3> " + j + " element "
553
+ "of array " + name + " was expected "
554
+ fltSample + ", but returned " + fltNew);
555
testFailed = true;
556
} else {
557
log.display("debuger> " + i + " field: primitive "
558
+ "sample is " + fltSample + ", primitive "
559
+ "read value is " + fltNew);
560
}
561
} else {
562
log.complain("debuger FAILURE 6> Unexpected type: "
563
+ realType);
564
testFailed = true;
565
break;
566
}
567
}
568
log.display("debuger> " + i + " field checked.\n");
569
}
570
571
pipe.println("quit");
572
debugee.waitFor();
573
int status = debugee.getStatus();
574
if (testFailed) {
575
log.complain("debuger FAILURE> TEST FAILED");
576
return 2;
577
} else {
578
if (status == 95) {
579
log.display("debuger> expected Debugee's exit "
580
+ "status - " + status);
581
return 0;
582
} else {
583
log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "
584
+ "status (not 95) - " + status);
585
return 2;
586
}
587
}
588
}
589
}
590
591