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/setvalue002.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.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 setvalue002 {
35
final static int MIN_INDEX = -50;
36
final static int MAX_INDEX = 51;
37
final static String FIELD_NAME[][] = {
38
{"z1", "5", "boolean"},
39
{"b1", "5", "byte"},
40
{"c1", "6", "char"},
41
{"d1", "1", "double"},
42
{"f1", "1", "float"},
43
{"i1", "10", "int"},
44
{"l1", "2", "long"},
45
{"r1", "5", "short"},
46
47
{"lF1", "0", "long"},
48
{"lP1", "2", "long"},
49
{"lU1", "3", "long"},
50
{"lR1", "4", "long"},
51
{"lT1", "5", "long"},
52
{"lV1", "6", "long"}
53
};
54
55
private static Log log;
56
private final static String prefix = "nsk.jdi.ArrayReference.setValue.";
57
private final static String className = "setvalue002";
58
private final static String debugerName = prefix + className;
59
private final static String debugeeName = debugerName + "a";
60
private final static String classToCheckName = prefix + "setvalue002aClassToCheck";
61
62
public static void main(String argv[]) {
63
System.exit(95 + run(argv, System.out));
64
}
65
66
public static int run(String argv[], PrintStream out) {
67
ArgumentHandler argHandler = new ArgumentHandler(argv);
68
log = new Log(out, argHandler);
69
Binder binder = new Binder(argHandler, log);
70
Debugee debugee = binder.bindToDebugee(debugeeName
71
+ (argHandler.verbose() ? " -verbose" : ""));
72
IOPipe pipe = debugee.createIOPipe();
73
boolean testFailed = false;
74
Field fieldBoolean = null;
75
Field fieldByte = null;
76
Field fieldChar = null;
77
Field fieldDouble = null;
78
Field fieldFloat = null;
79
Field fieldInt = null;
80
Field fieldLong = null;
81
Field fieldShort = null;
82
Value valueBoolean = null;
83
Value valueByte = null;
84
Value valueChar = null;
85
Value valueDouble = null;
86
Value valueFloat = null;
87
Value valueInt = null;
88
Value valueLong = null;
89
Value valueShort = null;
90
91
// Connect with debugee and resume it
92
debugee.redirectStderr(out);
93
debugee.resume();
94
String line = pipe.readln();
95
if (line == null) {
96
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");
97
return 2;
98
}
99
if (!line.equals("ready")) {
100
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "
101
+ line);
102
return 2;
103
}
104
else {
105
log.display("debuger> debugee's \"ready\" signal recieved.");
106
}
107
108
ReferenceType refType = debugee.classByName(classToCheckName);
109
if (refType == null) {
110
log.complain("debuger FAILURE> Class " + classToCheckName
111
+ " not found.");
112
return 2;
113
}
114
115
log.display("debuger> Total fields in debugee read: "
116
+ refType.allFields().size() + " total fields in debuger: "
117
+ FIELD_NAME.length + "\n");
118
119
// Get all samples of primitive types Values to set it to the
120
// ArrayReference
121
try {
122
fieldBoolean = refType.fieldByName("z");
123
fieldByte = refType.fieldByName("b");
124
fieldChar = refType.fieldByName("c");
125
fieldDouble = refType.fieldByName("d");
126
fieldFloat = refType.fieldByName("f");
127
fieldInt = refType.fieldByName("i");
128
fieldLong = refType.fieldByName("l");
129
fieldShort = refType.fieldByName("r");
130
} catch (ClassNotPreparedException e) {
131
log.complain("debuger FAILURE> Cannot get field by name.");
132
log.complain("debuger FAILURE> Exception: " + e);
133
log.complain("debuger FAILURE> boolean is " + fieldBoolean);
134
log.complain("debuger FAILURE> byte is " + fieldByte);
135
log.complain("debuger FAILURE> char is " + fieldChar);
136
log.complain("debuger FAILURE> double is " + fieldDouble);
137
log.complain("debuger FAILURE> float is " + fieldFloat);
138
log.complain("debuger FAILURE> int is " + fieldInt);
139
log.complain("debuger FAILURE> long is " + fieldLong);
140
log.complain("debuger FAILURE> short is " + fieldShort);
141
return 2;
142
} catch (ObjectCollectedException e) {
143
log.complain("debuger FAILURE> Cannot get field by name.");
144
log.complain("debuger FAILURE> Exception: " + e);
145
log.complain("debuger FAILURE> boolean is " + fieldBoolean);
146
log.complain("debuger FAILURE> byte is " + fieldByte);
147
log.complain("debuger FAILURE> char is " + fieldChar);
148
log.complain("debuger FAILURE> double is " + fieldDouble);
149
log.complain("debuger FAILURE> float is " + fieldFloat);
150
log.complain("debuger FAILURE> int is " + fieldInt);
151
log.complain("debuger FAILURE> long is " + fieldLong);
152
log.complain("debuger FAILURE> short is " + fieldShort);
153
return 2;
154
}
155
log.display("debuger> Got sample fields for primitive types.");
156
log.display("debuger> boolean is " + fieldBoolean);
157
log.display("debuger> byte is " + fieldByte);
158
log.display("debuger> char is " + fieldChar);
159
log.display("debuger> double is " + fieldDouble);
160
log.display("debuger> float is " + fieldFloat);
161
log.display("debuger> int is " + fieldInt);
162
log.display("debuger> long is " + fieldLong);
163
log.display("debuger> short is " + fieldShort + "\n");
164
165
if ((fieldBoolean == null) || (fieldByte == null) ||
166
(fieldChar == null) || (fieldDouble == null) ||
167
(fieldFloat == null) || (fieldInt == null) ||
168
(fieldLong == null) || (fieldShort == null)) {
169
log.complain("debuger FAILURE> Cannot find field in debuggee.");
170
return 2;
171
}
172
173
try {
174
valueBoolean = refType.getValue(fieldBoolean);
175
valueByte = refType.getValue(fieldByte);
176
valueChar = refType.getValue(fieldChar);
177
valueDouble = refType.getValue(fieldDouble);
178
valueFloat = refType.getValue(fieldFloat);
179
valueInt = refType.getValue(fieldInt);
180
valueLong = refType.getValue(fieldLong);
181
valueShort = refType.getValue(fieldShort);
182
} catch (IllegalArgumentException e) {
183
log.complain("debuger FAILURE> Cannot get values for fields.");
184
log.complain("debuger FAILURE> Exception: " + e);
185
log.complain("debuger FAILURE> boolean is " + fieldBoolean);
186
log.complain("debuger FAILURE> byte is " + fieldByte);
187
log.complain("debuger FAILURE> char is " + fieldChar);
188
log.complain("debuger FAILURE> double is " + fieldDouble);
189
log.complain("debuger FAILURE> float is " + fieldFloat);
190
log.complain("debuger FAILURE> int is " + fieldInt);
191
log.complain("debuger FAILURE> long is " + fieldLong);
192
log.complain("debuger FAILURE> short is " + fieldShort);
193
return 2;
194
} catch (ObjectCollectedException e) {
195
log.complain("debuger FAILURE> Cannot get values for fields.");
196
log.complain("debuger FAILURE> Exception: " + e);
197
log.complain("debuger FAILURE> boolean is " + fieldBoolean);
198
log.complain("debuger FAILURE> byte is " + fieldByte);
199
log.complain("debuger FAILURE> char is " + fieldChar);
200
log.complain("debuger FAILURE> double is " + fieldDouble);
201
log.complain("debuger FAILURE> float is " + fieldFloat);
202
log.complain("debuger FAILURE> int is " + fieldInt);
203
log.complain("debuger FAILURE> long is " + fieldLong);
204
log.complain("debuger FAILURE> short is " + fieldShort);
205
return 2;
206
}
207
log.display("debuger> Got sample values for primitive types.");
208
log.display("debuger> boolean is " + valueBoolean);
209
log.display("debuger> byte is " + valueByte);
210
log.display("debuger> char is " + valueChar);
211
log.display("debuger> double is " + valueDouble);
212
log.display("debuger> float is " + valueFloat);
213
log.display("debuger> int is " + valueInt);
214
log.display("debuger> long is " + valueLong);
215
log.display("debuger> short is " + valueShort + "\n");
216
217
// Check all array fields from debugee
218
for (int i = 0; i < FIELD_NAME.length; i++) {
219
Field field;
220
String name = FIELD_NAME[i][0];
221
Integer totalElements = Integer.valueOf(FIELD_NAME[i][1]);
222
String type = FIELD_NAME[i][2];
223
int lastElementIndex = totalElements.intValue() - 1;
224
Value value;
225
ArrayReference arrayRef;
226
Value valueToSet;
227
228
// Get field from debuggee by name
229
try {
230
field = refType.fieldByName(name);
231
} catch (ClassNotPreparedException e) {
232
log.complain("debuger FAILURE 1> Can't get field by name "
233
+ name);
234
log.complain("debuger FAILURE 1> Exception: " + e);
235
testFailed = true;
236
continue;
237
} catch (ObjectCollectedException e) {
238
log.complain("debuger FAILURE 1> Can't get field by name "
239
+ name);
240
log.complain("debuger FAILURE 1> Exception: " + e);
241
testFailed = true;
242
continue;
243
}
244
log.display("debuger> " + i + " field " + field + " read.");
245
246
// Get field's value
247
try {
248
value = refType.getValue(field);
249
} catch (IllegalArgumentException e) {
250
log.complain("debuger FAILURE 2> Cannot get value for field "
251
+ name);
252
log.complain("debuger FAILURE 2> Exception: " + e);
253
testFailed = true;
254
continue;
255
} catch (ObjectCollectedException e) {
256
log.complain("debuger FAILURE 2> Cannot get value for field "
257
+ name);
258
log.complain("debuger FAILURE 2> Exception: " + e);
259
testFailed = true;
260
continue;
261
}
262
log.display("debuger> " + i + " field value is " + value);
263
264
// Cast to ArrayReference. All fields in debugee are
265
// arrays, so ClassCastException should not be thrown
266
try {
267
arrayRef = (ArrayReference)value;
268
} catch (ClassCastException e) {
269
log.complain("debuger FAILURE 3> Cannot cast value for field "
270
+ name + " to ArrayReference.");
271
log.complain("debuger FAILURE 3> Exception: " + e);
272
testFailed = true;
273
continue;
274
}
275
276
// Prepare Value to set
277
if (type.equals("boolean")) {
278
valueToSet = (Value)valueBoolean;
279
} else if (type.equals("byte")) {
280
valueToSet = (Value)valueByte;
281
} else if (type.equals("char")) {
282
valueToSet = (Value)valueChar;
283
} else if (type.equals("double")) {
284
valueToSet = (Value)valueDouble;
285
} else if (type.equals("float")) {
286
valueToSet = (Value)valueFloat;
287
} else if (type.equals("int")) {
288
valueToSet = (Value)valueInt;
289
} else if (type.equals("long")) {
290
valueToSet = (Value)valueLong;
291
} else if (type.equals("short")) {
292
valueToSet = (Value)valueShort;
293
} else {
294
log.complain("debuger FAILURE 4> Unexpected type: " + type);
295
testFailed = true;
296
continue;
297
}
298
299
// Try to set value by index from MIN_INDEX to -1 and from
300
// arrayRef.length() to MAX_INDEX
301
for (int j = MIN_INDEX; j < MAX_INDEX; j++) {
302
if ( (j < 0) || (j > lastElementIndex) ) {
303
304
// Set the Value, IndexOutOfBoundsException is expected
305
try {
306
arrayRef.setValue(j, valueToSet);
307
log.complain("debuger FAILURE 5> IndexOutOfBoundsException"
308
+ "is not thrown. ");
309
testFailed = true;
310
} catch (ObjectCollectedException e) {
311
log.complain("debuger FAILURE 5> Cannot set value "
312
+ valueToSet + " to " + j + " index of "
313
+ "field " + name);
314
log.complain("debuger FAILURE 5> Exception: " + e);
315
testFailed = true;
316
} catch (IndexOutOfBoundsException e) {
317
log.display("debuger> " + i + " field: cannot set "
318
+ "value " + valueToSet + " with index "
319
+ j + ". Expected exception: " + e);
320
} catch (InvalidTypeException e) {
321
log.complain("debuger FAILURE 5> Cannot set value "
322
+ valueToSet + " to " + j + " index of "
323
+ "field " + name);
324
log.complain("debuger FAILURE 5> Exception: " + e);
325
testFailed = true;
326
} catch (ClassNotLoadedException e) {
327
log.complain("debuger FAILURE 5> Cannot set value "
328
+ valueToSet + " to " + j + " index of "
329
+ "field " + name);
330
log.complain("debuger FAILURE 5> Exception: " + e);
331
testFailed = true;
332
} catch (VMMismatchException e) {
333
log.complain("debuger FAILURE 5> Cannot set value "
334
+ valueToSet + " to " + j + " index of "
335
+ "field " + name);
336
log.complain("debuger FAILURE 5> Exception: " + e);
337
testFailed = true;
338
}
339
}
340
}
341
log.display("debuger> " + i + " field checked.\n");
342
}
343
344
pipe.println("quit");
345
debugee.waitFor();
346
int status = debugee.getStatus();
347
if (testFailed) {
348
log.complain("debuger FAILURE> TEST FAILED");
349
return 2;
350
} else {
351
if (status == 95) {
352
log.display("debuger> expected Debugee's exit "
353
+ "status - " + status);
354
return 0;
355
} else {
356
log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "
357
+ "status (not 95) - " + status);
358
return 2;
359
}
360
}
361
}
362
}
363
364