langtools/test/tools/javac/meth/InvokeDyn.java
author jjg
Fri, 09 Apr 2010 15:39:39 -0700
changeset 5319 63dc7f367a37
parent 2723 b659ca23d5f5
child 5736 ee0850472ca1
child 5520 86e4b9a9da40
permissions -rw-r--r--
6942649: add hidden option to identify location and version of javac classes Reviewed-by: darcy
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
/*
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    21
 * have any questions.
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
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    26
 * @bug 6754038
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 ..
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    31
 * @compile -source 7 -target 7 InvokeDyn.java
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
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    47
import java.dyn.InvokeDynamic;
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 {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    50
    void test() {
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    51
        Object x = "hello";
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    52
        InvokeDynamic.greet(x, "world", 123);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    53
        InvokeDynamic.greet(x, "mundus", 456);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    54
        InvokeDynamic.greet(x, "kosmos", 789);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    55
        InvokeDynamic.<String>cogitate(10.11121, 3.14);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    56
        InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    57
        InvokeDynamic.<int>invoke("goodbye");
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    58
    }
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents:
diff changeset
    59
}