Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/LookupKlassRefIndexInPoolTest.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.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.LookupKlassRefIndexInPoolTest43*/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.meta.ConstantPool;5455import java.util.HashMap;56import java.util.Map;5758import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_FIELDREF;59import 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.lookupKlassRefIndexInPool} method64*/65public class LookupKlassRefIndexInPoolTest {6667public static void main(String[] args) throws Exception {68Map<ConstantTypes, Validator> typeTests = new HashMap<>();69typeTests.put(CONSTANT_METHODREF, LookupKlassRefIndexInPoolTest::validate);70typeTests.put(CONSTANT_INTERFACEMETHODREF, LookupKlassRefIndexInPoolTest::validate);71typeTests.put(CONSTANT_FIELDREF, LookupKlassRefIndexInPoolTest::validate);72ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);73testCase.test();74// The next "Class.forName" and repeating "testCase.test()"75// are here for the following reason.76// The first test run is without dummy class initialization,77// which means no constant pool cache exists.78// The second run is with initialized class (with constant pool cache available).79// Some CompilerToVM methods require different input80// depending on whether CP cache exists or not.81for (DummyClasses dummy : DummyClasses.values()) {82Class.forName(dummy.klass.getName());83}84testCase.test();85}8687private static void validate(ConstantPool constantPoolCTVM,88ConstantTypes cpType,89DummyClasses dummyClass,90int cpi) {91TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);92if (entry == null) {93return;94}95int index = cpi;96String cached = "";97int cpci = dummyClass.getCPCacheIndex(cpi);98if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {99index = cpci;100cached = "cached ";101}102int indexToVerify = CompilerToVMHelper.lookupKlassRefIndexInPool(constantPoolCTVM, index);103int indexToRefer = dummyClass.constantPoolSS.getClassRefIndexAt(cpi);104String msg = String.format("Wrong class index returned by lookupKlassRefIndexInPool method "105+ "applied to %sconstant pool index %d",106cached,107index);108Asserts.assertEQ(indexToRefer, indexToVerify, msg);109}110}111112113