Path: blob/master/test/hotspot/jtreg/compiler/jvmci/errors/CodeInstallerTest.java
41152 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*/2223package compiler.jvmci.errors;2425import jdk.vm.ci.code.Architecture;26import jdk.vm.ci.code.CodeCacheProvider;27import jdk.vm.ci.code.Register;28import jdk.vm.ci.code.RegisterArray;29import jdk.vm.ci.code.StackSlot;30import jdk.vm.ci.code.site.DataPatch;31import jdk.vm.ci.code.site.Site;32import jdk.vm.ci.hotspot.HotSpotCompiledCode;33import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;34import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;35import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;36import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;37import jdk.vm.ci.meta.Assumptions.Assumption;38import jdk.vm.ci.meta.MetaAccessProvider;39import jdk.vm.ci.meta.PlatformKind;40import jdk.vm.ci.meta.ResolvedJavaMethod;41import jdk.vm.ci.runtime.JVMCI;42import jdk.vm.ci.runtime.JVMCIBackend;43import org.junit.Assert;4445import java.lang.reflect.Method;4647public class CodeInstallerTest {4849protected final Architecture arch;50protected final CodeCacheProvider codeCache;51protected final MetaAccessProvider metaAccess;52protected final HotSpotConstantReflectionProvider constantReflection;5354protected final HotSpotResolvedJavaMethod dummyMethod;5556public static void dummyMethod() {57}5859protected CodeInstallerTest() {60JVMCIBackend backend = JVMCI.getRuntime().getHostJVMCIBackend();61metaAccess = backend.getMetaAccess();62codeCache = backend.getCodeCache();63constantReflection = (HotSpotConstantReflectionProvider) backend.getConstantReflection();64arch = codeCache.getTarget().arch;6566Method method = null;67try {68method = CodeInstallerTest.class.getMethod("dummyMethod");69} catch (NoSuchMethodException e) {70Assert.fail();71}7273dummyMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);74}7576protected void installEmptyCode(Site[] sites, Assumption[] assumptions, Comment[] comments, int dataSectionAlignment, DataPatch[] dataSectionPatches, StackSlot deoptRescueSlot) {77HotSpotCompiledCode code = new HotSpotCompiledNmethod("dummyMethod", new byte[0], 0, sites, assumptions, new ResolvedJavaMethod[]{dummyMethod}, comments, new byte[8], dataSectionAlignment,78dataSectionPatches, false, 0, deoptRescueSlot,79dummyMethod, 0, 1, 0L, false);80codeCache.addCode(dummyMethod, code, null, null);81}8283protected Register getRegister(PlatformKind kind, int index) {84int idx = index;85RegisterArray allRegs = arch.getAvailableValueRegisters();86for (Register reg : allRegs) {87if (arch.canStoreValue(reg.getRegisterCategory(), kind)) {88if (idx-- == 0) {89return reg;90}91}92}93return null;94}95}969798