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