Path: blob/master/test/hotspot/jtreg/compiler/linkage/LinkageErrors.java
41152 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813287926* @compile CallSites.jasm27* @run main/othervm -Xverify:all -Xbatch28* -XX:CompileCommand=dontinline,compiler.linkage.LinkageErrors::test*29* compiler.linkage.LinkageErrors30*/3132package compiler.linkage;3334import java.lang.invoke.MethodHandle;35import java.lang.invoke.MethodHandles;36import java.lang.invoke.MethodType;3738interface I {39void m1(int i);40static void s1() {}41}4243class A implements I {44public void m1(int i) {}45}4647class X {48public void m1(int i) {}49public final void f1(int i) {}50public static void s1(int i) {}51}5253public class LinkageErrors {54final static MethodHandles.Lookup L = MethodHandles.lookup();5556static void testICCE(MethodHandle mh) {57try {58mh.invokeExact();59throw new AssertionError("No exception thrown");60} catch (IncompatibleClassChangeError e) {61return; // expected62} catch (AssertionError e) {63throw e; // rethrow64} catch (Throwable e) {65throw new AssertionError("Unexpected exception", e);66}67}6869static void testNSME(MethodHandle mh) {70try {71mh.invokeExact();72throw new AssertionError("No exception thrown");73} catch (NoSuchMethodError e) {74return; // expected75} catch (AssertionError e) {76throw e; // rethrow77} catch (Throwable e) {78throw new AssertionError("Unexpected exception", e);79}80}8182public static void main(String args[]) throws Throwable {83Class<?> test = Class.forName("compiler.linkage.CallSites");8485// Non-existent method lookups.86MethodHandle testI1 = L.findStatic(test, "testI1", MethodType.methodType(void.class, I.class));87MethodHandle testX1 = L.findStatic(test, "testX1", MethodType.methodType(void.class, X.class));8889MethodHandle testI1_A = testI1.bindTo(new A());90MethodHandle testI1_null = testI1.bindTo(null);91MethodHandle testX1_X = testX1.bindTo(new X());92MethodHandle testX1_null = testX1.bindTo(null);9394// invokestatic of instance methods.95MethodHandle testI2 = L.findStatic(test, "testI2", MethodType.methodType(void.class));96MethodHandle testX2 = L.findStatic(test, "testX2", MethodType.methodType(void.class));9798MethodHandle testI3 = L.findStatic(test, "testI3", MethodType.methodType(void.class, I.class));99MethodHandle testX3 = L.findStatic(test, "testX3", MethodType.methodType(void.class, X.class));100101// Virtual invocation of static methods.102MethodHandle testI3_A = testI3.bindTo(new A());103MethodHandle testI3_null = testI3.bindTo(null);104MethodHandle testX3_X = testX3.bindTo(new X());105MethodHandle testX3_null = testX3.bindTo(null);106107for (int i = 0; i < 20_000; i++) {108testNSME(testI1_A);109testNSME(testI1_null);110testNSME(testX1_X);111testNSME(testX1_null);112113testICCE(testI2);114testICCE(testX2);115116testICCE(testI3_A);117testICCE(testI3_null);118testICCE(testX3_X);119testICCE(testX3_null);120}121122System.out.println("TEST PASSED");123}124}125126127