test/jdk/com/sun/jdi/EarlyReturnTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 44423 jdk/test/com/sun/jdi/EarlyReturnTest.java@306c020eb154
child 49118 dbbbf6d7cf6e
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
     2
 * Copyright (c) 2005, 2016, 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
/*
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    26
 * @bug 6175634
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    27
 * @summary Allow early return from methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    29
 * @bug 6431720
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    30
 * @summary Unexpected InvalidTypeException when call ThreadReference.forceEarlyReturn with VoidValue
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    32
 * @bug 6432855
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    33
 * @summary Need a way to create JDI VoidValue for use in ThreadReference.forceEarlyReturn
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    35
 * @author Tim Bell (based on MethodExitReturnValuesTest by Jim Holmlund)
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    36
 *
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    37
 * @run build TestScaffold VMConnection TargetListener TargetAdapter
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    38
 * @run compile -g EarlyReturnTest.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 36511
diff changeset
    39
 * @run driver EarlyReturnTest
2
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.*",
12196
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   295
        "com.sun.*",
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   296
        "com.oracle.*",
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   297
        "oracle.*"};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    static VirtualMachineManager vmm ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    ClassType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    Field theValueField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    static int earlyReturns = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    static final int expectedEarlyReturns = 34; // determined by inspection :-)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    EarlyReturnTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        EarlyReturnTest meee = new EarlyReturnTest(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        vmm = Bootstrap.virtualMachineManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    // chkXXX methods lifted directly from MethodExitReturnValuesTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    // These methods check for correct return values.  Thanks, Jim!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    void ckByteValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        Field theValueField = targetClass.fieldByName("ebyteValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        ByteValue theValue = (ByteValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        byte vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        byte rv = ((ByteValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            failure("failure: byte: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            System.out.println("Passed: byte " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    void ckCharValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        Field theValueField = targetClass.fieldByName("echarValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        CharValue theValue = (CharValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        char vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        char rv = ((CharValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            failure("failure: char: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            System.out.println("Passed: char " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    void ckDoubleValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        Field theValueField = targetClass.fieldByName("edoubleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        DoubleValue theValue = (DoubleValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        double vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        double rv = ((DoubleValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            failure("failure: double: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            System.out.println("Passed: double " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    void ckFloatValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Field theValueField = targetClass.fieldByName("efloatValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        FloatValue theValue = (FloatValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        float vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        float rv = ((FloatValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            failure("failure: float: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            System.out.println("Passed: float " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    void ckIntValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Field theValueField = targetClass.fieldByName("eintValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        IntegerValue theValue = (IntegerValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        int vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int rv = ((IntegerValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            failure("failure: int: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            System.out.println("Passed: int " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    void ckLongValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        Field theValueField = targetClass.fieldByName("elongValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        LongValue theValue = (LongValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        long vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        long rv = ((LongValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            failure("failure: long: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            System.out.println("Passed: long " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    void ckShortValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        Field theValueField = targetClass.fieldByName("eshortValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        ShortValue theValue = (ShortValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        short vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        short rv = ((ShortValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            failure("failure: short: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            System.out.println("Passed: short " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    void ckBooleanValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        Field theValueField = targetClass.fieldByName("ebooleanValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        BooleanValue theValue = (BooleanValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        boolean vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        boolean rv = ((BooleanValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            failure("failure: boolean: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            System.out.println("Passed: boolean " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    void ckStringValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        Field theValueField = targetClass.fieldByName("estringValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        StringReference theValue = (StringReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        String vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        String rv = ((StringReference)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            failure("failure: String: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            System.out.println("Passed: String: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    void ckClassValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        Field theValueField = targetClass.fieldByName("eclassValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        ClassObjectReference vv = (ClassObjectReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        ClassObjectReference rv = (ClassObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            failure("failure: Class: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            System.out.println("Passed: Class: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    void ckClassLoaderValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        Field theValueField = targetClass.fieldByName("eclassLoaderValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        ClassLoaderReference vv = (ClassLoaderReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        ClassLoaderReference rv = (ClassLoaderReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            failure("failure: ClassLoader: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            System.out.println("Passed: ClassLoader: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    void ckThreadValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        Field theValueField = targetClass.fieldByName("ethreadValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        ThreadReference vv = (ThreadReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        ThreadReference rv = (ThreadReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            failure("failure: Thread: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            System.out.println("Passed: Thread: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    void ckThreadGroupValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        Field theValueField = targetClass.fieldByName("ethreadGroupValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        ThreadGroupReference vv = (ThreadGroupReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        ThreadGroupReference rv = (ThreadGroupReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            failure("failure: ThreadgGroup: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            System.out.println("Passed: ThreadGroup: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    void ckArrayValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Field theValueField = targetClass.fieldByName("eintArrayValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        ArrayReference theValue = (ArrayReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        IntegerValue theElem2 = (IntegerValue)theValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        ArrayReference theRetValue = (ArrayReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        IntegerValue retElem2 = (IntegerValue)theRetValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        int vv = theElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        int rv = retElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            failure("failure: in[2]: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            System.out.println("Passed: int[2]: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    void ckNullObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (retValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            failure("failure: NullObject: expected " + null + ", got " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            System.out.println("Passed: NullObject: " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    void ckObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        ObjectReference theRetValue = (ObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        Field theIVarField = targetClass.fieldByName("eobjectValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        ObjectReference theRetValField = (ObjectReference)targetClass.getValue(theIVarField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (! theRetValue.equals(theRetValField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            failure("failure: Object: expected " + theIVarField + ", got " + theRetValField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            System.out.println("Passed: Object: " + theRetValField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    void ckVoidValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        System.out.println("Passed: Void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        earlyReturns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public BreakpointRequest setBreakpoint(String clsName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                           String methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                           String methodSignature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        ReferenceType rt = findReferenceType(clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            rt = resumeToPrepareOf(clsName).referenceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        Method method = findMethod(rt, methodName, methodSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            throw new IllegalArgumentException("Bad method name/signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        BreakpointRequest bpr = eventRequestManager().createBreakpointRequest(method.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        bpr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        bpr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return bpr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public void breakpointReached(BreakpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        String origMethodName = event.location().method().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        String methodName = origMethodName.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        ThreadReference tr = event.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   567
        if (vm().canForceEarlyReturn()) {
2
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();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30376
diff changeset
   664
        if (vm().canGetMethodReturnValues()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            Value retValue = event.returnValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if (!origMethodName.startsWith("s_") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                !origMethodName.startsWith("i_")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                // Skip all uninteresting methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            String methodName = origMethodName.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if ("show".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                System.out.println(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if ("bytef".equals(methodName))             ckByteValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            else if ("charf".equals(methodName))        ckCharValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            else if ("doublef".equals(methodName))      ckDoubleValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            else if ("floatf".equals(methodName))       ckFloatValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            else if ("intf".equals(methodName))         ckIntValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            else if ("longf".equals(methodName))        ckLongValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            else if ("shortf".equals(methodName))       ckShortValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            else if ("booleanf".equals(methodName))     ckBooleanValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            else if ("stringf".equals(methodName))      ckStringValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            else if ("classf".equals(methodName))       ckClassValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            else if ("classLoaderf".equals(methodName)) ckClassLoaderValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            else if ("threadf".equals(methodName))      ckThreadValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            else if ("threadGroupf".equals(methodName)) ckThreadGroupValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            else if ("intArrayf".equals(methodName))    ckArrayValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            else if ("nullObjectf".equals(methodName))  ckNullObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            else if ("objectf".equals(methodName))      ckObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            else if ("voidf".equals(methodName))        ckVoidValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                failure("failure: Unknown methodName: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            System.out.println("Return Value not available for method: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        BreakpointEvent bpe = startToMain("EarlyReturnTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        targetClass = (ClassType)bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            eventRequestManager().createMethodExitRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            exitRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
         * Turn on the flag so debugee knows to check for early
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
         * return values instead of regular return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        Field flagField = targetClass.fieldByName("debuggerWatching");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        targetClass.setValue(flagField, vm().mirrorOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         * We set and enable breakpoints on all of the interesting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         * methods called by doit().  In the breakpointReached()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
         * handler we force an early return with a different return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * The MethodExitEvent handler will keep score.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        setBreakpoint("EarlyReturnTarg", "s_bytef", "(I)B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        setBreakpoint("EarlyReturnTarg", "s_charf", "()C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        setBreakpoint("EarlyReturnTarg", "s_doublef", "()D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        setBreakpoint("EarlyReturnTarg", "s_floatf", "()F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        setBreakpoint("EarlyReturnTarg", "s_intf", "()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        setBreakpoint("EarlyReturnTarg", "s_longf", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        setBreakpoint("EarlyReturnTarg", "s_shortf", "()S");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        setBreakpoint("EarlyReturnTarg", "s_booleanf", "()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        setBreakpoint("EarlyReturnTarg", "s_stringf", "()Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        setBreakpoint("EarlyReturnTarg", "s_classf", "()Ljava/lang/Class;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        setBreakpoint("EarlyReturnTarg", "s_classLoaderf", "()Ljava/lang/ClassLoader;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        setBreakpoint("EarlyReturnTarg", "s_threadf", "()Ljava/lang/Thread;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        setBreakpoint("EarlyReturnTarg", "s_threadGroupf", "()Ljava/lang/ThreadGroup;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        setBreakpoint("EarlyReturnTarg", "s_intArrayf", "()[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        setBreakpoint("EarlyReturnTarg", "s_nullObjectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        setBreakpoint("EarlyReturnTarg", "s_objectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        setBreakpoint("EarlyReturnTarg", "s_voidf", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        setBreakpoint("EarlyReturnTarg", "i_bytef", "(I)B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        setBreakpoint("EarlyReturnTarg", "i_charf", "()C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        setBreakpoint("EarlyReturnTarg", "i_doublef", "()D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        setBreakpoint("EarlyReturnTarg", "i_floatf", "()F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        setBreakpoint("EarlyReturnTarg", "i_intf", "()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        setBreakpoint("EarlyReturnTarg", "i_longf", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        setBreakpoint("EarlyReturnTarg", "i_shortf", "()S");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        setBreakpoint("EarlyReturnTarg", "i_booleanf", "()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        setBreakpoint("EarlyReturnTarg", "i_stringf", "()Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        setBreakpoint("EarlyReturnTarg", "i_intArrayf", "()[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        setBreakpoint("EarlyReturnTarg", "i_classf", "()Ljava/lang/Class;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        setBreakpoint("EarlyReturnTarg", "i_classLoaderf", "()Ljava/lang/ClassLoader;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        setBreakpoint("EarlyReturnTarg", "i_threadf", "()Ljava/lang/Thread;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        setBreakpoint("EarlyReturnTarg", "i_threadGroupf", "()Ljava/lang/ThreadGroup;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        setBreakpoint("EarlyReturnTarg", "i_nullObjectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        setBreakpoint("EarlyReturnTarg", "i_objectf", "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        setBreakpoint("EarlyReturnTarg", "i_voidf", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        /* Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (earlyReturns != expectedEarlyReturns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            failure("failure: Expected " + expectedEarlyReturns +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    ", but got " + earlyReturns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        System.out.println("All done, " + earlyReturns + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            System.out.println("EarlyReturnTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            System.out.println("EarlyReturnTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            throw new Exception("EarlyReturnTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
}