jdk/test/java/dyn/InvokeDynamicPrintArgs.java
author jrose
Thu, 16 Dec 2010 15:59:27 -0800
changeset 7562 a0ad195efe2c
parent 7558 e7a391a3bcfe
child 8345 9e2483e6cfab
permissions -rw-r--r--
7001424: implement JSR 292 EG adjustments, November 2010 Reviewed-by: twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7558
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     1
/*
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     4
 *
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     8
 *
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    13
 * accompanied this code).
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    14
 *
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    18
 *
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    21
 * questions.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    22
 */
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    23
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    24
/* @test
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    25
 * @summary smoke test for invokedynamic instructions
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    26
 * @library indify
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    27
 * @compile InvokeDynamicPrintArgs.java
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    28
 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    29
 *      indify.Indify
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    30
 *      --verify-specifier-count=3 --transitionalJSR292=false
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    31
 *      --expand-properties --classpath ${test.classes}
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    32
 *      --java InvokeDynamicPrintArgs --check-output
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    33
 */
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    34
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    35
import java.util.*;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    36
import java.io.*;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    37
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    38
import java.dyn.*;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    39
import static java.dyn.MethodHandles.*;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    40
import static java.dyn.MethodType.*;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    41
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    42
public class InvokeDynamicPrintArgs {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    43
    public static void main(String... av) throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    44
        if (av.length > 0)  openBuf();  // --check-output mode
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    45
        System.out.println("Printing some argument lists, starting with a empty one:");
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    46
        INDY_nothing().invokeExact();                 // BSM specifier #0 = {bsm}
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    47
        INDY_bar().invokeExact("bar arg", 1);         // BSM specifier #1 = {bsm2, Void.class, "void type"}
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    48
        INDY_bar2().invokeExact("bar2 arg", 222);     // BSM specifier #1 = (same)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    49
        INDY_baz().invokeExact("baz arg", 2, 3.14);   // BSM specifier #2 = {bsm2, 1234.5}
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    50
        INDY_foo().invokeExact("foo arg");            // BSM specifier #0 = (same)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    51
        // Hence, BSM specifier count should be 3.  See "--verify-specifier-count=3" above.
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    52
        System.out.println("Done printing argument lists.");
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    53
        closeBuf();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    54
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    55
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    56
    private static PrintStream oldOut;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    57
    private static ByteArrayOutputStream buf;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    58
    private static void openBuf() {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    59
        oldOut = System.out;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    60
        buf = new ByteArrayOutputStream();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    61
        System.setOut(new PrintStream(buf));
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    62
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    63
    private static void closeBuf() {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    64
        if (buf == null)  return;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    65
        System.out.flush();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    66
        System.setOut(oldOut);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    67
        String[] haveLines = new String(buf.toByteArray()).split("[\n\r]+");
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    68
        for (String line : haveLines)  System.out.println(line);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    69
        Iterator<String> iter = Arrays.asList(haveLines).iterator();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    70
        for (String want : EXPECT_OUTPUT) {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    71
            String have = iter.hasNext() ? iter.next() : "[EOF]";
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    72
            if (want.equals(have))  continue;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    73
            System.err.println("want line: "+want);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    74
            System.err.println("have line: "+have);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    75
            throw new AssertionError("unexpected output: "+have);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    76
        }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    77
        if (iter.hasNext())
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    78
            throw new AssertionError("unexpected output: "+iter.next());
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    79
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    80
    private static final String[] EXPECT_OUTPUT = {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    81
        "Printing some argument lists, starting with a empty one:",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    82
        "[InvokeDynamicPrintArgs, nothing, ()void][]",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    83
        "[InvokeDynamicPrintArgs, bar, (java.lang.String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar arg, 1]",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    84
        "[InvokeDynamicPrintArgs, bar2, (java.lang.String,int)void, class java.lang.Void, void type!, 1, 234.5, 67.5, 89][bar2 arg, 222]",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    85
        "[InvokeDynamicPrintArgs, baz, (java.lang.String,int,double)void, 1234.5][baz arg, 2, 3.14]",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    86
        "[InvokeDynamicPrintArgs, foo, (java.lang.String)void][foo arg]",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    87
        "Done printing argument lists."
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    88
    };
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    89
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    90
    private static void printArgs(Object bsmInfo, Object... args) {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    91
        System.out.println(bsmInfo+Arrays.deepToString(args));
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    92
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    93
    private static MethodHandle MH_printArgs() throws ReflectiveOperationException {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    94
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    95
        return lookup().findStatic(lookup().lookupClass(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    96
                                   "printArgs", methodType(void.class, Object.class, Object[].class));
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    97
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    98
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
    99
    private static CallSite bsm(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   100
        // ignore caller and name, but match the type:
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   101
        Object bsmInfo = Arrays.asList(caller, name, type);
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7558
diff changeset
   102
        return new ConstantCallSite(MH_printArgs().bindTo(bsmInfo).asCollector(Object[].class, type.parameterCount()).asType(type));
7558
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   103
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   104
    private static MethodType MT_bsm() {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   105
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   106
        return methodType(CallSite.class, Lookup.class, String.class, MethodType.class);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   107
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   108
    private static MethodHandle MH_bsm() throws ReflectiveOperationException {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   109
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   110
        return lookup().findStatic(lookup().lookupClass(), "bsm", MT_bsm());
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   111
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   112
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   113
    private static CallSite bsm2(Lookup caller, String name, MethodType type, Object arg) throws ReflectiveOperationException {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   114
        // ignore caller and name, but match the type:
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   115
        List<Object> bsmInfo = new ArrayList<>(Arrays.asList(caller, name, type));
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   116
        if (arg instanceof Object[])
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   117
            bsmInfo.addAll(Arrays.asList((Object[])arg));
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   118
        else
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   119
            bsmInfo.add(arg);
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7558
diff changeset
   120
        return new ConstantCallSite(MH_printArgs().bindTo(bsmInfo).asCollector(Object[].class, type.parameterCount()).asType(type));
7558
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   121
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   122
    private static MethodType MT_bsm2() {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   123
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   124
        return methodType(CallSite.class, Lookup.class, String.class, MethodType.class, Object.class);
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   125
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   126
    private static MethodHandle MH_bsm2() throws ReflectiveOperationException {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   127
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   128
        return lookup().findStatic(lookup().lookupClass(), "bsm2", MT_bsm2());
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   129
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   130
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   131
    private static MethodHandle INDY_nothing() throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   132
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   133
        return ((CallSite) MH_bsm().invokeGeneric(lookup(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   134
                                                  "nothing", methodType(void.class)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   135
                                                  )).dynamicInvoker();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   136
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   137
    private static MethodHandle INDY_foo() throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   138
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   139
        return ((CallSite) MH_bsm().invokeGeneric(lookup(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   140
                                                  "foo", methodType(void.class, String.class)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   141
                                                  )).dynamicInvoker();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   142
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   143
    private static MethodHandle INDY_bar() throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   144
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   145
        return ((CallSite) MH_bsm2().invokeGeneric(lookup(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   146
                                                  "bar", methodType(void.class, String.class, int.class)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   147
                                                  , new Object[] { Void.class, "void type!",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   148
                                                                   1, 234.5F, 67.5, (long)89 }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   149
                                                  )).dynamicInvoker();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   150
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   151
    private static MethodHandle INDY_bar2() throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   152
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   153
        return ((CallSite) MH_bsm2().invokeGeneric(lookup(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   154
                                                  "bar2", methodType(void.class, String.class, int.class)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   155
                                                  , new Object[] { Void.class, "void type!",
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   156
                                                                   1, 234.5F, 67.5, (long)89 }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   157
                                                  )).dynamicInvoker();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   158
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   159
    private static MethodHandle INDY_baz() throws Throwable {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   160
        shouldNotCallThis();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   161
        return ((CallSite) MH_bsm2().invokeGeneric(lookup(),
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   162
                                                  "baz", methodType(void.class, String.class, int.class, double.class)
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   163
                                                  , 1234.5
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   164
                                                  )).dynamicInvoker();
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   165
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   166
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   167
    private static void shouldNotCallThis() {
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   168
        // if this gets called, the transformation has not taken place
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   169
        if (System.getProperty("InvokeDynamicPrintArgs.allow-untransformed") != null)  return;
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   170
        throw new AssertionError("this code should be statically transformed away by Indify");
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   171
    }
e7a391a3bcfe 7001423: JSR 292 bytecode enhancements need unit tests
jrose
parents:
diff changeset
   172
}