Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/LookupNameInPoolTest.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.runtime35* jdk.internal.vm.ci/jdk.vm.ci.meta36*37* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper38* @build sun.hotspot.WhiteBox39* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox40* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions41* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI42* -XX:-UseJVMCICompiler43* compiler.jvmci.compilerToVM.LookupNameInPoolTest44*/4546package compiler.jvmci.compilerToVM;4748import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;49import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;50import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;51import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;52import jdk.test.lib.Asserts;53import jdk.vm.ci.hotspot.CompilerToVMHelper;54import jdk.vm.ci.meta.ConstantPool;5556import java.util.HashMap;57import java.util.Map;5859import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_FIELDREF;60import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_INTERFACEMETHODREF;61import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_INVOKEDYNAMIC;62import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_METHODREF;6364/**65* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupNameInPool} method66*/67public class LookupNameInPoolTest {6869public static void main(String[] args) throws Exception {70Map<ConstantTypes, Validator> typeTests = new HashMap<>();71typeTests.put(CONSTANT_METHODREF, LookupNameInPoolTest::validate);72typeTests.put(CONSTANT_INTERFACEMETHODREF, LookupNameInPoolTest::validate);73typeTests.put(CONSTANT_FIELDREF, LookupNameInPoolTest::validate);74typeTests.put(CONSTANT_INVOKEDYNAMIC, LookupNameInPoolTest::validate);75ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);76testCase.test();77// The next "Class.forName" and repeating "testCase.test()"78// are here for the following reason.79// The first test run is without dummy class initialization,80// which means no constant pool cache exists.81// The second run is with initialized class (with constant pool cache available).82// Some CompilerToVM methods require different input83// depending on whether CP cache exists or not.84for (DummyClasses dummy : DummyClasses.values()) {85Class.forName(dummy.klass.getName());86}87testCase.test();88}8990private static void validate(ConstantPool constantPoolCTVM,91ConstantTypes cpType,92DummyClasses dummyClass,93int cpi) {94TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);95if (entry == null) {96return;97}98int index = cpi;99String cached = "";100int cpci = dummyClass.getCPCacheIndex(cpi);101if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {102index = cpci;103cached = "cached ";104}105String nameToVerify = CompilerToVMHelper.lookupNameInPool(constantPoolCTVM, index);106String nameToRefer = entry.name;107String msg = String.format("Wrong name accessed by %sconstant pool index %d", cached, index);108Asserts.assertEQ(nameToVerify, nameToRefer, msg);109}110}111112113