Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/LookupKlassInPoolTest.java
41153 views
/*1* Copyright (c) 2015, 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 813642126* @requires vm.jvmci27* @summary Testing compiler.jvmci.CompilerToVM.lookupKlassInPool method28* @library /test/lib /29* @library ../common/patches30* @modules java.base/jdk.internal.access31* java.base/jdk.internal.reflect32* java.base/jdk.internal.org.objectweb.asm33* java.base/jdk.internal.org.objectweb.asm.tree34* jdk.internal.vm.ci/jdk.vm.ci.hotspot35* jdk.internal.vm.ci/jdk.vm.ci.runtime36* jdk.internal.vm.ci/jdk.vm.ci.meta37*38* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox39* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox40* @run main/othervm -Xbootclasspath/a:.41* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI42* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI43* -XX:-UseJVMCICompiler44* compiler.jvmci.compilerToVM.LookupKlassInPoolTest45*/4647package compiler.jvmci.compilerToVM;4849import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;50import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;51import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;52import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;53import jdk.vm.ci.hotspot.CompilerToVMHelper;54import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;55import jdk.vm.ci.meta.ConstantPool;5657import java.util.HashMap;58import java.util.Map;5960import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_CLASS;6162/**63* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupKlassInPool} method64*/65public class LookupKlassInPoolTest {6667public static void main(String[] args) throws Exception {68Map<ConstantTypes, Validator> typeTests = new HashMap<>();69typeTests.put(CONSTANT_CLASS, LookupKlassInPoolTest::validate);70ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);71testCase.test();72// The next "Class.forName" and repeating "testCase.test()"73// are here for the following reason.74// The first test run is without dummy class initialization,75// which means no constant pool cache exists.76// The second run is with initialized class (with constant pool cache available).77// Some CompilerToVM methods require different input78// depending on whether CP cache exists or not.79for (DummyClasses dummy : DummyClasses.values()) {80Class.forName(dummy.klass.getName());81}82testCase.test();83}8485public static void validate(ConstantPool constantPoolCTVM,86ConstantTypes cpType,87DummyClasses dummyClass,88int i) {89TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, i);90if (entry == null) {91return;92}93Object classToVerify = CompilerToVMHelper.lookupKlassInPool(constantPoolCTVM, i);94if (!(classToVerify instanceof HotSpotResolvedObjectType) && !(classToVerify instanceof String)) {95String msg = String.format("Output of method CTVM.lookupKlassInPool is neither"96+ " a HotSpotResolvedObjectType, nor a String");97throw new AssertionError(msg);98}99String classNameToRefer = entry.klass;100String outputToVerify = classToVerify.toString();101if (!outputToVerify.contains(classNameToRefer)) {102String msg = String.format("Wrong class accessed by constant pool index %d: %s, but should be %s",103i,104outputToVerify,105classNameToRefer);106throw new AssertionError(msg);107}108}109}110111112