jdk/test/com/sun/jdi/MethodExitReturnValuesTest.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 12196 78184ec38cbe
child 21355 c53a16ac1969
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12196
diff changeset
     2
 * Copyright (c) 2004, 2012, 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 4195445 6204179
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary JDWP, JDI: Add return value to Method Exit Event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Jim Holmlund
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g MethodExitReturnValuesTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main MethodExitReturnValuesTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This test has a debuggee which calls a static method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for each kind of JDI Value, and then an instance method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The debugger turns on MethodExitEvents and checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * that the right return values are included in the MethodExitEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Each value is stored in a static var in the debuggee.  The debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * gets the values from these static vars to check for correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * return values in the MethodExitEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
class MethodExitReturnValuesTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // These are the values that will be returned by the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static URL[] urls = new URL[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static byte      byteValue = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static char      charValue = 'x';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static double    doubleValue = 2.2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static float     floatValue = 3.3f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static int       intValue = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static long      longValue = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static short     shortValue = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static boolean   booleanValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static Class       classValue = Object.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static ClassLoader classLoaderValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            urls[0] = new URL("hi there");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } catch (java.net.MalformedURLException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        classLoaderValue = new URLClassLoader(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static Thread      threadValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static ThreadGroup threadGroupValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static String      stringValue = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static int[]       intArrayValue = new int[] {1, 2, 3};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static MethodExitReturnValuesTarg  objectValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        new MethodExitReturnValuesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String ivar = stringValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // arrays to be used in calls to native methods Array.get...(....)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static byte[]    arrByte      = new byte[]    {byteValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static char[]    arrChar      = new char[]    {charValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static double[]  arrDouble    = new double[]  {doubleValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static float[]   arrFloat     = new float[]   {floatValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static int[]     arrInt       = new int[]     {intValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static long[]    arrLong      = new long[]    {longValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static short[]   arrShort     = new short[]   {shortValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static boolean[] arrBoolean   = new boolean[] {booleanValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static Object[]  arrObject    = new Object[]  {objectValue};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Used to show which set of tests follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static String s_show(String p1) { return p1;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // These are the static methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static byte s_bytef()      { return byteValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static char s_charf()      { return charValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static double s_doublef()  { return doubleValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static float s_floatf()    { return floatValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static int s_intf()        { return intValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static long s_longf()      { return longValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static short s_shortf()    { return shortValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static boolean s_booleanf(){ return booleanValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static String s_stringf()  { return stringValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static Class s_classf()    { return classValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static ClassLoader s_classLoaderf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                      { return classLoaderValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static Thread s_threadf()  { threadValue = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        return threadValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static ThreadGroup s_threadGroupf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                      { threadGroupValue = threadValue.getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                        return threadGroupValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static int[] s_intArrayf() { return intArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static Object s_nullObjectf() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static Object s_objectf()  { return objectValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static void s_voidf()      {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // These are the instance methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public byte i_bytef()            { return byteValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public char i_charf()            { return charValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public double i_doublef()        { return doubleValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public float i_floatf()          { return floatValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int i_intf()              { return intValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public long i_longf()            { return longValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public short i_shortf()          { return shortValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public boolean i_booleanf()      { return booleanValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public String i_stringf()        { return stringValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public Class i_classf()          { return classValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public ClassLoader i_classLoaderf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                     { return classLoaderValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Thread i_threadf()        { return threadValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public ThreadGroup i_threadGroupf()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                     { return threadGroupValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public int[] i_intArrayf()       { return intArrayValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Object i_nullObjectf()    { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public Object i_objectf()        { return objectValue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void i_voidf()            {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    static void doit(MethodExitReturnValuesTarg xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        s_show("==========  Testing static methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        s_bytef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        s_charf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        s_doublef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        s_floatf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        s_intf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        s_longf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        s_shortf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        s_booleanf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        s_stringf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        s_classf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        s_classLoaderf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        s_threadf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        s_threadGroupf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        s_intArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        s_nullObjectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        s_objectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        s_voidf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        s_show("==========  Testing instance methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        xx.i_bytef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        xx.i_charf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        xx.i_doublef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        xx.i_floatf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        xx.i_intf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        xx.i_longf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        xx.i_shortf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        xx.i_booleanf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        xx.i_stringf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        xx.i_intArrayf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        xx.i_classf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        xx.i_classLoaderf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        xx.i_threadf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        xx.i_threadGroupf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        xx.i_nullObjectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        xx.i_objectf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        xx.i_voidf();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Prove it works for native methods too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        s_show("==========  Testing native methods ================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        StrictMath.sin(doubleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Array.getByte(arrByte, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Array.getChar(arrChar, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Array.getDouble(arrDouble, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Array.getFloat(arrFloat, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Array.getInt(arrInt, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        Array.getLong(arrLong, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Array.getShort(arrShort, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Array.getBoolean(arrBoolean, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Array.get(arrObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        stringValue.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // The debugger will stop at the start of main,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // enable method exit events, and then do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // a resume.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        MethodExitReturnValuesTarg xx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            new MethodExitReturnValuesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        doit(xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
public class MethodExitReturnValuesTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Class patterns for which we don't want events (copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * from the "Trace.java" example):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private String[] excludes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        "javax.*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        "sun.*",
12196
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   221
        "com.sun.*",
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   222
        "com.oracle.*",
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   223
        "oracle.*"};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static VirtualMachineManager vmm ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    ClassType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    Field theValueField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    static int successes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    static final int expectedSuccesses = 44;  // determined by inspection :-)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    MethodExitReturnValuesTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        MethodExitReturnValuesTest meee = new MethodExitReturnValuesTest(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        vmm = Bootstrap.virtualMachineManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    // These are the methods that check for correct return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    void ckByteValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Field theValueField = targetClass.fieldByName("byteValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        ByteValue theValue = (ByteValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        byte vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        byte rv = ((ByteValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            failure("failure: byte: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            System.out.println("Passed: byte " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            successes++;
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
    void ckCharValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        Field theValueField = targetClass.fieldByName("charValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        CharValue theValue = (CharValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        char vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        char rv = ((CharValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            failure("failure: char: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            System.out.println("Passed: char " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    void ckDoubleValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        Field theValueField = targetClass.fieldByName("doubleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        DoubleValue theValue = (DoubleValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        double vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        double rv = ((DoubleValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            failure("failure: double: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            System.out.println("Passed: double " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    void ckFloatValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        Field theValueField = targetClass.fieldByName("floatValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        FloatValue theValue = (FloatValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        float vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        float rv = ((FloatValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            failure("failure: float: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            System.out.println("Passed: float " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    void ckIntValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        Field theValueField = targetClass.fieldByName("intValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        IntegerValue theValue = (IntegerValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        int vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        int rv = ((IntegerValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            failure("failure: int: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            System.out.println("Passed: int " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    void ckLongValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Field theValueField = targetClass.fieldByName("longValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        LongValue theValue = (LongValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        long vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        long rv = ((LongValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            failure("failure: long: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            System.out.println("Passed: long " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    void ckShortValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        Field theValueField = targetClass.fieldByName("shortValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        ShortValue theValue = (ShortValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        short vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        short rv = ((ShortValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            failure("failure: short: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            System.out.println("Passed: short " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    void ckBooleanValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        Field theValueField = targetClass.fieldByName("booleanValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        BooleanValue theValue = (BooleanValue)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        boolean vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        boolean rv = ((BooleanValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            failure("failure: boolean: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            System.out.println("Passed: boolean " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    void ckStringValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Field theValueField = targetClass.fieldByName("stringValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        StringReference theValue = (StringReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        String vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        String rv = ((StringReference)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            failure("failure: String: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            System.out.println("Passed: String: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    void ckClassValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        Field theValueField = targetClass.fieldByName("classValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        ClassObjectReference vv = (ClassObjectReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        ClassObjectReference rv = (ClassObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            failure("failure: Class: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            System.out.println("Passed: Class: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    void ckClassLoaderValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Field theValueField = targetClass.fieldByName("classLoaderValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        ClassLoaderReference vv = (ClassLoaderReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        ClassLoaderReference rv = (ClassLoaderReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            failure("failure: ClassLoader: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            System.out.println("Passed: ClassLoader: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    void ckThreadValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        Field theValueField = targetClass.fieldByName("threadValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        ThreadReference vv = (ThreadReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        ThreadReference rv = (ThreadReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            failure("failure: Thread: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            System.out.println("Passed: Thread: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    void ckThreadGroupValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Field theValueField = targetClass.fieldByName("threadGroupValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        ThreadGroupReference vv = (ThreadGroupReference)targetClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        ThreadGroupReference rv = (ThreadGroupReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            failure("failure: ThreadgGroup: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            System.out.println("Passed: ThreadGroup: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    void ckArrayValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Field theValueField = targetClass.fieldByName("intArrayValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        ArrayReference theValue = (ArrayReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        IntegerValue theElem2 = (IntegerValue)theValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        ArrayReference theRetValue = (ArrayReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        IntegerValue retElem2 = (IntegerValue)theRetValue.getValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int vv = theElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int rv = retElem2.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            failure("failure: in[2]: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            System.out.println("Passed: int[2]: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    void ckNullObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (retValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            failure("failure: NullObject: expected " + null + ", got " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            System.out.println("Passed: NullObject: " + retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    void ckObjectValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // We will check the ivar field which we know contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // the value of 'stringValue'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        Field theValueField = targetClass.fieldByName("stringValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        StringReference theValue = (StringReference)targetClass.getValue(theValueField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        Field theIVarField = targetClass.fieldByName("ivar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        ObjectReference theRetValue = (ObjectReference)retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        StringReference theRetValField = (StringReference)theRetValue.getValue(theIVarField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        String vv = theValue.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        String rv = theRetValField.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (vv != rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            failure("failure: Object: 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: Object: " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            successes++;
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 ckVoidValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        System.out.println("Passed: Void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    void ckSinValue(Value retValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        double rv = ((DoubleValue)retValue).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        double vv = StrictMath.sin(MethodExitReturnValuesTarg.doubleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (rv != vv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            failure("failure: sin: expected " + vv + ", got " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            System.out.println("Passed: sin " + rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            successes++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // This is the MethodExitEvent handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public void methodExited(MethodExitEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        String origMethodName = event.method().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (vmm.majorInterfaceVersion() >= 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            vmm.minorInterfaceVersion() >= 6 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            vm().canGetMethodReturnValues()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            Value retValue = event.returnValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if ("sin".equals(origMethodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                ckSinValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (!origMethodName.startsWith("s_") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                !origMethodName.startsWith("i_")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                // Check native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                if ("getByte".equals(origMethodName))         ckByteValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                else if ("getChar".equals(origMethodName))    ckCharValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                else if ("getDouble".equals(origMethodName))  ckDoubleValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                else if ("getFloat".equals(origMethodName))   ckFloatValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                else if ("getInt".equals(origMethodName))     ckIntValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                else if ("getLong".equals(origMethodName))    ckLongValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                else if ("getShort".equals(origMethodName))   ckShortValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                else if ("getBoolean".equals(origMethodName)) ckBooleanValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                else if ("getObject".equals(origMethodName))  ckObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                else if ("intern".equals(origMethodName))     ckStringValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            String methodName = origMethodName.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if ("show".equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                System.out.println(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if ("bytef".equals(methodName))             ckByteValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            else if ("charf".equals(methodName))        ckCharValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            else if ("doublef".equals(methodName))      ckDoubleValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            else if ("floatf".equals(methodName))       ckFloatValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            else if ("intf".equals(methodName))         ckIntValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            else if ("longf".equals(methodName))        ckLongValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            else if ("shortf".equals(methodName))       ckShortValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            else if ("booleanf".equals(methodName))     ckBooleanValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            else if ("stringf".equals(methodName))      ckStringValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            else if ("classf".equals(methodName))       ckClassValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            else if ("classLoaderf".equals(methodName)) ckClassLoaderValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            else if ("threadf".equals(methodName))      ckThreadValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            else if ("threadGroupf".equals(methodName)) ckThreadGroupValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            else if ("intArrayf".equals(methodName))    ckArrayValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            else if ("nullObjectf".equals(methodName))  ckNullObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            else if ("objectf".equals(methodName))      ckObjectValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            else if ("voidf".equals(methodName))        ckVoidValue(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                failure("failure: Unknown methodName: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            System.out.println("Return Value not available for method: " + origMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        BreakpointEvent bpe = startToMain("MethodExitReturnValuesTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        targetClass = (ClassType)bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        theValueField = targetClass.fieldByName("theValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            eventRequestManager().createMethodExitRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            exitRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         * We are now set up to receive the notifications we want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         * Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (successes != expectedSuccesses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            failure("failure: Expected " + expectedSuccesses + ", but got " + successes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        System.out.println("All done, " + successes + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            System.out.println("MethodExitReturnValuesTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            System.out.println("MethodExitReturnValuesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            throw new Exception("MethodExitReturnValuesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
}