2
|
1 |
/** hard coded linenumbers in test - DO NOT CHANGE
|
|
2 |
* @test/nodynamiccopyright/
|
|
3 |
* @bug 4386002 4429245
|
|
4 |
* @summary Test fix for: Incorrect values reported for some locals of type long
|
|
5 |
*
|
|
6 |
* @author Tim Bell
|
|
7 |
*
|
|
8 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
9 |
* @run compile -g FetchLocals.java
|
|
10 |
* @run main FetchLocals
|
|
11 |
*/
|
|
12 |
import com.sun.jdi.*;
|
|
13 |
import com.sun.jdi.event.*;
|
|
14 |
import java.util.*;
|
|
15 |
|
|
16 |
class FetchLocalsDebugee {
|
|
17 |
public long testMethod() {
|
|
18 |
short s = 12345;
|
|
19 |
int i = 8675309;
|
|
20 |
boolean pt = true;
|
|
21 |
long w = 973230999L;
|
|
22 |
byte b = 0x3b;
|
|
23 |
long x = w * 1000L;
|
|
24 |
char c = '\u005A'; // 005A = "Z"
|
|
25 |
long y = 22;
|
|
26 |
float f = 6.66f;
|
|
27 |
double d = 7.77;
|
|
28 |
|
|
29 |
System.out.print("pt is: ");
|
|
30 |
System.out.println(pt);
|
|
31 |
System.out.print("b is: ");
|
|
32 |
System.out.println(b);
|
|
33 |
System.out.print("c is: ");
|
|
34 |
System.out.println(c);
|
|
35 |
System.out.print("s is: ");
|
|
36 |
System.out.println(s);
|
|
37 |
System.out.print("i is: ");
|
|
38 |
System.out.println(i);
|
|
39 |
|
|
40 |
System.out.print("w is: ");
|
|
41 |
System.out.print(w);
|
|
42 |
System.out.print(" (0x");
|
|
43 |
System.out.print(Long.toHexString(w));
|
|
44 |
System.out.println(")");
|
|
45 |
|
|
46 |
System.out.print("x is: ");
|
|
47 |
System.out.print(x);
|
|
48 |
System.out.print(" (0x");
|
|
49 |
System.out.print(Long.toHexString(x));
|
|
50 |
System.out.println(")");
|
|
51 |
|
|
52 |
System.out.print("y is: ");
|
|
53 |
System.out.print(y);
|
|
54 |
System.out.print(" (0x");
|
|
55 |
System.out.print(Long.toHexString(y));
|
|
56 |
System.out.println(")");
|
|
57 |
|
|
58 |
System.out.print("f is: ");
|
|
59 |
System.out.println(f);
|
|
60 |
System.out.print("d is: ");
|
|
61 |
System.out.println(d);
|
|
62 |
System.out.println(); // Thie is Line 63...
|
|
63 |
if (w == 0xde00ad00be00ef00L) {
|
|
64 |
System.out.print ("The debugger was here. w modified to: 0x");
|
|
65 |
System.out.println(Long.toHexString(w));
|
|
66 |
} else {
|
|
67 |
System.out.print ("w contains : 0x");
|
|
68 |
System.out.println(Long.toHexString(w));
|
|
69 |
}
|
|
70 |
System.out.println();
|
|
71 |
return x;
|
|
72 |
}
|
|
73 |
public static void main(String[] args) {
|
|
74 |
System.out.print ("FetchLocalsDebugee");
|
|
75 |
System.out.println(" Starting up...");
|
|
76 |
FetchLocalsDebugee my = new FetchLocalsDebugee ();
|
|
77 |
long result = my.testMethod();
|
|
78 |
System.out.print ("testMethod() returned: ");
|
|
79 |
System.out.print (result);
|
|
80 |
System.out.print (" (0x");
|
|
81 |
System.out.print (Long.toHexString(result));
|
|
82 |
System.out.println(")");
|
|
83 |
|
|
84 |
System.out.print ("FetchLocalsDebugee");
|
|
85 |
System.out.println(" Shutting down...");
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
public class FetchLocals extends TestScaffold {
|
|
90 |
|
|
91 |
FetchLocals (String args[]) {
|
|
92 |
super(args);
|
|
93 |
}
|
|
94 |
|
|
95 |
public static void main(String[] args)
|
|
96 |
throws Exception
|
|
97 |
{
|
|
98 |
new FetchLocals (args).startTests();
|
|
99 |
}
|
|
100 |
|
|
101 |
/** Express a 64 bit double as a hex string
|
|
102 |
*/
|
|
103 |
private static String hexify(double d) {
|
|
104 |
long bits = Double.doubleToLongBits(d);
|
|
105 |
return (" (0x" + java.lang.Long.toHexString(bits) + ")");
|
|
106 |
}
|
|
107 |
/** Express a 32 bit float as a hex string
|
|
108 |
*/
|
|
109 |
private static String hexify(float f) {
|
|
110 |
int bits = Float.floatToIntBits(f);
|
|
111 |
return (" (0x" + java.lang.Integer.toHexString(bits) + ")");
|
|
112 |
}
|
|
113 |
|
|
114 |
protected void test(String name, BooleanValue testV, boolean expectV)
|
|
115 |
throws Exception
|
|
116 |
{
|
|
117 |
if (testV.value() != expectV) {
|
|
118 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
119 |
" should be: " + expectV);
|
|
120 |
testFailed = true;
|
|
121 |
} else {
|
|
122 |
System.out.print ("Tested OK: ");
|
|
123 |
System.out.print (name);
|
|
124 |
System.out.print (" = ");
|
|
125 |
System.out.println(expectV);
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
protected void test(String name, ByteValue testV, byte expectV)
|
|
130 |
throws Exception
|
|
131 |
{
|
|
132 |
if (testV.value() != expectV) {
|
|
133 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
134 |
" should be: " + expectV);
|
|
135 |
testFailed = true;
|
|
136 |
} else {
|
|
137 |
System.out.print ("Tested OK: ");
|
|
138 |
System.out.print (name);
|
|
139 |
System.out.print (" = ");
|
|
140 |
System.out.println(expectV);
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
protected void test(String name, CharValue testV, char expectV)
|
|
145 |
throws Exception
|
|
146 |
{
|
|
147 |
if (testV.value() != expectV) {
|
|
148 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
149 |
" should be: " + expectV);
|
|
150 |
testFailed = true;
|
|
151 |
} else {
|
|
152 |
System.out.print ("Tested OK: ");
|
|
153 |
System.out.print (name);
|
|
154 |
System.out.print (" = ");
|
|
155 |
System.out.println(expectV);
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
protected void test(String name, ShortValue testV, short expectV)
|
|
160 |
throws Exception
|
|
161 |
{
|
|
162 |
if (testV.value() != expectV) {
|
|
163 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
164 |
" should be: " + expectV);
|
|
165 |
testFailed = true;
|
|
166 |
} else {
|
|
167 |
System.out.print ("Tested OK: ");
|
|
168 |
System.out.print (name);
|
|
169 |
System.out.print (" = ");
|
|
170 |
System.out.println(expectV);
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
protected void test(String name, IntegerValue testV, int expectV)
|
|
175 |
throws Exception
|
|
176 |
{
|
|
177 |
if (testV.value() != expectV) {
|
|
178 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
179 |
" should be: " + expectV);
|
|
180 |
testFailed = true;
|
|
181 |
} else {
|
|
182 |
System.out.print ("Tested OK: ");
|
|
183 |
System.out.print (name);
|
|
184 |
System.out.print (" = ");
|
|
185 |
System.out.println(expectV);
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
protected void test(String name, LongValue testV, long expectV)
|
|
190 |
throws Exception
|
|
191 |
{
|
|
192 |
if (testV.value() != expectV) {
|
|
193 |
System.out.println("Error for " + name + " = 0x" +
|
|
194 |
Long.toHexString(testV.value()) +
|
|
195 |
" should be: 0x" +
|
|
196 |
Long.toHexString(expectV));
|
|
197 |
testFailed = true;
|
|
198 |
} else {
|
|
199 |
System.out.print ("Tested OK: ");
|
|
200 |
System.out.print (name);
|
|
201 |
System.out.print (" = ");
|
|
202 |
System.out.println(expectV);
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
protected void test(String name, FloatValue testV, float expectV)
|
|
207 |
throws Exception
|
|
208 |
{
|
|
209 |
if (testV.value() != expectV) {
|
|
210 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
211 |
hexify(testV.value()) +
|
|
212 |
" should be: " + expectV +
|
|
213 |
hexify(expectV));
|
|
214 |
testFailed = true;
|
|
215 |
} else {
|
|
216 |
System.out.print ("Tested OK: ");
|
|
217 |
System.out.print (name);
|
|
218 |
System.out.print (" = ");
|
|
219 |
System.out.println(expectV);
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
protected void test(String name, DoubleValue testV, double expectV)
|
|
224 |
throws Exception
|
|
225 |
{
|
|
226 |
if (testV.value() != expectV) {
|
|
227 |
System.out.println("Error for " + name + " = " + testV.value() +
|
|
228 |
hexify(testV.value()) +
|
|
229 |
" should be: " + expectV +
|
|
230 |
hexify(expectV));
|
|
231 |
testFailed = true;
|
|
232 |
} else {
|
|
233 |
System.out.print ("Tested OK: ");
|
|
234 |
System.out.print (name);
|
|
235 |
System.out.print (" = ");
|
|
236 |
System.out.println(expectV);
|
|
237 |
}
|
|
238 |
}
|
|
239 |
|
|
240 |
protected void testLocalVariables (StackFrame sf)
|
|
241 |
throws Exception
|
|
242 |
{
|
|
243 |
/*
|
|
244 |
* Test values in the local method testMethod ():
|
|
245 |
* 1) Read current data
|
|
246 |
* 2) Test against the expected value
|
|
247 |
* 3) Set to a new value
|
|
248 |
* 4) Read again
|
|
249 |
* 5) Test against the expected value
|
|
250 |
*/
|
|
251 |
LocalVariable lv = sf.visibleVariableByName("pt");
|
|
252 |
BooleanValue booleanV = (BooleanValue) sf.getValue(lv);
|
|
253 |
test("pt", booleanV, true);
|
|
254 |
booleanV = vm().mirrorOf(false);
|
|
255 |
sf.setValue(lv, booleanV);
|
|
256 |
booleanV = (BooleanValue) sf.getValue(lv);
|
|
257 |
test("pt", booleanV, false);
|
|
258 |
|
|
259 |
lv = sf.visibleVariableByName("b");
|
|
260 |
ByteValue byteV = (ByteValue) sf.getValue(lv);
|
|
261 |
byte bTmp = 0x3b;
|
|
262 |
test("b", byteV, bTmp);
|
|
263 |
bTmp = 0x7e;
|
|
264 |
byteV = vm().mirrorOf(bTmp);
|
|
265 |
sf.setValue(lv, byteV);
|
|
266 |
byteV = (ByteValue) sf.getValue(lv);
|
|
267 |
test("b", byteV, bTmp);
|
|
268 |
|
|
269 |
lv = sf.visibleVariableByName("c");
|
|
270 |
CharValue charV = (CharValue) sf.getValue(lv);
|
|
271 |
char cTmp = '\u005A';
|
|
272 |
test("c", charV, cTmp);
|
|
273 |
cTmp = 'A';
|
|
274 |
charV = vm().mirrorOf(cTmp);
|
|
275 |
sf.setValue(lv, charV);
|
|
276 |
charV = (CharValue) sf.getValue(lv);
|
|
277 |
test("c", charV, cTmp);
|
|
278 |
|
|
279 |
lv = sf.visibleVariableByName("s");
|
|
280 |
ShortValue shortV = (ShortValue) sf.getValue(lv);
|
|
281 |
short sTmp = 12345;
|
|
282 |
test("s", shortV, sTmp);
|
|
283 |
sTmp = -32766;
|
|
284 |
shortV = vm().mirrorOf(sTmp);
|
|
285 |
sf.setValue(lv, shortV);
|
|
286 |
shortV = (ShortValue) sf.getValue(lv);
|
|
287 |
test("s", shortV, sTmp);
|
|
288 |
|
|
289 |
lv = sf.visibleVariableByName("i");
|
|
290 |
IntegerValue integerV = (IntegerValue) sf.getValue(lv);
|
|
291 |
int iTmp = 8675309;
|
|
292 |
test("i", integerV, iTmp);
|
|
293 |
iTmp = -42;
|
|
294 |
integerV = vm().mirrorOf(iTmp);
|
|
295 |
sf.setValue(lv, integerV);
|
|
296 |
integerV = (IntegerValue) sf.getValue(lv);
|
|
297 |
test("i", integerV, iTmp);
|
|
298 |
|
|
299 |
lv = sf.visibleVariableByName("w");
|
|
300 |
LongValue longV = (LongValue) sf.getValue(lv);
|
|
301 |
long wTmp = 973230999L;
|
|
302 |
test("w", longV, wTmp);
|
|
303 |
wTmp = 0xde00ad00be00ef00L;
|
|
304 |
longV = vm().mirrorOf(wTmp);
|
|
305 |
sf.setValue(lv, longV);
|
|
306 |
longV = (LongValue) sf.getValue(lv);
|
|
307 |
test("w", longV, wTmp);
|
|
308 |
|
|
309 |
lv = sf.visibleVariableByName("x");
|
|
310 |
longV = (LongValue) sf.getValue(lv);
|
|
311 |
long xTmp = 973230999L * 1000L;
|
|
312 |
test("x", longV, xTmp);
|
|
313 |
xTmp = 0xca00fe00ba00be00L;
|
|
314 |
longV = vm().mirrorOf(xTmp);
|
|
315 |
sf.setValue(lv, longV);
|
|
316 |
longV = (LongValue) sf.getValue(lv);
|
|
317 |
test("x", longV, xTmp);
|
|
318 |
|
|
319 |
lv = sf.visibleVariableByName("y");
|
|
320 |
longV = (LongValue) sf.getValue(lv);
|
|
321 |
long yTmp = 22;
|
|
322 |
test("y", longV, yTmp);
|
|
323 |
yTmp = 0xdeadbeefcafebabeL;
|
|
324 |
longV = vm().mirrorOf(yTmp);
|
|
325 |
sf.setValue(lv, longV);
|
|
326 |
longV = (LongValue) sf.getValue(lv);
|
|
327 |
test("x", longV, yTmp);
|
|
328 |
|
|
329 |
lv = sf.visibleVariableByName("f");
|
|
330 |
FloatValue floatV = (FloatValue) sf.getValue(lv);
|
|
331 |
float fTmp = 6.66f;
|
|
332 |
test("f", floatV, fTmp);
|
|
333 |
fTmp = (float)java.lang.Math.PI;
|
|
334 |
floatV = vm().mirrorOf(fTmp);
|
|
335 |
sf.setValue(lv, floatV);
|
|
336 |
floatV = (FloatValue)sf.getValue(lv);
|
|
337 |
test("f", floatV, fTmp);
|
|
338 |
|
|
339 |
lv = sf.visibleVariableByName("d");
|
|
340 |
DoubleValue doubleV = (DoubleValue) sf.getValue(lv);
|
|
341 |
double dTmp = 7.77;
|
|
342 |
test("d", doubleV, dTmp);
|
|
343 |
dTmp = java.lang.Math.E;
|
|
344 |
doubleV = vm().mirrorOf(dTmp);
|
|
345 |
sf.setValue(lv, doubleV);
|
|
346 |
doubleV = (DoubleValue) sf.getValue(lv);
|
|
347 |
test("d", doubleV, dTmp);
|
|
348 |
}
|
|
349 |
|
|
350 |
protected void runTests()
|
|
351 |
throws Exception
|
|
352 |
{
|
|
353 |
startToMain("FetchLocalsDebugee");
|
|
354 |
/*
|
|
355 |
* Get to the bottom of testMethod():
|
|
356 |
*/
|
|
357 |
try {
|
|
358 |
BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", 63);
|
|
359 |
/*
|
|
360 |
* Fetch values from fields; what did we get?
|
|
361 |
*/
|
|
362 |
StackFrame sf = bpe.thread().frame(0);
|
|
363 |
testLocalVariables (sf);
|
|
364 |
|
|
365 |
} catch(Exception ex) {
|
|
366 |
ex.printStackTrace();
|
|
367 |
testFailed = true;
|
|
368 |
} finally {
|
|
369 |
// Allow application to complete and shut down
|
|
370 |
resumeToVMDisconnect();
|
|
371 |
}
|
|
372 |
if (!testFailed) {
|
|
373 |
System.out.println("FetchLocals: passed");
|
|
374 |
} else {
|
|
375 |
throw new Exception("FetchLocals: failed");
|
|
376 |
}
|
|
377 |
}
|
|
378 |
}
|