langtools/test/tools/javac/meth/InvokeDyn.java
author jjg
Thu, 18 Nov 2010 16:13:11 -0800
changeset 7330 7c670eebe55c
parent 6592 dc56420a69bc
permissions -rw-r--r--
6999438: remove support for exotic identifiers from JDK 7 Reviewed-by: mcimadamore
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
/*
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
     2
 * Copyright (c) 2008, 2010, 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
 *
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    30
 * @library ..
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    31
 * @compile -source 7 -target 7 -XDinvokedynamic -XDallowTransitionalJSR292=no InvokeDyn.java
2723
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
//No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    34
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    35
/*
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    36
 * Standalone testing:
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    37
 * <code>
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    38
 * $ cd $MY_REPO_DIR/langtools
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    39
 * $ (cd make; make)
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    40
 * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeDyn.java
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    41
 * $ javap -c -classpath dist meth.InvokeDyn
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    42
 * </code>
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    43
 */
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    44
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    45
package meth;
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    46
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    47
import java.dyn.*;
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    48
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    49
public class InvokeDyn {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    50
    class CS extends CallSite {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    51
        CS(Object x, Object y, Object z) { throw new RuntimeException(); }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    52
    }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    53
    //@BootstrapMethod(CS.class)  //note: requires 6964498
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2723
diff changeset
    54
    void test() throws Throwable {
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    55
        Object x = "hello";
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    56
        Object ojunk; int ijunk;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    57
        ojunk = InvokeDynamic.greet(x, "world", 123);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    58
        ojunk = InvokeDynamic.greet(x, "mundus", 456);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    59
        ojunk = InvokeDynamic.greet(x, "kosmos", 789);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    60
        ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14);
7330
7c670eebe55c 6999438: remove support for exotic identifiers from JDK 7
jjg
parents: 6592
diff changeset
    61
        //InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 5738
diff changeset
    62
        ijunk = (int) InvokeDynamic.invoke("goodbye");
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    63
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    64
}