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