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/setvalue003.java
41162 views
1
/*
2
* Copyright (c) 2002, 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.jdi.ArrayReference.setValue;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdi.*;
29
30
import com.sun.jdi.*;
31
import java.io.*;
32
import java.util.*;
33
34
public class setvalue003 {
35
36
// exit code when test failed
37
public final static int TEST_FAILED = 2;
38
// exit code when test passed
39
public final static int TEST_PASSED = 0;
40
// shift of exit code
41
public final static int JCK_STATUS_BASE = 95;
42
43
// parameters arrays to call com.sum.jdi.ArrayReference.setValue(int, Value)
44
private static long[] INDEX_PARAM = { Integer.MAX_VALUE + 1,
45
-1,
46
0,
47
Integer.MAX_VALUE
48
};
49
private final static String BYTE_VALUES_FIELD = "BYTE_VALUE_PARAM";
50
private final static String CHAR_VALUES_FIELD = "CHAR_VALUE_PARAM";
51
private final static String DBL_VALUES_FIELD = "DBL_VALUE_PARAM";
52
private final static String FLT_VALUES_FIELD = "FLT_VALUE_PARAM";
53
private final static String INT_VALUES_FIELD = "INT_VALUE_PARAM";
54
private final static String LNG_VALUES_FIELD = "LNG_VALUE_PARAM";
55
private final static String SHORT_VALUES_FIELD= "SHORT_VALUE_PARAM";
56
57
private final static String prefix = "nsk.jdi.ArrayReference.setValue.";
58
private final static String className = "setvalue003";
59
private final static String debuggerName = prefix + className;
60
private final static String debugeeName = debuggerName + "a";
61
private final static String objectToCheck = "testedObj";
62
63
private int exitStatus;
64
private Log log;
65
private Debugee debugee;
66
private IOPipe pipe;
67
private ReferenceType refType;
68
69
public static void main(String argv[]) {
70
System.exit(JCK_STATUS_BASE + run(argv, System.out));
71
}
72
73
public static int run(String argv[], PrintStream out) {
74
75
setvalue003 tstObj = new setvalue003();
76
77
if ( tstObj.prepareDebugee(argv, out) ) {
78
tstObj.execTest();
79
tstObj.disposeOfDebugee();
80
}
81
82
if ( tstObj.exitStatus == TEST_FAILED )
83
tstObj.complain("run:: TEST FAILED");
84
else
85
tstObj.display("run:: TEST PASSED");
86
return tstObj.exitStatus;
87
}
88
89
private boolean prepareDebugee(String argv[], PrintStream out) {
90
ArgumentHandler argHandler = new ArgumentHandler(argv);
91
log = new Log(out, argHandler);
92
Binder binder = new Binder(argHandler, log);
93
display("prepareDebugee:: binder created.");
94
95
debugee = binder.bindToDebugee(debugeeName);
96
log.display("prepareDebugee:: binded to debugee.");
97
pipe = debugee.createIOPipe();
98
log.display("prepareDebugee:: pipe created.");
99
100
debugee.redirectStderr(out);
101
debugee.resume();
102
103
String line = pipe.readln();
104
if ( line == null ) {
105
complain("prepareDebugee:: UNEXPECTED debugee's signal - null");
106
return false;
107
}
108
if ( !line.equals("ready") ) {
109
complain("prepareDebugee:: UNEXPECTED debugee's signal - "
110
+ line);
111
return false;
112
}
113
114
display("prepareDebugee:: debugee's \"ready\" signal received.");
115
return true;
116
}
117
118
private boolean disposeOfDebugee() {
119
pipe.println("quit");
120
debugee.waitFor();
121
int status = debugee.getStatus();
122
123
if ( status != JCK_STATUS_BASE ) {
124
complain("disposeOfDebugee:: UNEXPECTED Debugee's exit "
125
+ "status (not " + JCK_STATUS_BASE + ") - " + status);
126
return false;
127
}
128
display("disposeOfDebugee:: expected Debugee's exit "
129
+ "status - " + status);
130
return true;
131
}
132
133
private void display(String msg) {
134
if ( log != null )
135
log.display("debugger> " + msg);
136
}
137
138
private void complain(String msg) {
139
if ( log != null )
140
log.complain("debugger FAILURE> " + msg);
141
}
142
143
private boolean execTest() {
144
exitStatus = TEST_FAILED;
145
146
refType = debugee.classByName(debugeeName);
147
if ( refType == null ) {
148
complain("eventHandler:: Class '" + debugeeName + "' not found.");
149
return false;
150
}
151
152
Field field = refType.fieldByName(objectToCheck);
153
if ( field == null ) {
154
complain("eventHandler:: Field '" + objectToCheck + "' not found.");
155
return false;
156
}
157
158
Value objectValue = refType.getValue(field);
159
if ( objectValue == null ) {
160
complain("eventHandler:: Field '" + objectToCheck
161
+ "' not initialized.");
162
return false;
163
}
164
165
return checkObjectFields(objectValue);
166
}
167
168
public boolean checkObjectFields(Value objectValue) {
169
List fieldList;
170
if ( ! (objectValue instanceof ObjectReference) )
171
return false;
172
173
fieldList = ((ClassType )objectValue.type()).allFields();
174
175
// Check all array fields from debugee
176
display("checkObjectFields:: Tests starts >>>");
177
boolean res = true;
178
for (int i = 0; i < fieldList.size(); i++) {
179
res = checkFieldValue((ObjectReference )objectValue,
180
(Field )fieldList.get(i)) && res;
181
}
182
183
exitStatus = res ? TEST_PASSED : TEST_FAILED;
184
return res;
185
}
186
187
private boolean checkFieldValue(ObjectReference object, Field field) {
188
Value fieldValue;
189
ArrayReference arrayRef;
190
String fieldName = field.name();
191
log.display("");
192
display("<" + fieldName + "> field is being checked.");
193
try {
194
fieldValue = object.getValue(field);
195
} catch (IllegalArgumentException e) {
196
complain("checkFieldValue:: can not get value for field " + fieldName);
197
complain("checkFieldValue:: " + e);
198
return false;
199
}
200
201
display("***" + fieldName + " = " + fieldValue);
202
203
// Tested object doesn't have non-initialized fields!
204
if ( fieldValue == null ) {
205
complain("unexpected field value <"
206
+ fieldValue + ">");
207
return false;
208
}
209
210
display("*** type of " + fieldName + " = " + fieldValue.type());
211
212
// Checking up of value type.
213
// Tested object doesn't have other fields than be ArrayType
214
if ( ! (fieldValue.type() instanceof ArrayType) ) {
215
display("type of value is not ArrayType.");
216
return false;
217
}
218
219
boolean res = true;
220
221
Type itemType;
222
try {
223
itemType = ((ArrayType )fieldValue.type()).componentType();
224
} catch(Exception e) {
225
complain("Unexpected " + e.getClass().getName() );
226
return false;
227
}
228
229
// getting value to set from debugee with defined type
230
Field fieldOfValues = null;
231
if ( itemType instanceof ByteType ) {
232
fieldOfValues = refType.fieldByName(BYTE_VALUES_FIELD);
233
if ( fieldOfValues == null ) {
234
complain("Field '" + BYTE_VALUES_FIELD + "' not found.");
235
return false;
236
}
237
} else if ( itemType instanceof CharType ) {
238
fieldOfValues = refType.fieldByName(CHAR_VALUES_FIELD);
239
if ( fieldOfValues == null ) {
240
complain("Field '" + CHAR_VALUES_FIELD + "' not found.");
241
return false;
242
}
243
} else if ( itemType instanceof DoubleType ) {
244
fieldOfValues = refType.fieldByName(DBL_VALUES_FIELD);
245
if ( fieldOfValues == null ) {
246
complain("Field '" + DBL_VALUES_FIELD + "' not found.");
247
return false;
248
}
249
} else if ( itemType instanceof FloatType ) {
250
fieldOfValues = refType.fieldByName(FLT_VALUES_FIELD);
251
if ( fieldOfValues == null ) {
252
complain("Field '" + FLT_VALUES_FIELD + "' not found.");
253
return false;
254
}
255
} else if ( itemType instanceof IntegerType ) {
256
fieldOfValues = refType.fieldByName(INT_VALUES_FIELD);
257
if ( fieldOfValues == null ) {
258
complain("Field '" + INT_VALUES_FIELD + "' not found.");
259
return false;
260
}
261
} else if ( itemType instanceof LongType ) {
262
fieldOfValues = refType.fieldByName(LNG_VALUES_FIELD);
263
if ( fieldOfValues == null ) {
264
complain("Field '" + LNG_VALUES_FIELD + "' not found.");
265
return false;
266
}
267
} else if ( itemType instanceof ShortType ) {
268
fieldOfValues = refType.fieldByName(SHORT_VALUES_FIELD);
269
if ( fieldOfValues == null ) {
270
complain("Field '" + SHORT_VALUES_FIELD + "' not found.");
271
return false;
272
}
273
}
274
275
ArrayReference values = (ArrayReference )refType.getValue(fieldOfValues);
276
277
// Checking up of test cases.
278
for ( int i = 0; i < INDEX_PARAM.length; i++ ) {
279
for ( int j = 0; j < values.length(); j++ ) {
280
res = checkValueUpdating(fieldName,
281
(ArrayReference )fieldValue, INDEX_PARAM[i],
282
values.getValue(j)) && res;
283
}
284
}
285
return res;
286
}
287
288
private boolean checkValueUpdating(String name,
289
ArrayReference arrayRef, long index, Value value) {
290
Value itemValue;
291
List list;
292
String il2Str = "for index=" + index + " value=" + value;
293
int arrayLength = arrayRef.length();
294
295
try {
296
arrayRef.setValue((int )index, value);
297
Value v1 = arrayRef.getValue((int )index);
298
299
if ( !value.equals(v1) ) {
300
complain("not correct value " + v1
301
+ " " + il2Str);
302
return false;
303
}
304
305
if ( index < 0 || index >= arrayLength ) {
306
complain("IndexOutOfBoundsException is expected " + il2Str);
307
return false;
308
} else {
309
display("Value " + v1 + " is set " + il2Str);
310
}
311
312
} catch (IndexOutOfBoundsException e) {
313
314
// checking specification conditions
315
if ( index < 0 || index >= arrayLength ) {
316
display("expected IndexOutOfBoundsException "
317
+ il2Str);
318
} else {
319
complain("unexpected IndexOutOfBoundsException "
320
+ il2Str);
321
return false;
322
}
323
324
} catch (Exception e) {
325
complain("Unexpected exception: "
326
+ e + " " + il2Str);
327
return false;
328
}
329
return true;
330
}
331
}
332
333