jdk/test/com/sun/jdi/EarlyReturnNegativeTest.java
author jjg
Thu, 22 May 2008 15:51:41 -0700
changeset 655 1ebc7ce89018
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6705945: com.sun.tools.javac.zip files do not have valid copyright Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 6431735
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Unexpected ClassCastException in ThreadReference.forceEarlyReturn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Jim Holmlund
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g EarlyReturnNegativeTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main EarlyReturnNegativeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This test has a debuggee which calls an instance method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for each kind of JDI value return type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The debugger sets breakpoints in all methods.  When a breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * is hit the debugger requests an early return and supplies a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * return value. The new value is not compatible with the method's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * return type so an InvalidTypeException should be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Each value is stored in a static var in the debuggee.  The debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * gets the values from these static vars to pass back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * debuggee in forceEarlyReturn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * This test was created out of EarlyReturnTest.java.  Not all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * debuggee methods are actually used, just the ones needed to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * for correct operation.  I left the others in just in case they come
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * in handy in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
class EarlyReturnNegativeTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * These are the values that will be used by methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * returning normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static URL[] urls = new URL[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static byte      byteValue = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static char      charValue = 'x';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static double    doubleValue = 2.2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static float     floatValue = 3.3f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static int       intValue = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static long      longValue = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static short     shortValue = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static boolean   booleanValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static Class       classValue = Object.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static ClassLoader classLoaderValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            urls[0] = new URL("hi there");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        } catch (java.net.MalformedURLException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        classLoaderValue = new URLClassLoader(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static Thread      threadValue = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static ThreadGroup threadGroupValue = threadValue.getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static String      stringValue = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static int[]       intArrayValue = new int[] {1, 2, 3};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static Object[]    objectArrayValue = new Object[] {"a", "b", "c"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static EarlyReturnNegativeTarg  objectValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        new EarlyReturnNegativeTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public String ivar = stringValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // Used to show which set of tests follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static String s_show(String p1) { return p1;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // These are the instance methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public byte i_bytef()            { return byteValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public char i_charf()            { return charValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public double i_doublef()        { return doubleValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public float i_floatf()          { return floatValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public int i_intf()              { return intValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public long i_longf()            { return longValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public short i_shortf()          { return shortValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public boolean i_booleanf()      { return booleanValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public String i_stringf()        { return stringValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public Class i_classf()          { return classValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public ClassLoader i_classLoaderf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                     { return classLoaderValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public Thread i_threadf()        { return threadValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public ThreadGroup i_threadGroupf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                     { return threadGroupValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public int[] i_intArrayf()       { return intArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public Object[] i_objectArrayf() { return objectArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public Object i_nullObjectf()    { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public Object i_objectf()        { return objectValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void i_voidf()            {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    static void doit(EarlyReturnNegativeTarg xx) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        System.err.print("debugee in doit ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        s_show("==========  Testing instance methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        xx.i_bytef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        xx.i_charf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        xx.i_doublef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        xx.i_floatf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        xx.i_intf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        xx.i_longf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        xx.i_shortf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        xx.i_booleanf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        xx.i_stringf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        xx.i_intArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        xx.i_objectArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        xx.i_classf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        xx.i_classLoaderf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        xx.i_threadf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        xx.i_threadGroupf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        xx.i_nullObjectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        xx.i_objectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        xx.i_voidf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * The debugger will stop at the start of main,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * set breakpoints and then do a resume.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        System.err.println("debugee in main");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        EarlyReturnNegativeTarg xx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            new EarlyReturnNegativeTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        doit(xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
public class EarlyReturnNegativeTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    static VirtualMachineManager vmm ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    ClassType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    Field theValueField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    ByteValue byteVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    CharValue charVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    DoubleValue doubleVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    FloatValue floatVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    IntegerValue integerVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    LongValue longVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    ShortValue shortVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    BooleanValue booleanVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    ObjectReference objectVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    ArrayReference intArrayVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    ArrayReference objectArrayVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    VoidValue voidVV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    EarlyReturnNegativeTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        EarlyReturnNegativeTest meee = new EarlyReturnNegativeTest(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        vmm = Bootstrap.virtualMachineManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public BreakpointRequest setBreakpoint(String clsName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                           String methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                           String methodSignature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        ReferenceType rt = findReferenceType(clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            rt = resumeToPrepareOf(clsName).referenceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        Method method = findMethod(rt, methodName, methodSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new IllegalArgumentException("Bad method name/signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        BreakpointRequest bpr = eventRequestManager().createBreakpointRequest(method.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        bpr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        bpr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return bpr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    void doEarly(ThreadReference tr, String methodName, Value val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            tr.forceEarlyReturn(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } catch (InvalidTypeException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.out.println("Ok: " + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            failure("failure: " + ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        failure("Expected InvalidTypeException for " + methodName + ", " + val + " but didn't get it.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void breakpointReached(BreakpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        String origMethodName = event.location().method().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        String methodName = origMethodName.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        ThreadReference tr = event.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (vmm.majorInterfaceVersion() >= 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            vmm.minorInterfaceVersion() >= 6 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            vm().canForceEarlyReturn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            /* There are some incompatible classes of values.  In the following,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
             * we test each combination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if ("shortf".equals(methodName)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                doEarly(tr, origMethodName, booleanVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                doEarly(tr, origMethodName, objectVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                doEarly(tr, origMethodName, voidVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                doEarly(tr, origMethodName, intArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                doEarly(tr, origMethodName, objectArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            } else if ("booleanf".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                doEarly(tr, origMethodName, shortVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                doEarly(tr, origMethodName, objectVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                doEarly(tr, origMethodName, voidVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                doEarly(tr, origMethodName, intArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                doEarly(tr, origMethodName, objectArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            } else if ("intArrayf".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                doEarly(tr, origMethodName, booleanVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                doEarly(tr, origMethodName, shortVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                doEarly(tr, origMethodName, voidVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                doEarly(tr, origMethodName, objectVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                doEarly(tr, origMethodName, objectArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            } else if ("objectArrayf".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                doEarly(tr, origMethodName, booleanVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                doEarly(tr, origMethodName, shortVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                doEarly(tr, origMethodName, voidVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                doEarly(tr, origMethodName, objectVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                doEarly(tr, origMethodName, intArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            } else if ("objectf".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                doEarly(tr, origMethodName, booleanVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                doEarly(tr, origMethodName, shortVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                doEarly(tr, origMethodName, voidVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
             } else if ("voidf".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                doEarly(tr, origMethodName, booleanVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                doEarly(tr, origMethodName, shortVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                doEarly(tr, origMethodName, objectVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                doEarly(tr, origMethodName, intArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                doEarly(tr, origMethodName, objectArrayVV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                // just ignore others
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                System.out.println("Ignoring: " + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            System.out.println("Cannot force early return for method: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        BreakpointEvent bpe = startToMain("EarlyReturnNegativeTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        targetClass = (ClassType)bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * We set and enable breakpoints on all of the interesting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * methods called by doit().  In the breakpointReached()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * handler we force an early return with a different return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        setBreakpoint("EarlyReturnNegativeTarg", "i_bytef", "()B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        setBreakpoint("EarlyReturnNegativeTarg", "i_charf", "()C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        setBreakpoint("EarlyReturnNegativeTarg", "i_doublef", "()D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        setBreakpoint("EarlyReturnNegativeTarg", "i_floatf", "()F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        setBreakpoint("EarlyReturnNegativeTarg", "i_intf", "()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        setBreakpoint("EarlyReturnNegativeTarg", "i_longf", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        setBreakpoint("EarlyReturnNegativeTarg", "i_shortf", "()S");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        setBreakpoint("EarlyReturnNegativeTarg", "i_booleanf", "()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        setBreakpoint("EarlyReturnNegativeTarg", "i_stringf", "()Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        setBreakpoint("EarlyReturnNegativeTarg", "i_intArrayf", "()[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        setBreakpoint("EarlyReturnNegativeTarg", "i_objectArrayf", "()[Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        setBreakpoint("EarlyReturnNegativeTarg", "i_classf", "()Ljava/lang/Class;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        setBreakpoint("EarlyReturnNegativeTarg", "i_classLoaderf", "()Ljava/lang/ClassLoader;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        setBreakpoint("EarlyReturnNegativeTarg", "i_threadf", "()Ljava/lang/Thread;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        setBreakpoint("EarlyReturnNegativeTarg", "i_threadGroupf", "()Ljava/lang/ThreadGroup;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        setBreakpoint("EarlyReturnNegativeTarg", "i_nullObjectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        setBreakpoint("EarlyReturnNegativeTarg", "i_objectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        setBreakpoint("EarlyReturnNegativeTarg", "i_voidf", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        /* Create Value objects to be passed in forceEarlyReturn calls */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        Field theValueField = targetClass.fieldByName("byteValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        byteVV = (ByteValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        theValueField = targetClass.fieldByName("charValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        charVV = (CharValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        theValueField = targetClass.fieldByName("doubleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        doubleVV = (DoubleValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        theValueField = targetClass.fieldByName("floatValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        floatVV = (FloatValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        theValueField = targetClass.fieldByName("intValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        integerVV = (IntegerValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        theValueField = targetClass.fieldByName("longValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        longVV = (LongValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        theValueField = targetClass.fieldByName("shortValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        shortVV = (ShortValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        theValueField = targetClass.fieldByName("booleanValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        booleanVV = (BooleanValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        theValueField = targetClass.fieldByName("objectValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        objectVV = (ObjectReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        theValueField = targetClass.fieldByName("intArrayValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        intArrayVV = (ArrayReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        theValueField = targetClass.fieldByName("objectArrayValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        objectArrayVV = (ArrayReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        voidVV = vm().mirrorOfVoid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        /* Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            System.out.println("EarlyReturnNegativeTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            System.out.println("EarlyReturnNegativeTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw new Exception("EarlyReturnNegativeTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}