2
|
1 |
/*
|
|
2 |
* Copyright 2005-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6175634
|
|
27 |
* @summary Allow early return from methods
|
|
28 |
*
|
|
29 |
* @bug 6431720
|
|
30 |
* @summary Unexpected InvalidTypeException when call ThreadReference.forceEarlyReturn with VoidValue
|
|
31 |
*
|
|
32 |
* @bug 6432855
|
|
33 |
* @summary Need a way to create JDI VoidValue for use in ThreadReference.forceEarlyReturn
|
|
34 |
*
|
|
35 |
* @author Tim Bell (based on MethodExitReturnValuesTest by Jim Holmlund)
|
|
36 |
*
|
|
37 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
38 |
* @run compile -g EarlyReturnTest.java
|
|
39 |
* @run main EarlyReturnTest
|
|
40 |
*/
|
|
41 |
import com.sun.jdi.*;
|
|
42 |
import com.sun.jdi.event.*;
|
|
43 |
import com.sun.jdi.request.*;
|
|
44 |
import java.util.*;
|
|
45 |
import java.net.URLClassLoader;
|
|
46 |
import java.net.URL;
|
|
47 |
import java.lang.reflect.Array;
|
|
48 |
|
|
49 |
/*
|
|
50 |
* This test has a debuggee which calls a static method
|
|
51 |
* for each kind of JDI Value, and then an instance method
|
|
52 |
* for each.
|
|
53 |
*
|
|
54 |
* The debugger sets breakpoints in all methods. When a breakpoint
|
|
55 |
* is hit the debugger requests an early return and supplies a new
|
|
56 |
* return value. It then checks that the correct return values are
|
|
57 |
* included in the MethodExitEvents.
|
|
58 |
*
|
|
59 |
* Each value is stored in a static var in the debuggee. The debugger
|
|
60 |
* gets the values from these static vars to check for correct
|
|
61 |
* return values in the MethodExitEvents.
|
|
62 |
*/
|
|
63 |
|
|
64 |
class EarlyReturnTarg {
|
|
65 |
static boolean debuggerWatching = false;
|
|
66 |
static int failureCount = 0;
|
|
67 |
/*
|
|
68 |
* These are the values that will be used by methods
|
|
69 |
* returning normally.
|
|
70 |
*/
|
|
71 |
static URL[] urls = new URL[1];
|
|
72 |
public static byte byteValue = 89;
|
|
73 |
public static char charValue = 'x';
|
|
74 |
public static double doubleValue = 2.2;
|
|
75 |
public static float floatValue = 3.3f;
|
|
76 |
public static int intValue = 1;
|
|
77 |
public static long longValue = Long.MAX_VALUE;
|
|
78 |
public static short shortValue = 8;
|
|
79 |
public static boolean booleanValue = false;
|
|
80 |
|
|
81 |
public static Class classValue = Object.class;
|
|
82 |
public static ClassLoader classLoaderValue;
|
|
83 |
{
|
|
84 |
try {
|
|
85 |
urls[0] = new URL("hi there");
|
|
86 |
} catch (java.net.MalformedURLException ee) {
|
|
87 |
}
|
|
88 |
classLoaderValue = new URLClassLoader(urls);
|
|
89 |
}
|
|
90 |
|
|
91 |
public static Thread threadValue = Thread.currentThread();
|
|
92 |
public static ThreadGroup threadGroupValue = threadValue.getThreadGroup();
|
|
93 |
public static String stringValue = "abc";
|
|
94 |
public static int[] intArrayValue = new int[] {1, 2, 3};
|
|
95 |
|
|
96 |
public static EarlyReturnTarg objectValue =
|
|
97 |
new EarlyReturnTarg();
|
|
98 |
public String ivar = stringValue;
|
|
99 |
|
|
100 |
/*
|
|
101 |
* These are the values that will be used by methods
|
|
102 |
* returning early. These are != the normal values
|
|
103 |
* defined above.
|
|
104 |
*/
|
|
105 |
static URL[] eurls = new URL[1];
|
|
106 |
public static byte ebyteValue = 42;
|
|
107 |
public static char echarValue = 'a';
|
|
108 |
public static double edoubleValue = 6.6;
|
|
109 |
public static float efloatValue = 9.9f;
|
|
110 |
public static int eintValue = 7;
|
|
111 |
public static long elongValue = Long.MIN_VALUE;
|
|
112 |
public static short eshortValue = 3;
|
|
113 |
public static boolean ebooleanValue = true;
|
|
114 |
|
|
115 |
public static Class eclassValue = String.class;
|
|
116 |
public static ClassLoader eclassLoaderValue;
|
|
117 |
{
|
|
118 |
try {
|
|
119 |
urls[0] = new URL("been there, done that");
|
|
120 |
} catch (java.net.MalformedURLException ee) {
|
|
121 |
}
|
|
122 |
classLoaderValue = new URLClassLoader(urls);
|
|
123 |
}
|
|
124 |
public static Thread ethreadValue;
|
|
125 |
public static ThreadGroup ethreadGroupValue;
|
|
126 |
public static String estringValue = "wxyz";
|
|
127 |
public static int[] eintArrayValue = new int[] {10, 11, 12};
|
|
128 |
|
|
129 |
public static java.util.Date eobjectValue = new java.util.Date();
|
|
130 |
|
|
131 |
// Used to check the return values seen on the debugee side
|
|
132 |
public static boolean chk(byte v) {
|
|
133 |
return v == (debuggerWatching ? ebyteValue: byteValue);
|
|
134 |
}
|
|
135 |
public static boolean chk(char v) {
|
|
136 |
return v == (debuggerWatching ? echarValue: charValue);
|
|
137 |
}
|
|
138 |
public static boolean chk(double v) {
|
|
139 |
return v == (debuggerWatching ? edoubleValue: doubleValue);
|
|
140 |
}
|
|
141 |
public static boolean chk(float v) {
|
|
142 |
return v == (debuggerWatching ? efloatValue: floatValue);
|
|
143 |
}
|
|
144 |
public static boolean chk(int v) {
|
|
145 |
return v == (debuggerWatching ? eintValue: intValue);
|
|
146 |
}
|
|
147 |
public static boolean chk(long v) {
|
|
148 |
return v == (debuggerWatching ? elongValue: longValue);
|
|
149 |
}
|
|
150 |
public static boolean chk(short v) {
|
|
151 |
return v == (debuggerWatching ? eshortValue: shortValue);
|
|
152 |
}
|
|
153 |
public static boolean chk(boolean v) {
|
|
154 |
return v == (debuggerWatching ? ebooleanValue: booleanValue);
|
|
155 |
}
|
|
156 |
public static boolean chk(String v) {
|
|
157 |
return v.equals(debuggerWatching ? estringValue: stringValue);
|
|
158 |
}
|
|
159 |
public static boolean chk(Object v) {
|
|
160 |
return v.equals(debuggerWatching ? eobjectValue: objectValue);
|
|
161 |
}
|
|
162 |
|
|
163 |
// Used to show which set of tests follows
|
|
164 |
public static String s_show(String p1) { return p1;}
|
|
165 |
|
|
166 |
// These are the static methods
|
|
167 |
public static byte s_bytef(int p1){ return byteValue; }
|
|
168 |
public static char s_charf() { return charValue; }
|
|
169 |
public static double s_doublef() { return doubleValue; }
|
|
170 |
public static float s_floatf() { return floatValue; }
|
|
171 |
public static int s_intf() { return intValue; }
|
|
172 |
public static long s_longf() { return longValue; }
|
|
173 |
public static short s_shortf() { return shortValue; }
|
|
174 |
public static boolean s_booleanf(){ return booleanValue; }
|
|
175 |
public static String s_stringf() { return stringValue; }
|
|
176 |
public static Class s_classf() { return classValue; }
|
|
177 |
public static ClassLoader s_classLoaderf()
|
|
178 |
{ return classLoaderValue; }
|
|
179 |
public static Thread s_threadf() { return threadValue; }
|
|
180 |
public static ThreadGroup s_threadGroupf()
|
|
181 |
{ return threadGroupValue; }
|
|
182 |
public static int[] s_intArrayf() { return intArrayValue; }
|
|
183 |
public static Object s_nullObjectf() { return null; }
|
|
184 |
public static Object s_objectf() { return objectValue; }
|
|
185 |
public static void s_voidf() { System.err.println("debugee in s_voidf");}
|
|
186 |
|
|
187 |
// These are the instance methods
|
|
188 |
public byte i_bytef(int p1) { return byteValue; }
|
|
189 |
public char i_charf() { return charValue; }
|
|
190 |
public double i_doublef() { return doubleValue; }
|
|
191 |
public float i_floatf() { return floatValue; }
|
|
192 |
public int i_intf() { return intValue; }
|
|
193 |
public long i_longf() { return longValue; }
|
|
194 |
public short i_shortf() { return shortValue; }
|
|
195 |
public boolean i_booleanf() { return booleanValue; }
|
|
196 |
public String i_stringf() { return stringValue; }
|
|
197 |
public Class i_classf() { return classValue; }
|
|
198 |
public ClassLoader i_classLoaderf()
|
|
199 |
{ return classLoaderValue; }
|
|
200 |
public Thread i_threadf() { return threadValue; }
|
|
201 |
public ThreadGroup i_threadGroupf()
|
|
202 |
{ return threadGroupValue; }
|
|
203 |
public int[] i_intArrayf() { return intArrayValue; }
|
|
204 |
public Object i_nullObjectf() { return null; }
|
|
205 |
public Object i_objectf() { return objectValue; }
|
|
206 |
public void i_voidf() {}
|
|
207 |
|
|
208 |
static void doit(EarlyReturnTarg xx) throws Exception {
|
|
209 |
System.err.print("debugee in doit ");
|
|
210 |
if (debuggerWatching) {
|
|
211 |
System.err.println("with a debugger watching. Early returns expected.");
|
|
212 |
} else {
|
|
213 |
System.err.println("with no debugger watching. Normal returns.");
|
|
214 |
}
|
|
215 |
|
|
216 |
s_show("========== Testing static methods ================");
|
|
217 |
if (!chk( s_bytef(88))) failureCount++;
|
|
218 |
if (!chk( s_charf())) failureCount++;
|
|
219 |
if (!chk( s_doublef())) failureCount++;
|
|
220 |
if (!chk( s_floatf())) failureCount++;
|
|
221 |
if (!chk( s_intf())) failureCount++;
|
|
222 |
if (!chk( s_longf())) failureCount++;
|
|
223 |
if (!chk( s_shortf())) failureCount++;
|
|
224 |
if (!chk( s_booleanf())) failureCount++;
|
|
225 |
|
|
226 |
if (!chk( s_stringf())) failureCount++;
|
|
227 |
s_classf();
|
|
228 |
s_classLoaderf();
|
|
229 |
s_threadf();
|
|
230 |
s_threadGroupf();
|
|
231 |
s_intArrayf();
|
|
232 |
s_nullObjectf();
|
|
233 |
if (!chk( s_objectf())) failureCount++;
|
|
234 |
s_voidf();
|
|
235 |
|
|
236 |
s_show("========== Testing instance methods ================");
|
|
237 |
if (!chk( xx.i_bytef(89))) failureCount++;
|
|
238 |
if (!chk( xx.i_charf())) failureCount++;
|
|
239 |
if (!chk( xx.i_doublef())) failureCount++;
|
|
240 |
if (!chk( xx.i_floatf())) failureCount++;
|
|
241 |
if (!chk( xx.i_intf())) failureCount++;
|
|
242 |
if (!chk( xx.i_longf())) failureCount++;
|
|
243 |
if (!chk( xx.i_shortf())) failureCount++;
|
|
244 |
if (!chk( xx.i_booleanf())) failureCount++;
|
|
245 |
if (!chk( xx.i_stringf())) failureCount++;
|
|
246 |
xx.i_intArrayf();
|
|
247 |
xx.i_classf();
|
|
248 |
xx.i_classLoaderf();
|
|
249 |
xx.i_threadf();
|
|
250 |
xx.i_threadGroupf();
|
|
251 |
xx.i_nullObjectf();
|
|
252 |
if (!chk( xx.i_objectf())) failureCount++;
|
|
253 |
xx.i_voidf();
|
|
254 |
|
|
255 |
}
|
|
256 |
|
|
257 |
/** Hang so that test fails */
|
|
258 |
static void hang() {
|
|
259 |
try {
|
|
260 |
// ten minute nap
|
|
261 |
Thread.currentThread().sleep(10 * 60 * 1000);
|
|
262 |
} catch (InterruptedException exc) {
|
|
263 |
// shouldn't happen
|
|
264 |
}
|
|
265 |
}
|
|
266 |
|
|
267 |
public static void main(String[] args) throws Exception {
|
|
268 |
// The debugger will stop at the start of main,
|
|
269 |
// set breakpoints and then do a resume.
|
|
270 |
System.err.println("debugee in main");
|
|
271 |
EarlyReturnTarg xx =
|
|
272 |
new EarlyReturnTarg();
|
|
273 |
|
|
274 |
doit(xx);
|
|
275 |
if (debuggerWatching && failureCount > 0) {
|
|
276 |
hang();
|
|
277 |
throw new Exception("EarlyReturnTarg: failed");
|
|
278 |
}
|
|
279 |
}
|
|
280 |
}
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
public class EarlyReturnTest extends TestScaffold {
|
|
285 |
|
|
286 |
|
|
287 |
/*
|
|
288 |
* Class patterns for which we don't want events (copied
|
|
289 |
* from the "Trace.java" example):
|
|
290 |
* http://java.sun.com/javase/technologies/core/toolsapis/jpda/
|
|
291 |
*/
|
|
292 |
private String[] excludes = {
|
|
293 |
"javax.*",
|
|
294 |
"sun.*",
|
|
295 |
"com.sun.*"};
|
|
296 |
|
|
297 |
static VirtualMachineManager vmm ;
|
|
298 |
ClassType targetClass;
|
|
299 |
Field theValueField;
|
|
300 |
static int earlyReturns = 0;
|
|
301 |
static final int expectedEarlyReturns = 34; // determined by inspection :-)
|
|
302 |
|
|
303 |
EarlyReturnTest(String args[]) {
|
|
304 |
super(args);
|
|
305 |
}
|
|
306 |
|
|
307 |
public static void main(String[] args) throws Exception {
|
|
308 |
EarlyReturnTest meee = new EarlyReturnTest(args);
|
|
309 |
vmm = Bootstrap.virtualMachineManager();
|
|
310 |
meee.startTests();
|
|
311 |
}
|
|
312 |
|
|
313 |
// chkXXX methods lifted directly from MethodExitReturnValuesTest
|
|
314 |
// These methods check for correct return values. Thanks, Jim!
|
|
315 |
void ckByteValue(Value retValue) {
|
|
316 |
Field theValueField = targetClass.fieldByName("ebyteValue");
|
|
317 |
ByteValue theValue = (ByteValue)targetClass.getValue(theValueField);
|
|
318 |
|
|
319 |
byte vv = theValue.value();
|
|
320 |
byte rv = ((ByteValue)retValue).value();
|
|
321 |
if (vv != rv) {
|
|
322 |
failure("failure: byte: expected " + vv + ", got " + rv);
|
|
323 |
} else {
|
|
324 |
System.out.println("Passed: byte " + rv);
|
|
325 |
earlyReturns++;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
void ckCharValue(Value retValue) {
|
|
330 |
Field theValueField = targetClass.fieldByName("echarValue");
|
|
331 |
CharValue theValue = (CharValue)targetClass.getValue(theValueField);
|
|
332 |
|
|
333 |
char vv = theValue.value();
|
|
334 |
char rv = ((CharValue)retValue).value();
|
|
335 |
if (vv != rv) {
|
|
336 |
failure("failure: char: expected " + vv + ", got " + rv);
|
|
337 |
} else {
|
|
338 |
System.out.println("Passed: char " + rv);
|
|
339 |
earlyReturns++;
|
|
340 |
}
|
|
341 |
}
|
|
342 |
|
|
343 |
void ckDoubleValue(Value retValue) {
|
|
344 |
Field theValueField = targetClass.fieldByName("edoubleValue");
|
|
345 |
DoubleValue theValue = (DoubleValue)targetClass.getValue(theValueField);
|
|
346 |
|
|
347 |
double vv = theValue.value();
|
|
348 |
double rv = ((DoubleValue)retValue).value();
|
|
349 |
if (vv != rv) {
|
|
350 |
failure("failure: double: expected " + vv + ", got " + rv);
|
|
351 |
} else {
|
|
352 |
System.out.println("Passed: double " + rv);
|
|
353 |
earlyReturns++;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
|
|
357 |
void ckFloatValue(Value retValue) {
|
|
358 |
Field theValueField = targetClass.fieldByName("efloatValue");
|
|
359 |
FloatValue theValue = (FloatValue)targetClass.getValue(theValueField);
|
|
360 |
|
|
361 |
float vv = theValue.value();
|
|
362 |
float rv = ((FloatValue)retValue).value();
|
|
363 |
if (vv != rv) {
|
|
364 |
failure("failure: float: expected " + vv + ", got " + rv);
|
|
365 |
} else {
|
|
366 |
System.out.println("Passed: float " + rv);
|
|
367 |
earlyReturns++;
|
|
368 |
}
|
|
369 |
}
|
|
370 |
|
|
371 |
void ckIntValue(Value retValue) {
|
|
372 |
Field theValueField = targetClass.fieldByName("eintValue");
|
|
373 |
IntegerValue theValue = (IntegerValue)targetClass.getValue(theValueField);
|
|
374 |
|
|
375 |
int vv = theValue.value();
|
|
376 |
int rv = ((IntegerValue)retValue).value();
|
|
377 |
if (vv != rv) {
|
|
378 |
failure("failure: int: expected " + vv + ", got " + rv);
|
|
379 |
} else {
|
|
380 |
System.out.println("Passed: int " + rv);
|
|
381 |
earlyReturns++;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
void ckLongValue(Value retValue) {
|
|
386 |
Field theValueField = targetClass.fieldByName("elongValue");
|
|
387 |
LongValue theValue = (LongValue)targetClass.getValue(theValueField);
|
|
388 |
|
|
389 |
long vv = theValue.value();
|
|
390 |
long rv = ((LongValue)retValue).value();
|
|
391 |
if (vv != rv) {
|
|
392 |
failure("failure: long: expected " + vv + ", got " + rv);
|
|
393 |
} else {
|
|
394 |
System.out.println("Passed: long " + rv);
|
|
395 |
earlyReturns++;
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
void ckShortValue(Value retValue) {
|
|
400 |
Field theValueField = targetClass.fieldByName("eshortValue");
|
|
401 |
ShortValue theValue = (ShortValue)targetClass.getValue(theValueField);
|
|
402 |
|
|
403 |
short vv = theValue.value();
|
|
404 |
short rv = ((ShortValue)retValue).value();
|
|
405 |
if (vv != rv) {
|
|
406 |
failure("failure: short: expected " + vv + ", got " + rv);
|
|
407 |
} else {
|
|
408 |
System.out.println("Passed: short " + rv);
|
|
409 |
earlyReturns++;
|
|
410 |
}
|
|
411 |
}
|
|
412 |
|
|
413 |
void ckBooleanValue(Value retValue) {
|
|
414 |
Field theValueField = targetClass.fieldByName("ebooleanValue");
|
|
415 |
BooleanValue theValue = (BooleanValue)targetClass.getValue(theValueField);
|
|
416 |
|
|
417 |
boolean vv = theValue.value();
|
|
418 |
boolean rv = ((BooleanValue)retValue).value();
|
|
419 |
if (vv != rv) {
|
|
420 |
failure("failure: boolean: expected " + vv + ", got " + rv);
|
|
421 |
} else {
|
|
422 |
System.out.println("Passed: boolean " + rv);
|
|
423 |
earlyReturns++;
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
void ckStringValue(Value retValue) {
|
|
428 |
Field theValueField = targetClass.fieldByName("estringValue");
|
|
429 |
StringReference theValue = (StringReference)targetClass.getValue(theValueField);
|
|
430 |
|
|
431 |
String vv = theValue.value();
|
|
432 |
String rv = ((StringReference)retValue).value();
|
|
433 |
if (vv != rv) {
|
|
434 |
failure("failure: String: expected " + vv + ", got " + rv);
|
|
435 |
} else {
|
|
436 |
System.out.println("Passed: String: " + rv);
|
|
437 |
earlyReturns++;
|
|
438 |
}
|
|
439 |
}
|
|
440 |
|
|
441 |
void ckClassValue(Value retValue) {
|
|
442 |
Field theValueField = targetClass.fieldByName("eclassValue");
|
|
443 |
ClassObjectReference vv = (ClassObjectReference)targetClass.
|
|
444 |
getValue(theValueField);
|
|
445 |
|
|
446 |
ClassObjectReference rv = (ClassObjectReference)retValue;
|
|
447 |
if (vv != rv) {
|
|
448 |
failure("failure: Class: expected " + vv + ", got " + rv);
|
|
449 |
} else {
|
|
450 |
System.out.println("Passed: Class: " + rv);
|
|
451 |
earlyReturns++;
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
void ckClassLoaderValue(Value retValue) {
|
|
456 |
Field theValueField = targetClass.fieldByName("eclassLoaderValue");
|
|
457 |
ClassLoaderReference vv = (ClassLoaderReference)targetClass.
|
|
458 |
getValue(theValueField);
|
|
459 |
|
|
460 |
ClassLoaderReference rv = (ClassLoaderReference)retValue;
|
|
461 |
if (vv != rv) {
|
|
462 |
failure("failure: ClassLoader: expected " + vv + ", got " + rv);
|
|
463 |
} else {
|
|
464 |
System.out.println("Passed: ClassLoader: " + rv);
|
|
465 |
earlyReturns++;
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
void ckThreadValue(Value retValue) {
|
|
470 |
Field theValueField = targetClass.fieldByName("ethreadValue");
|
|
471 |
ThreadReference vv = (ThreadReference)targetClass.
|
|
472 |
getValue(theValueField);
|
|
473 |
|
|
474 |
ThreadReference rv = (ThreadReference)retValue;
|
|
475 |
if (vv != rv) {
|
|
476 |
failure("failure: Thread: expected " + vv + ", got " + rv);
|
|
477 |
} else {
|
|
478 |
System.out.println("Passed: Thread: " + rv);
|
|
479 |
earlyReturns++;
|
|
480 |
}
|
|
481 |
}
|
|
482 |
|
|
483 |
void ckThreadGroupValue(Value retValue) {
|
|
484 |
Field theValueField = targetClass.fieldByName("ethreadGroupValue");
|
|
485 |
ThreadGroupReference vv = (ThreadGroupReference)targetClass.
|
|
486 |
getValue(theValueField);
|
|
487 |
|
|
488 |
ThreadGroupReference rv = (ThreadGroupReference)retValue;
|
|
489 |
if (vv != rv) {
|
|
490 |
failure("failure: ThreadgGroup: expected " + vv + ", got " + rv);
|
|
491 |
} else {
|
|
492 |
System.out.println("Passed: ThreadGroup: " + rv);
|
|
493 |
earlyReturns++;
|
|
494 |
}
|
|
495 |
}
|
|
496 |
|
|
497 |
void ckArrayValue(Value retValue) {
|
|
498 |
Field theValueField = targetClass.fieldByName("eintArrayValue");
|
|
499 |
ArrayReference theValue = (ArrayReference)targetClass.getValue(theValueField);
|
|
500 |
IntegerValue theElem2 = (IntegerValue)theValue.getValue(2);
|
|
501 |
|
|
502 |
ArrayReference theRetValue = (ArrayReference)retValue;
|
|
503 |
IntegerValue retElem2 = (IntegerValue)theRetValue.getValue(2);
|
|
504 |
int vv = theElem2.value();
|
|
505 |
int rv = retElem2.value();
|
|
506 |
if (vv != rv) {
|
|
507 |
failure("failure: in[2]: expected " + vv + ", got " + rv);
|
|
508 |
} else {
|
|
509 |
System.out.println("Passed: int[2]: " + rv);
|
|
510 |
earlyReturns++;
|
|
511 |
}
|
|
512 |
}
|
|
513 |
|
|
514 |
void ckNullObjectValue(Value retValue) {
|
|
515 |
if (retValue != null) {
|
|
516 |
failure("failure: NullObject: expected " + null + ", got " + retValue);
|
|
517 |
} else {
|
|
518 |
System.out.println("Passed: NullObject: " + retValue);
|
|
519 |
earlyReturns++;
|
|
520 |
}
|
|
521 |
}
|
|
522 |
|
|
523 |
void ckObjectValue(Value retValue) {
|
|
524 |
ObjectReference theRetValue = (ObjectReference)retValue;
|
|
525 |
|
|
526 |
Field theIVarField = targetClass.fieldByName("eobjectValue");
|
|
527 |
ObjectReference theRetValField = (ObjectReference)targetClass.getValue(theIVarField);
|
|
528 |
|
|
529 |
if (! theRetValue.equals(theRetValField)) {
|
|
530 |
failure("failure: Object: expected " + theIVarField + ", got " + theRetValField);
|
|
531 |
} else {
|
|
532 |
System.out.println("Passed: Object: " + theRetValField);
|
|
533 |
earlyReturns++;
|
|
534 |
}
|
|
535 |
}
|
|
536 |
|
|
537 |
void ckVoidValue(Value retValue) {
|
|
538 |
System.out.println("Passed: Void");
|
|
539 |
earlyReturns++;
|
|
540 |
}
|
|
541 |
|
|
542 |
public BreakpointRequest setBreakpoint(String clsName,
|
|
543 |
String methodName,
|
|
544 |
String methodSignature) {
|
|
545 |
ReferenceType rt = findReferenceType(clsName);
|
|
546 |
if (rt == null) {
|
|
547 |
rt = resumeToPrepareOf(clsName).referenceType();
|
|
548 |
}
|
|
549 |
|
|
550 |
Method method = findMethod(rt, methodName, methodSignature);
|
|
551 |
if (method == null) {
|
|
552 |
throw new IllegalArgumentException("Bad method name/signature");
|
|
553 |
}
|
|
554 |
BreakpointRequest bpr = eventRequestManager().createBreakpointRequest(method.location());
|
|
555 |
bpr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
|
|
556 |
bpr.enable();
|
|
557 |
return bpr;
|
|
558 |
}
|
|
559 |
|
|
560 |
public void breakpointReached(BreakpointEvent event) {
|
|
561 |
String origMethodName = event.location().method().name();
|
|
562 |
String methodName = origMethodName.substring(2);
|
|
563 |
ThreadReference tr = event.thread();
|
|
564 |
|
|
565 |
if (vmm.majorInterfaceVersion() >= 1 &&
|
|
566 |
vmm.minorInterfaceVersion() >= 6 &&
|
|
567 |
vm().canForceEarlyReturn()) {
|
|
568 |
|
|
569 |
try {
|
|
570 |
|
|
571 |
if ("bytef".equals(methodName)){
|
|
572 |
Field theValueField = targetClass.fieldByName("ebyteValue");
|
|
573 |
ByteValue theValue = (ByteValue)targetClass.getValue(theValueField);
|
|
574 |
tr.forceEarlyReturn(theValue);
|
|
575 |
/*
|
|
576 |
* See what happens if we access the stack after the force
|
|
577 |
* and before the resume. Disabling this since spec says
|
|
578 |
* the stack is undefined. This type of code can be used to
|
|
579 |
* pursue just what that means.
|
|
580 |
*
|
|
581 |
* StackFrame sf = tr.frame(0);
|
|
582 |
* List<Value> ll = sf.getArgumentValues();
|
|
583 |
* for (Value vv: ll) {
|
|
584 |
* System.out.println("vv = " + vv);
|
|
585 |
* }
|
|
586 |
*/
|
|
587 |
} else if ("charf".equals(methodName)) {
|
|
588 |
Field theValueField = targetClass.fieldByName("echarValue");
|
|
589 |
CharValue theValue = (CharValue)targetClass.getValue(theValueField);
|
|
590 |
tr.forceEarlyReturn(theValue);
|
|
591 |
} else if ("doublef".equals(methodName)) {
|
|
592 |
Field theValueField = targetClass.fieldByName("edoubleValue");
|
|
593 |
DoubleValue theValue = (DoubleValue)targetClass.getValue(theValueField);
|
|
594 |
tr.forceEarlyReturn(theValue);
|
|
595 |
} else if ("floatf".equals(methodName)) {
|
|
596 |
Field theValueField = targetClass.fieldByName("efloatValue");
|
|
597 |
FloatValue theValue = (FloatValue)targetClass.getValue(theValueField);
|
|
598 |
tr.forceEarlyReturn(theValue);
|
|
599 |
} else if ("intf".equals(methodName)) {
|
|
600 |
Field theValueField = targetClass.fieldByName("eintValue");
|
|
601 |
IntegerValue theValue = (IntegerValue)targetClass.getValue(theValueField);
|
|
602 |
tr.forceEarlyReturn(theValue);
|
|
603 |
} else if ("longf".equals(methodName)) {
|
|
604 |
Field theValueField = targetClass.fieldByName("elongValue");
|
|
605 |
LongValue theValue = (LongValue)targetClass.getValue(theValueField);
|
|
606 |
tr.forceEarlyReturn(theValue);
|
|
607 |
} else if ("shortf".equals(methodName)) {
|
|
608 |
Field theValueField = targetClass.fieldByName("eshortValue");
|
|
609 |
ShortValue theValue = (ShortValue)targetClass.getValue(theValueField);
|
|
610 |
tr.forceEarlyReturn(theValue);
|
|
611 |
} else if ("booleanf".equals(methodName)) {
|
|
612 |
Field theValueField = targetClass.fieldByName("ebooleanValue");
|
|
613 |
BooleanValue theValue = (BooleanValue)targetClass.getValue(theValueField);
|
|
614 |
tr.forceEarlyReturn(theValue);
|
|
615 |
} else if ("stringf".equals(methodName)) {
|
|
616 |
Field theValueField = targetClass.fieldByName("estringValue");
|
|
617 |
StringReference theValue = (StringReference)targetClass.getValue(theValueField);
|
|
618 |
tr.forceEarlyReturn(theValue);
|
|
619 |
} else if ("classf".equals(methodName)) {
|
|
620 |
Field theValueField = targetClass.fieldByName("eclassValue");
|
|
621 |
ClassObjectReference theValue = (ClassObjectReference)targetClass.getValue(theValueField);
|
|
622 |
tr.forceEarlyReturn(theValue);
|
|
623 |
} else if ("classLoaderf".equals(methodName)) {
|
|
624 |
Field theValueField = targetClass.fieldByName("eclassLoaderValue");
|
|
625 |
ClassLoaderReference theValue = (ClassLoaderReference)targetClass.getValue(theValueField);
|
|
626 |
tr.forceEarlyReturn(theValue);
|
|
627 |
} else if ("threadf".equals(methodName)) {
|
|
628 |
Field theValueField = targetClass.fieldByName("ethreadValue");
|
|
629 |
ThreadReference theValue = (ThreadReference)targetClass.getValue(theValueField);
|
|
630 |
tr.forceEarlyReturn(theValue);
|
|
631 |
} else if ("threadGroupf".equals(methodName)) {
|
|
632 |
Field theValueField = targetClass.fieldByName("ethreadGroupValue");
|
|
633 |
ThreadGroupReference theValue = (ThreadGroupReference)targetClass.getValue(theValueField);
|
|
634 |
tr.forceEarlyReturn(theValue);
|
|
635 |
} else if ("intArrayf".equals(methodName)) {
|
|
636 |
Field theValueField = targetClass.fieldByName("eintArrayValue");
|
|
637 |
ArrayReference theValue = (ArrayReference)targetClass.getValue(theValueField);
|
|
638 |
tr.forceEarlyReturn(theValue);
|
|
639 |
} else if ("nullObjectf".equals(methodName)) {
|
|
640 |
tr.forceEarlyReturn(null);
|
|
641 |
} else if ("objectf".equals(methodName)) {
|
|
642 |
Field theValueField = targetClass.fieldByName("eobjectValue");
|
|
643 |
ObjectReference theValue = (ObjectReference)targetClass.getValue(theValueField);
|
|
644 |
tr.forceEarlyReturn(theValue);
|
|
645 |
} else if ("voidf".equals(methodName)) {
|
|
646 |
VoidValue theValue = vm().mirrorOfVoid();
|
|
647 |
tr.forceEarlyReturn(theValue);
|
|
648 |
} else {
|
|
649 |
failure("failure: Unknown methodName: " + origMethodName);
|
|
650 |
}
|
|
651 |
|
|
652 |
} catch (Exception ex) {
|
|
653 |
failure("failure: " + ex.toString());
|
|
654 |
ex.printStackTrace();
|
|
655 |
}
|
|
656 |
} else {
|
|
657 |
System.out.println("Cannot force early return for method: " + origMethodName);
|
|
658 |
}
|
|
659 |
}
|
|
660 |
|
|
661 |
// This is the MethodExitEvent handler.
|
|
662 |
public void methodExited(MethodExitEvent event) {
|
|
663 |
String origMethodName = event.method().name();
|
|
664 |
if (vmm.majorInterfaceVersion() >= 1 &&
|
|
665 |
vmm.minorInterfaceVersion() >= 6 &&
|
|
666 |
vm().canGetMethodReturnValues()) {
|
|
667 |
Value retValue = event.returnValue();
|
|
668 |
|
|
669 |
if (!origMethodName.startsWith("s_") &&
|
|
670 |
!origMethodName.startsWith("i_")) {
|
|
671 |
// Skip all uninteresting methods
|
|
672 |
return;
|
|
673 |
}
|
|
674 |
|
|
675 |
String methodName = origMethodName.substring(2);
|
|
676 |
if ("show".equals(methodName)) {
|
|
677 |
System.out.println(retValue);
|
|
678 |
return;
|
|
679 |
}
|
|
680 |
|
|
681 |
if ("bytef".equals(methodName)) ckByteValue(retValue);
|
|
682 |
else if ("charf".equals(methodName)) ckCharValue(retValue);
|
|
683 |
else if ("doublef".equals(methodName)) ckDoubleValue(retValue);
|
|
684 |
else if ("floatf".equals(methodName)) ckFloatValue(retValue);
|
|
685 |
else if ("intf".equals(methodName)) ckIntValue(retValue);
|
|
686 |
else if ("longf".equals(methodName)) ckLongValue(retValue);
|
|
687 |
else if ("shortf".equals(methodName)) ckShortValue(retValue);
|
|
688 |
else if ("booleanf".equals(methodName)) ckBooleanValue(retValue);
|
|
689 |
else if ("stringf".equals(methodName)) ckStringValue(retValue);
|
|
690 |
else if ("classf".equals(methodName)) ckClassValue(retValue);
|
|
691 |
else if ("classLoaderf".equals(methodName)) ckClassLoaderValue(retValue);
|
|
692 |
else if ("threadf".equals(methodName)) ckThreadValue(retValue);
|
|
693 |
else if ("threadGroupf".equals(methodName)) ckThreadGroupValue(retValue);
|
|
694 |
else if ("intArrayf".equals(methodName)) ckArrayValue(retValue);
|
|
695 |
else if ("nullObjectf".equals(methodName)) ckNullObjectValue(retValue);
|
|
696 |
else if ("objectf".equals(methodName)) ckObjectValue(retValue);
|
|
697 |
else if ("voidf".equals(methodName)) ckVoidValue(retValue);
|
|
698 |
else {
|
|
699 |
failure("failure: Unknown methodName: " + origMethodName);
|
|
700 |
}
|
|
701 |
} else {
|
|
702 |
System.out.println("Return Value not available for method: " + origMethodName);
|
|
703 |
}
|
|
704 |
}
|
|
705 |
|
|
706 |
protected void runTests() throws Exception {
|
|
707 |
/*
|
|
708 |
* Get to the top of main()
|
|
709 |
* to determine targetClass and mainThread
|
|
710 |
*/
|
|
711 |
|
|
712 |
BreakpointEvent bpe = startToMain("EarlyReturnTarg");
|
|
713 |
targetClass = (ClassType)bpe.location().declaringType();
|
|
714 |
mainThread = bpe.thread();
|
|
715 |
|
|
716 |
/*
|
|
717 |
* Ask for method exit events
|
|
718 |
*/
|
|
719 |
MethodExitRequest exitRequest =
|
|
720 |
eventRequestManager().createMethodExitRequest();
|
|
721 |
|
|
722 |
for (int i=0; i<excludes.length; ++i) {
|
|
723 |
exitRequest.addClassExclusionFilter(excludes[i]);
|
|
724 |
}
|
|
725 |
int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
|
|
726 |
//sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
|
|
727 |
//sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
|
|
728 |
exitRequest.setSuspendPolicy(sessionSuspendPolicy);
|
|
729 |
exitRequest.enable();
|
|
730 |
|
|
731 |
/*
|
|
732 |
* Turn on the flag so debugee knows to check for early
|
|
733 |
* return values instead of regular return values.
|
|
734 |
*/
|
|
735 |
Field flagField = targetClass.fieldByName("debuggerWatching");
|
|
736 |
targetClass.setValue(flagField, vm().mirrorOf(true));
|
|
737 |
|
|
738 |
|
|
739 |
/*
|
|
740 |
* We set and enable breakpoints on all of the interesting
|
|
741 |
* methods called by doit(). In the breakpointReached()
|
|
742 |
* handler we force an early return with a different return
|
|
743 |
* value.
|
|
744 |
*
|
|
745 |
* The MethodExitEvent handler will keep score.
|
|
746 |
*/
|
|
747 |
|
|
748 |
setBreakpoint("EarlyReturnTarg", "s_bytef", "(I)B");
|
|
749 |
setBreakpoint("EarlyReturnTarg", "s_charf", "()C");
|
|
750 |
setBreakpoint("EarlyReturnTarg", "s_doublef", "()D");
|
|
751 |
setBreakpoint("EarlyReturnTarg", "s_floatf", "()F");
|
|
752 |
setBreakpoint("EarlyReturnTarg", "s_intf", "()I");
|
|
753 |
setBreakpoint("EarlyReturnTarg", "s_longf", "()J");
|
|
754 |
setBreakpoint("EarlyReturnTarg", "s_shortf", "()S");
|
|
755 |
setBreakpoint("EarlyReturnTarg", "s_booleanf", "()Z");
|
|
756 |
|
|
757 |
setBreakpoint("EarlyReturnTarg", "s_stringf", "()Ljava/lang/String;");
|
|
758 |
setBreakpoint("EarlyReturnTarg", "s_classf", "()Ljava/lang/Class;");
|
|
759 |
setBreakpoint("EarlyReturnTarg", "s_classLoaderf", "()Ljava/lang/ClassLoader;");
|
|
760 |
setBreakpoint("EarlyReturnTarg", "s_threadf", "()Ljava/lang/Thread;");
|
|
761 |
setBreakpoint("EarlyReturnTarg", "s_threadGroupf", "()Ljava/lang/ThreadGroup;");
|
|
762 |
setBreakpoint("EarlyReturnTarg", "s_intArrayf", "()[I");
|
|
763 |
setBreakpoint("EarlyReturnTarg", "s_nullObjectf", "()Ljava/lang/Object;");
|
|
764 |
setBreakpoint("EarlyReturnTarg", "s_objectf", "()Ljava/lang/Object;");
|
|
765 |
setBreakpoint("EarlyReturnTarg", "s_voidf", "()V");
|
|
766 |
|
|
767 |
setBreakpoint("EarlyReturnTarg", "i_bytef", "(I)B");
|
|
768 |
setBreakpoint("EarlyReturnTarg", "i_charf", "()C");
|
|
769 |
setBreakpoint("EarlyReturnTarg", "i_doublef", "()D");
|
|
770 |
setBreakpoint("EarlyReturnTarg", "i_floatf", "()F");
|
|
771 |
setBreakpoint("EarlyReturnTarg", "i_intf", "()I");
|
|
772 |
setBreakpoint("EarlyReturnTarg", "i_longf", "()J");
|
|
773 |
setBreakpoint("EarlyReturnTarg", "i_shortf", "()S");
|
|
774 |
setBreakpoint("EarlyReturnTarg", "i_booleanf", "()Z");
|
|
775 |
setBreakpoint("EarlyReturnTarg", "i_stringf", "()Ljava/lang/String;");
|
|
776 |
setBreakpoint("EarlyReturnTarg", "i_intArrayf", "()[I");
|
|
777 |
setBreakpoint("EarlyReturnTarg", "i_classf", "()Ljava/lang/Class;");
|
|
778 |
setBreakpoint("EarlyReturnTarg", "i_classLoaderf", "()Ljava/lang/ClassLoader;");
|
|
779 |
setBreakpoint("EarlyReturnTarg", "i_threadf", "()Ljava/lang/Thread;");
|
|
780 |
setBreakpoint("EarlyReturnTarg", "i_threadGroupf", "()Ljava/lang/ThreadGroup;");
|
|
781 |
setBreakpoint("EarlyReturnTarg", "i_nullObjectf", "()Ljava/lang/Object;");
|
|
782 |
setBreakpoint("EarlyReturnTarg", "i_objectf", "()Ljava/lang/Object;");
|
|
783 |
setBreakpoint("EarlyReturnTarg", "i_voidf", "()V");
|
|
784 |
|
|
785 |
/* Here we go. This adds 'this' as a listener so
|
|
786 |
* that our handlers above will be called.
|
|
787 |
*/
|
|
788 |
listenUntilVMDisconnect();
|
|
789 |
|
|
790 |
if (earlyReturns != expectedEarlyReturns) {
|
|
791 |
failure("failure: Expected " + expectedEarlyReturns +
|
|
792 |
", but got " + earlyReturns);
|
|
793 |
}
|
|
794 |
System.out.println("All done, " + earlyReturns + " passed");
|
|
795 |
|
|
796 |
|
|
797 |
if (!testFailed) {
|
|
798 |
System.out.println();
|
|
799 |
System.out.println("EarlyReturnTest: passed");
|
|
800 |
} else {
|
|
801 |
System.out.println();
|
|
802 |
System.out.println("EarlyReturnTest: failed");
|
|
803 |
throw new Exception("EarlyReturnTest: failed");
|
|
804 |
}
|
|
805 |
}
|
|
806 |
}
|