langtools/test/tools/javac/meth/InvokeMH.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 23393 1698e8b53501
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     1
/*
23393
1698e8b53501 8036842: Remove unneeded/obsolete -source/-target options in javac tests, part 2
darcy
parents: 9882
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     4
 *
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     8
 *
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    13
 * accompanied this code).
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    14
 *
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2723
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2723
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2723
diff changeset
    21
 * questions.
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    22
 */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    23
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    24
/*
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    25
 * @test
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    26
 * @bug 6754038 6979327
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    27
 * @summary Generate call sites for method handle
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    28
 * @author jrose
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    29
 *
23393
1698e8b53501 8036842: Remove unneeded/obsolete -source/-target options in javac tests, part 2
darcy
parents: 9882
diff changeset
    30
 * @compile InvokeMH.java
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    31
 */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    32
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    33
/*
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    34
 * Standalone testing:
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    35
 * <code>
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    36
 * $ cd $MY_REPO_DIR/langtools
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    37
 * $ (cd make; make)
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    38
 * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    39
 * $ javap -c -classpath dist meth.InvokeMH
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    40
 * </code>
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    41
 */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    42
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    43
package meth;
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    44
9082
53409a3a93f8 7028405: (javac) remove unused JSR-292 code
ksrini
parents: 6592
diff changeset
    45
import java.lang.invoke.MethodHandle;
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    46
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    47
public class InvokeMH {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    48
    void test(MethodHandle mh_SiO,
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    49
              MethodHandle mh_vS,
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    50
              MethodHandle mh_vi,
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    51
              MethodHandle mh_vv) throws Throwable {
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    52
        Object o; String s; int i;  // for return type testing
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    53
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    54
        // next five must have sig = (String,int)Object
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    55
        mh_SiO.invokeExact("world", 123);
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    56
        mh_SiO.invokeExact("mundus", 456);
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    57
        Object k = "kosmos";
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    58
        mh_SiO.invokeExact((String)k, 789);
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    59
        o = mh_SiO.invokeExact((String)null, 000);
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    60
        o = (Object) mh_SiO.invokeExact("arda", -123);
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    61
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    62
        // sig = ()String
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    63
        s = (String) mh_vS.invokeExact();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    64
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    65
        // sig = ()int
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    66
        i = (int) mh_vi.invokeExact();
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    67
        o = (int) mh_vi.invokeExact();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    68
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    69
        // sig = ()void
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    70
        mh_vv.invokeExact();
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    71
    }
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    72
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    73
    void testGen(MethodHandle mh_SiO,
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    74
                 MethodHandle mh_vS,
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    75
                 MethodHandle mh_vi,
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    76
                 MethodHandle mh_vv) throws Throwable {
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    77
        Object o; String s; int i;  // for return type testing
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    78
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    79
        // next five must have sig = (*,*)*
9882
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    80
        o = mh_SiO.invoke((Object)"world", (Object)123);
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    81
        mh_SiO.invoke((Object)"mundus", (Object)456);
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    82
        Object k = "kosmos";
9882
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    83
        o = mh_SiO.invoke(k, 789);
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    84
        o = mh_SiO.invoke(null, 000);
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    85
        o = mh_SiO.invoke("arda", -123);
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    86
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    87
        // sig = ()String
9882
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    88
        o = mh_vS.invoke();
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    89
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    90
        // sig = ()int
9882
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    91
        i = (int) mh_vi.invoke();
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    92
        o = (int) mh_vi.invoke();
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    93
        mh_vi.invoke();
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    94
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    95
        // sig = ()void
9882
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    96
        mh_vv.invoke();
a89465baa9fd 7052782: Two langtools regression tests fail due to fix for 7034977 which removed the invokeGeneric method
jjh
parents: 9082
diff changeset
    97
        o = mh_vv.invoke();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    98
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    99
}