InvokeMH.java revision 956
6116N/A/*
6116N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
6116N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6116N/A *
6116N/A * This code is free software; you can redistribute it and/or modify it
6116N/A * under the terms of the GNU General Public License version 2 only, as
6116N/A * published by the Free Software Foundation.
6116N/A *
6116N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6116N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6116N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6116N/A * version 2 for more details (a copy is included in the LICENSE file that
6116N/A * accompanied this code).
6116N/A *
6116N/A * You should have received a copy of the GNU General Public License version
6116N/A * 2 along with this work; if not, write to the Free Software Foundation,
6116N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6116N/A *
6116N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6116N/A * or visit www.oracle.com if you need additional information or have any
6116N/A * questions.
6116N/A */
6116N/A
6116N/A/*
6116N/A * @test
6116N/A * @bug 6754038 6979327
6116N/A * @summary Generate call sites for method handle
6116N/A * @author jrose
6116N/A *
6116N/A * @compile -source 7 -target 7 -XDallowTransitionalJSR292=no InvokeMH.java
6116N/A */
6116N/A
6116N/A/*
6116N/A * Standalone testing:
6116N/A * <code>
6116N/A * $ cd $MY_REPO_DIR/langtools
6116N/A * $ (cd make; make)
6116N/A * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java
6116N/A * $ javap -c -classpath dist meth.InvokeMH
6116N/A * </code>
6116N/A */
6116N/A
6116N/Apackage meth;
6116N/A
6116N/Aimport java.lang.invoke.MethodHandle;
6116N/A
6116N/Apublic class InvokeMH {
6116N/A void test(MethodHandle mh_SiO,
6116N/A MethodHandle mh_vS,
6116N/A MethodHandle mh_vi,
6116N/A MethodHandle mh_vv) throws Throwable {
6116N/A Object o; String s; int i; // for return type testing
6116N/A
6116N/A // next five must have sig = (String,int)Object
6116N/A mh_SiO.invokeExact("world", 123);
6116N/A mh_SiO.invokeExact("mundus", 456);
6116N/A Object k = "kosmos";
6116N/A mh_SiO.invokeExact((String)k, 789);
6116N/A o = mh_SiO.invokeExact((String)null, 000);
6116N/A o = (Object) mh_SiO.invokeExact("arda", -123);
6116N/A
6116N/A // sig = ()String
6116N/A s = (String) mh_vS.invokeExact();
6116N/A
6116N/A // sig = ()int
6116N/A i = (int) mh_vi.invokeExact();
6116N/A o = (int) mh_vi.invokeExact();
6116N/A
6116N/A // sig = ()void
6116N/A mh_vv.invokeExact();
6116N/A }
6116N/A
6116N/A void testGen(MethodHandle mh_SiO,
6116N/A MethodHandle mh_vS,
6116N/A MethodHandle mh_vi,
6116N/A MethodHandle mh_vv) throws Throwable {
6116N/A Object o; String s; int i; // for return type testing
6116N/A
6116N/A // next five must have sig = (*,*)*
6116N/A o = mh_SiO.invokeGeneric((Object)"world", (Object)123);
6116N/A mh_SiO.invokeGeneric((Object)"mundus", (Object)456);
6116N/A Object k = "kosmos";
6116N/A o = mh_SiO.invokeGeneric(k, 789);
6116N/A o = mh_SiO.invokeGeneric(null, 000);
6116N/A o = mh_SiO.invokeGeneric("arda", -123);
6116N/A
6116N/A // sig = ()String
6116N/A o = mh_vS.invokeGeneric();
6116N/A
6116N/A // sig = ()int
i = (int) mh_vi.invokeGeneric();
o = (int) mh_vi.invokeGeneric();
mh_vi.invokeGeneric();
// sig = ()void
mh_vv.invokeGeneric();
o = mh_vv.invokeGeneric();
}
}