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