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