8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 /*
25 * @test
26 * @bug 8132879
27 * @compile CallSites.jasm
28 * @run main/othervm -Xverify:all -Xbatch -XX:CompileCommand=dontinline,Test::test* LinkageErrors
29 */
30
31 import java.lang.invoke.*;
32
33 interface I {
34 void m1(int i);
35 static void s1() {}
36 }
37
38 class A implements I {
39 public void m1(int i) {}
40 }
41
42 class X {
43 public void m1(int i) {}
44 public final void f1(int i) {}
45 public static void s1(int i) {}
46 }
47
48 public class LinkageErrors {
49 final static MethodHandles.Lookup L = MethodHandles.lookup();
50
51 static void test(MethodHandle mh) {
52 try {
53 mh.invokeExact();
54 throw new AssertionError("No exception thrown");
55 } catch (LinkageError e) {
56 return; // expected
57 } catch (AssertionError e) {
58 throw e; // rethrow
59 } catch (Throwable e) {
60 throw new AssertionError("Unexpected exception", e);
61 }
62 }
63
64 public static void main(String args[]) throws Throwable {
65 Class<?> test = Class.forName("CallSites");
66
67 // Non-existent method lookups.
68 MethodHandle testI1 = L.findStatic(test, "testI1", MethodType.methodType(void.class, I.class));
69 MethodHandle testX1 = L.findStatic(test, "testX1", MethodType.methodType(void.class, X.class));
70
71 MethodHandle testI1_A = testI1.bindTo(new A());
72 MethodHandle testI1_null = testI1.bindTo(null);
73 MethodHandle testX1_X = testX1.bindTo(new X());
74 MethodHandle testX1_null = testX1.bindTo(null);
75
76 // invokestatic of instance methods.
77 MethodHandle testI2 = L.findStatic(test, "testI2", MethodType.methodType(void.class));
78 MethodHandle testX2 = L.findStatic(test, "testX2", MethodType.methodType(void.class));
79
80 MethodHandle testI3 = L.findStatic(test, "testI3", MethodType.methodType(void.class, I.class));
81 MethodHandle testX3 = L.findStatic(test, "testX3", MethodType.methodType(void.class, X.class));
82
83 // Virtual invocation of static methods.
84 MethodHandle testI3_A = testI3.bindTo(new A());
85 MethodHandle testI3_null = testI3.bindTo(null);
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 /*
25 * @test
26 * @bug 8132879
27 * @compile CallSites.jasm
28 * @run main/othervm -Xverify:all -Xbatch
29 * -XX:CompileCommand=dontinline,compiler.linkage.LinkageErrors::test*
30 * compiler.linkage.LinkageErrors
31 */
32
33 package compiler.linkage;
34
35 import java.lang.invoke.MethodHandle;
36 import java.lang.invoke.MethodHandles;
37 import java.lang.invoke.MethodType;
38
39 interface I {
40 void m1(int i);
41 static void s1() {}
42 }
43
44 class A implements I {
45 public void m1(int i) {}
46 }
47
48 class X {
49 public void m1(int i) {}
50 public final void f1(int i) {}
51 public static void s1(int i) {}
52 }
53
54 public class LinkageErrors {
55 final static MethodHandles.Lookup L = MethodHandles.lookup();
56
57 static void test(MethodHandle mh) {
58 try {
59 mh.invokeExact();
60 throw new AssertionError("No exception thrown");
61 } catch (LinkageError e) {
62 return; // expected
63 } catch (AssertionError e) {
64 throw e; // rethrow
65 } catch (Throwable e) {
66 throw new AssertionError("Unexpected exception", e);
67 }
68 }
69
70 public static void main(String args[]) throws Throwable {
71 Class<?> test = Class.forName("compiler.linkage.CallSites");
72
73 // Non-existent method lookups.
74 MethodHandle testI1 = L.findStatic(test, "testI1", MethodType.methodType(void.class, I.class));
75 MethodHandle testX1 = L.findStatic(test, "testX1", MethodType.methodType(void.class, X.class));
76
77 MethodHandle testI1_A = testI1.bindTo(new A());
78 MethodHandle testI1_null = testI1.bindTo(null);
79 MethodHandle testX1_X = testX1.bindTo(new X());
80 MethodHandle testX1_null = testX1.bindTo(null);
81
82 // invokestatic of instance methods.
83 MethodHandle testI2 = L.findStatic(test, "testI2", MethodType.methodType(void.class));
84 MethodHandle testX2 = L.findStatic(test, "testX2", MethodType.methodType(void.class));
85
86 MethodHandle testI3 = L.findStatic(test, "testI3", MethodType.methodType(void.class, I.class));
87 MethodHandle testX3 = L.findStatic(test, "testX3", MethodType.methodType(void.class, X.class));
88
89 // Virtual invocation of static methods.
90 MethodHandle testI3_A = testI3.bindTo(new A());
91 MethodHandle testI3_null = testI3.bindTo(null);
|