Path: blob/master/test/hotspot/jtreg/compiler/c1/TestStaticInterfaceMethodCall.java
41152 views
/*1* Copyright (c) 2020, 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 823908326* @summary Test invocation of static interface method with and without method handle with C1.27*28* @run main/othervm -Xbatch -XX:TieredStopAtLevel=3 compiler.c1.TestStaticInterfaceMethodCall29*/3031package compiler.c1;3233import java.lang.invoke.MethodHandle;34import java.lang.invoke.MethodHandles;35import java.lang.invoke.MethodType;3637public class TestStaticInterfaceMethodCall {3839static final MethodHandle MH_m;4041static {42try {43MH_m = MethodHandles.lookup().findStatic(MyInterface.class, "m", MethodType.methodType(void.class));44} catch (ReflectiveOperationException e) {45throw new BootstrapMethodError(e);46}47}4849public static void main(String[] args) throws Throwable {50for (int i = 0; i < 20_000; i++) {51test_call_by_method_handle();52test_direct_call();53}54}5556static void test_call_by_method_handle() throws Throwable {57MH_m.invokeExact();58}5960static void test_direct_call() {61MyInterface.m();62}6364}6566interface MyInterface {67static void m() {}68}697071