1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package compiler.jvmci.errors; 25 26 import java.lang.reflect.Method; 27 28 import jdk.vm.ci.code.Architecture; 29 import jdk.vm.ci.code.CodeCacheProvider; 30 import jdk.vm.ci.code.CompilationResult; 31 import jdk.vm.ci.code.Register; 32 import jdk.vm.ci.meta.MetaAccessProvider; 33 import jdk.vm.ci.meta.PlatformKind; 34 import jdk.vm.ci.meta.ResolvedJavaMethod; 35 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; 36 import jdk.vm.ci.runtime.JVMCI; 37 import jdk.vm.ci.runtime.JVMCIBackend; 38 39 import org.junit.Assert; 40 41 public class CodeInstallerTest { 42 43 protected final Architecture arch; 44 protected final CodeCacheProvider codeCache; 45 protected final MetaAccessProvider metaAccess; 46 protected final HotSpotConstantReflectionProvider constantReflection; 47 48 protected final ResolvedJavaMethod dummyMethod; 49 50 public static void dummyMethod() { 51 } 52 53 protected CodeInstallerTest() { 54 JVMCIBackend backend = JVMCI.getRuntime().getHostJVMCIBackend(); 55 metaAccess = backend.getMetaAccess(); 56 codeCache = backend.getCodeCache(); 57 constantReflection = (HotSpotConstantReflectionProvider) backend.getConstantReflection(); 58 arch = codeCache.getTarget().arch; 59 60 Method method = null; 61 try { 62 method = CodeInstallerTest.class.getMethod("dummyMethod"); 63 } catch (NoSuchMethodException e) { 64 Assert.fail(); 65 } 66 67 dummyMethod = metaAccess.lookupJavaMethod(method); 68 } 69 70 protected void installCode(CompilationResult result) { 71 codeCache.addCode(dummyMethod, result, null, null); 72 } 73 74 protected CompilationResult createEmptyCompilationResult() { 75 CompilationResult ret = new CompilationResult(); 76 ret.setTotalFrameSize(0); 77 return ret; 78 } 79 80 protected Register getRegister(PlatformKind kind, int index) { 81 Register[] allRegs = arch.getAvailableValueRegisters(); 82 for (int i = 0; i < allRegs.length; i++) { 83 if (arch.canStoreValue(allRegs[i].getRegisterCategory(), kind)) { 84 if (index-- == 0) { 85 return allRegs[i]; 86 } 87 } 88 } 89 return null; 90 } 91 }