Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/LookupMethodInPoolTest.java
41153 views
/*1* Copyright (c) 2016, 2021, 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 813870826* @requires vm.jvmci27* @library /test/lib /28* @library ../common/patches29* @modules java.base/jdk.internal.access30* java.base/jdk.internal.reflect31* java.base/jdk.internal.org.objectweb.asm32* java.base/jdk.internal.org.objectweb.asm.tree33* jdk.internal.vm.ci/jdk.vm.ci.hotspot34* jdk.internal.vm.ci/jdk.vm.ci.meta35* jdk.internal.vm.ci/jdk.vm.ci.runtime36*37* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox38* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox39* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions40* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI41* -XX:-UseJVMCICompiler42* compiler.jvmci.compilerToVM.LookupMethodInPoolTest43*/4445package compiler.jvmci.compilerToVM;4647import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;48import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;49import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;50import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;51import jdk.test.lib.Asserts;52import jdk.vm.ci.hotspot.CompilerToVMHelper;53import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;54import jdk.vm.ci.meta.ConstantPool;5556import java.util.HashMap;57import java.util.Map;5859import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_INTERFACEMETHODREF;60import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_METHODREF;6162/**63* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupMethodInPool} method64*/65public class LookupMethodInPoolTest {6667public static void main(String[] args) throws Exception {68Map<ConstantTypes, Validator> typeTests = new HashMap<>();69typeTests.put(CONSTANT_METHODREF, LookupMethodInPoolTest::validate);70typeTests.put(CONSTANT_INTERFACEMETHODREF, LookupMethodInPoolTest::validate);71ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);72testCase.test();73// The next "Class.forName" and repeating "testCase.test()"74// are here for the following reason.75// The first test run is without dummy class initialization,76// which means no constant pool cache exists.77// The second run is with initialized class (with constant pool cache available).78// Some CompilerToVM methods require different input79// depending on whether CP cache exists or not.80for (DummyClasses dummy : DummyClasses.values()) {81Class.forName(dummy.klass.getName());82}83testCase.test();84}8586private static void validate(ConstantPool constantPoolCTVM,87ConstantTypes cpType,88DummyClasses dummyClass,89int cpi) {90TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);91if (entry == null) {92return;93}94int index = cpi;95String cached = "";96int cpci = dummyClass.getCPCacheIndex(cpi);97if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {98index = cpci;99cached = "cached ";100}101for (int j = 0; j < entry.opcodes.length; j++) {102HotSpotResolvedJavaMethod methodToVerify = CompilerToVMHelper103.lookupMethodInPool(constantPoolCTVM, index, entry.opcodes[j]);104String msg = String.format("Object returned by lookupMethodInPool method"105+ " for %sindex %d should not be null",106cached,107index);108Asserts.assertNotNull(methodToVerify, msg);109String[] classNameSplit = entry.klass.split("/");110String classNameToRefer = classNameSplit[classNameSplit.length - 1];111String methodNameToRefer = entry.name;112String methodToVerifyToString = methodToVerify.toString();113if (!methodToVerifyToString.contains(classNameToRefer)114|| !methodToVerifyToString.contains(methodNameToRefer)) {115msg = String.format("String representation \"%s\" of the object"116+ " returned by lookupMethodInPool method"117+ " for index %d does not contain a method's class name"118+ " or method's name, should contain %s.%s",119methodToVerifyToString,120index,121classNameToRefer,122methodNameToRefer);123throw new AssertionError(msg);124}125}126}127}128129130