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/getvalue002.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 getvalue002 {
35
final static int MIN_INDEX = -50;
36
final static int MAX_INDEX = 51;
37
final static String FIELD_NAME[][] = {
38
{"z1", "5"},
39
{"b1", "5"},
40
{"c1", "6"},
41
{"d1", "1"},
42
{"f1", "1"},
43
{"i1", "10"},
44
{"l1", "2"},
45
{"r1", "5"},
46
47
{"lF1", "0"},
48
{"lP1", "2"},
49
{"lU1", "3"},
50
{"lR1", "4"},
51
{"lT1", "5"},
52
{"lV1", "6"}
53
};
54
55
private static Log log;
56
private final static String prefix = "nsk.jdi.ArrayReference.getValue.";
57
private final static String className = "getvalue002";
58
private final static String debugerName = prefix + className;
59
private final static String debugeeName = debugerName + "a";
60
private final static String classToCheckName = prefix + "getvalue002aClassToCheck";
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
75
// Connect with debugee and resume it
76
debugee.redirectStderr(out);
77
debugee.resume();
78
String line = pipe.readln();
79
if (line == null) {
80
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");
81
return 2;
82
}
83
if (!line.equals("ready")) {
84
log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "
85
+ line);
86
return 2;
87
}
88
else {
89
log.display("debuger> debugee's \"ready\" signal recieved.");
90
}
91
92
ReferenceType refType = debugee.classByName(classToCheckName);
93
if (refType == null) {
94
log.complain("debuger FAILURE> Class " + classToCheckName
95
+ " not found.");
96
return 2;
97
}
98
99
log.display("debuger> Total fields in debugee read: "
100
+ refType.allFields().size() + " total fields in debuger: "
101
+ FIELD_NAME.length + "\n");
102
103
// Check all array fields from debugee
104
for (int i = 0; i < FIELD_NAME.length; i++) {
105
Field field;
106
String name = FIELD_NAME[i][0];
107
Integer totalElements = Integer.valueOf(FIELD_NAME[i][1]);
108
int lastElementIndex = totalElements.intValue() - 1;
109
Value value;
110
ArrayReference arrayRef;
111
112
// Get field from debuggee by name
113
try {
114
field = refType.fieldByName(name);
115
} catch (ClassNotPreparedException e) {
116
log.complain("debuger FAILURE 1> Can't get field by name "
117
+ name);
118
log.complain("debuger FAILURE 1> Exception: " + e);
119
testFailed = true;
120
continue;
121
} catch (ObjectCollectedException e) {
122
log.complain("debuger FAILURE 1> Can't get field by name "
123
+ name);
124
log.complain("debuger FAILURE 1> Exception: " + e);
125
testFailed = true;
126
continue;
127
}
128
log.display("debuger> " + i + " field " + field + " read.");
129
130
// Get field's value
131
try {
132
value = refType.getValue(field);
133
} catch (IllegalArgumentException e) {
134
log.complain("debuger FAILURE 2> Cannot get value for field "
135
+ name);
136
log.complain("debuger FAILURE 2> Exception: " + e);
137
testFailed = true;
138
continue;
139
} catch (ObjectCollectedException e) {
140
log.complain("debuger FAILURE 2> Cannot get value for field "
141
+ name);
142
log.complain("debuger FAILURE 2> Exception: " + e);
143
testFailed = true;
144
continue;
145
}
146
log.display("debuger> " + i + " field value is " + value);
147
148
// Cast to ArrayReference. All fields in debugee are
149
// arrays, so ClassCastException should not be thrown
150
try {
151
arrayRef = (ArrayReference)value;
152
} catch (ClassCastException e) {
153
log.complain("debuger FAILURE 3> Cannot cast value for field "
154
+ name + " to ArrayReference.");
155
log.complain("debuger FAILURE 3> Exception: " + e);
156
testFailed = true;
157
continue;
158
}
159
160
// Try to get value by index from MIN_INDEX to -1 and from
161
// arrayRef.length() to MAX_INDEX
162
for (int j = MIN_INDEX; j < MAX_INDEX; j++) {
163
if ( (j < 0) || (j > lastElementIndex) ) {
164
Value arrayValue;
165
166
try {
167
arrayValue = arrayRef.getValue(j);
168
log.complain("debuger FAILURE 4> Value for " + j
169
+ " element of field " + name + " is " + arrayValue
170
+ ", but IndexOutOfBoundsException expected.");
171
testFailed = true;
172
} catch (ObjectCollectedException e) {
173
log.display("debuger> Cannot get " + j + " value from "
174
+ "field " + name);
175
log.display("debuger> Exception: " + e);
176
testFailed = true;
177
} catch (IndexOutOfBoundsException e) {
178
// Index is always out of bounds, so
179
// IndexOutOfBoundsException is expected
180
log.display("debuger> " + i + " field: cannot get "
181
+ "element with index " + j + ". Expected "
182
+ "exception: " + e);
183
}
184
}
185
}
186
log.display("debuger> " + i + " field checked.\n");
187
}
188
189
pipe.println("quit");
190
debugee.waitFor();
191
int status = debugee.getStatus();
192
if (testFailed) {
193
log.complain("debuger FAILURE> TEST FAILED");
194
return 2;
195
} else {
196
if (status == 95) {
197
log.display("debuger> expected Debugee's exit "
198
+ "status - " + status);
199
return 0;
200
} else {
201
log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "
202
+ "status (not 95) - " + status);
203
return 2;
204
}
205
}
206
}
207
}
208
209