Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/FindUniqueConcreteMethodTest.java
41153 views
/*1* Copyright (c) 2015, 2019, 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 813642126* @requires vm.jvmci27* @library / /test/lib28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules java.base/jdk.internal.org.objectweb.asm31* java.base/jdk.internal.org.objectweb.asm.tree32* jdk.internal.vm.ci/jdk.vm.ci.hotspot33* jdk.internal.vm.ci/jdk.vm.ci.code34* jdk.internal.vm.ci/jdk.vm.ci.meta35* jdk.internal.vm.ci/jdk.vm.ci.runtime36* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper37* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI38* -XX:-UseJVMCICompiler39* compiler.jvmci.compilerToVM.FindUniqueConcreteMethodTest40*/4142package compiler.jvmci.compilerToVM;4344import compiler.jvmci.common.CTVMUtilities;45import compiler.jvmci.common.testcases.DuplicateSimpleSingleImplementerInterface;46import compiler.jvmci.common.testcases.SimpleSingleImplementerInterface;47import compiler.jvmci.common.testcases.MultipleImplementer1;48import compiler.jvmci.common.testcases.MultipleSuperImplementers;49import compiler.jvmci.common.testcases.SingleImplementer;50import compiler.jvmci.common.testcases.SingleImplementerInterface;51import compiler.jvmci.common.testcases.SingleSubclass;52import jdk.test.lib.Asserts;53import jdk.test.lib.Utils;54import jdk.vm.ci.hotspot.CompilerToVMHelper;55import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;56import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;5758import java.lang.reflect.Method;59import java.util.HashSet;60import java.util.Set;6162public class FindUniqueConcreteMethodTest {63public static void main(String args[]) {64FindUniqueConcreteMethodTest test = new FindUniqueConcreteMethodTest();65try {66for (TestCase tcase : createTestCases()) {67test.runTest(tcase);68}69} catch (NoSuchMethodException e) {70throw new Error("TEST BUG: can't find method", e);71}72}7374private static Set<TestCase> createTestCases() {75Set<TestCase> result = new HashSet<>();76// a public method77result.add(new TestCase(true, SingleSubclass.class, "usualMethod"));78// overriden method79result.add(new TestCase(true, SingleSubclass.class, "overridenMethod"));80// private method81result.add(new TestCase(InternalError.class, SingleSubclass.class, "privateMethod"));82// protected method83result.add(new TestCase(true, SingleSubclass.class, "protectedMethod"));84// default(package-private) method85result.add(new TestCase(true, SingleSubclass.class, "defaultAccessMethod"));86// default interface method redefined in implementer87result.add(new TestCase(true, MultipleImplementer1.class, "defaultMethod"));88// interface method89result.add(new TestCase(true, MultipleImplementer1.class, "testMethod"));90// default interface method not redefined in implementer91// result.add(new TestCase(true, SingleImplementer.class,92// SingleImplementerInterface.class, "defaultMethod"));93// static method94result.add(new TestCase(InternalError.class, SingleSubclass.class, "staticMethod"));95// interface method96result.add(new TestCase(false, MultipleSuperImplementers.class,97DuplicateSimpleSingleImplementerInterface.class, "interfaceMethod"));98result.add(new TestCase(false, MultipleSuperImplementers.class,99SimpleSingleImplementerInterface.class, "interfaceMethod"));100return result;101}102103private void runTest(TestCase tcase) throws NoSuchMethodException {104System.out.println(tcase);105Method method = tcase.holder.getDeclaredMethod(tcase.methodName);106HotSpotResolvedJavaMethod testMethod = CTVMUtilities.getResolvedMethod(method);107108HotSpotResolvedObjectType resolvedType = CompilerToVMHelper109.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver), getClass(),110/* resolve = */ true);111if (tcase.exception != null) {112try {113HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper114.findUniqueConcreteMethod(resolvedType, testMethod);115116Asserts.fail("Exception " + tcase.exception.getName() + " not thrown for " + tcase.methodName);117} catch (Throwable t) {118Asserts.assertEQ(t.getClass(), tcase.exception, "Wrong exception thrown for " + tcase.methodName);119}120} else {121HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper122.findUniqueConcreteMethod(resolvedType, testMethod);123Asserts.assertEQ(concreteMethod, tcase.isPositive ? testMethod : null,124"Unexpected concrete method for " + tcase.methodName);125}126}127128private static class TestCase {129public final Class<?> receiver;130public final Class<?> holder;131public final String methodName;132public final boolean isPositive;133public final Class<?> exception;134135public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder,136String methodName, Class<?> exception) {137this.receiver = clazz;138this.methodName = methodName;139this.isPositive = isPositive;140this.holder = holder;141this.exception = exception;142}143144public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder,145String methodName) {146this(isPositive, clazz, holder, methodName, null);147}148149public TestCase(boolean isPositive, Class<?> clazz, String methodName) {150this(isPositive, clazz, clazz, methodName, null);151}152153public TestCase(Class<?> exception, Class<?> clazz, String methodName) {154this(false, clazz, clazz, methodName, exception);155}156157@Override158public String toString() {159return String.format("CASE: receiver=%s, holder=%s, method=%s, isPositive=%s, exception=%s",160receiver.getName(), holder.getName(), methodName, isPositive,161exception == null ? "<none>" : exception.getName());162}163}164}165166167