Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetLocalVariableTableTest.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/lib /28* @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*37* @clean compiler.jvmci.compilerToVM.*38* @compile -g DummyInterface.java39* @compile -g DummyAbstractClass.java40* @compile -g DummyClass.java41* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper42* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI43* -XX:-UseJVMCICompiler44* compiler.jvmci.compilerToVM.GetLocalVariableTableTest45* @clean compiler.jvmci.compilerToVM.*46*/4748package compiler.jvmci.compilerToVM;4950import compiler.jvmci.common.CTVMUtilities;51import jdk.test.lib.Asserts;52import jdk.vm.ci.hotspot.CompilerToVMHelper;53import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;5455import java.lang.reflect.Executable;56import java.util.HashMap;57import java.util.Map;5859public class GetLocalVariableTableTest {6061public static final int MAIN_LOCALS_COUNT = 0;62public static final int INSTANCE_LOCALS_COUNT = 4;63public static final int EMPTY_INSTANCE_COUNT = 1;64public static final int EMPTY_STATIC_COUNT = 0;65public static final int ABSTRACT_INHERIT_LOCALS_COUNT = 2;66public static final int DEFAULTFUNC_LOCALS_COUNT = 4;6768public static void main(String[] args) {69Map<Executable, Integer> testCases = createTestCases();70testCases.forEach(GetLocalVariableTableTest::runSanityTest);71}7273private static Map<Executable, Integer> createTestCases() {74HashMap<Executable, Integer> methods = new HashMap<>();75try {76Class<?> aClass;7778aClass = GetLocalVariableTableTest.class;79methods.put(aClass.getDeclaredMethod("main", String[].class),80MAIN_LOCALS_COUNT);8182aClass = DummyClass.class;83methods.put(aClass.getMethod("dummyInstanceFunction"),84INSTANCE_LOCALS_COUNT);85methods.put(aClass.getMethod("dummyEmptyInstanceFunction"),86EMPTY_INSTANCE_COUNT);87methods.put(aClass.getMethod("dummyEmptyStaticFunction"),88EMPTY_STATIC_COUNT);89methods.put(aClass.getMethod("dummyFunction"),90EMPTY_INSTANCE_COUNT);91methods.put(aClass.getMethod("dummyAbstractFunction"),92ABSTRACT_INHERIT_LOCALS_COUNT);9394aClass = DummyInterface.class;95methods.put(aClass.getMethod("dummyFunction"), EMPTY_STATIC_COUNT);96methods.put(aClass.getMethod("dummyDefaultFunction", int.class,97int.class), DEFAULTFUNC_LOCALS_COUNT);9899aClass = DummyAbstractClass.class;100methods.put(aClass.getMethod("dummyAbstractFunction"), 0);101} catch (NoSuchMethodException e) {102throw new Error("TEST BUG", e);103}104return methods;105}106107private static void runSanityTest(Executable aMethod,108Integer expectedTableLength) {109HotSpotResolvedJavaMethod method = CTVMUtilities110.getResolvedMethod(aMethod);111112int tblLength = CompilerToVMHelper.getLocalVariableTableLength(method);113Asserts.assertEQ(tblLength, expectedTableLength, aMethod + " : incorrect "114+ "local variable table length.");115116long tblStart = CompilerToVMHelper.getLocalVariableTableStart(method);117if (tblLength > 0) {118Asserts.assertNE(tblStart, 0L, aMethod + " : local variable table starts"119+ " at 0 with length " + tblLength);120}121}122}123124125