EarlyReturnTest.java revision 0
0N/A * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * @summary Allow early return from methods 0N/A * @summary Unexpected InvalidTypeException when call ThreadReference.forceEarlyReturn with VoidValue 0N/A * @summary Need a way to create JDI VoidValue for use in ThreadReference.forceEarlyReturn 0N/A * @author Tim Bell (based on MethodExitReturnValuesTest by Jim Holmlund) 0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter 0N/A * @run main EarlyReturnTest 0N/A * This test has a debuggee which calls a static method 0N/A * for each kind of JDI Value, and then an instance method 0N/A * The debugger sets breakpoints in all methods. When a breakpoint 0N/A * is hit the debugger requests an early return and supplies a new 0N/A * return value. It then checks that the correct return values are 0N/A * included in the MethodExitEvents. 0N/A * Each value is stored in a static var in the debuggee. The debugger 0N/A * gets the values from these static vars to check for correct 0N/A * return values in the MethodExitEvents. 0N/A * These are the values that will be used by methods 0N/A * returning normally. 0N/A * These are the values that will be used by methods 0N/A * returning early. These are != the normal values 0N/A // Used to check the return values seen on the debugee side 0N/A public static boolean chk(
byte v) {
0N/A public static boolean chk(
char v) {
0N/A public static boolean chk(
double v) {
0N/A public static boolean chk(
float v) {
0N/A public static boolean chk(
int v) {
0N/A public static boolean chk(
long v) {
0N/A public static boolean chk(
short v) {
0N/A public static boolean chk(
boolean v) {
0N/A // Used to show which set of tests follows 0N/A // These are the static methods 0N/A // These are the instance methods 0N/A s_show(
"========== Testing static methods ================");
0N/A s_show(
"========== Testing instance methods ================");
0N/A /** Hang so that test fails */ 0N/A // The debugger will stop at the start of main, 0N/A // set breakpoints and then do a resume. 0N/A * Class patterns for which we don't want events (copied 0N/A // chkXXX methods lifted directly from MethodExitReturnValuesTest 0N/A // These methods check for correct return values. Thanks, Jim! 0N/A * See what happens if we access the stack after the force 0N/A * and before the resume. Disabling this since spec says 0N/A * the stack is undefined. This type of code can be used to 0N/A * pursue just what that means. 0N/A * StackFrame sf = tr.frame(0); 0N/A * List<Value> ll = sf.getArgumentValues(); 0N/A * for (Value vv: ll) { 0N/A * System.out.println("vv = " + vv); 0N/A // This is the MethodExitEvent handler. 0N/A // Skip all uninteresting methods 0N/A * Get to the top of main() 0N/A * to determine targetClass and mainThread 0N/A * Ask for method exit events 0N/A //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; 0N/A //sessionSuspendPolicy = EventRequest.SUSPEND_NONE; 0N/A * Turn on the flag so debugee knows to check for early 0N/A * return values instead of regular return values. 0N/A * We set and enable breakpoints on all of the interesting 0N/A * methods called by doit(). In the breakpointReached() 0N/A * handler we force an early return with a different return 0N/A * The MethodExitEvent handler will keep score. 0N/A /* Here we go. This adds 'this' as a listener so 0N/A * that our handlers above will be called.