1 /* 2 * Copyright (c) 2011, 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 com.oracle.graal.hotspot.bridge; 25 26 import java.lang.reflect.*; 27 28 import com.oracle.graal.api.code.*; 29 import com.oracle.graal.api.meta.*; 30 import com.oracle.graal.hotspot.*; 31 import com.oracle.graal.hotspot.meta.*; 32 33 /** 34 * Calls from Java into HotSpot. 35 */ 36 public interface CompilerToVM { 37 38 /** 39 * Copies the original bytecode of a given method into a given byte array. 40 * 41 * @param metaspaceMethod the metaspace Method object 42 * @param code the array into which to copy the original bytecode 43 * @return the value of {@code code} 44 */ 45 byte[] initializeBytecode(long metaspaceMethod, byte[] code); 46 47 String getSignature(long metaspaceMethod); 48 49 ExceptionHandler[] initializeExceptionHandlers(long metaspaceMethod, ExceptionHandler[] handlers); 50 51 /** 52 * Determines if a given metaspace Method object has balanced monitors. 53 * 54 * @param metaspaceMethod the metaspace Method object to query 55 * @return true if the method has balanced monitors 56 */ 57 boolean hasBalancedMonitors(long metaspaceMethod); 58 59 /** 60 * Determines if a given metaspace Method object is compilable. A method may not be compilable 61 * for a number of reasons such as: 62 * <ul> 63 * <li>a CompileOracle directive may prevent compilation of methods</li> 64 * <li>the method may have a bytecode breakpoint set</li> 65 * <li>the method may have other bytecode features that require special handling by the VM</li> 66 * </ul> 67 * 68 * A non-compilable method should not be inlined. 69 * 70 * @param metaspaceMethod the metaspace Method object to query 71 * @return true if the method is compilable 72 */ 73 boolean isMethodCompilable(long metaspaceMethod); 74 75 /** 76 * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}. 77 * 78 * @param metaspaceMethod the metaspace Method on which to based the search 79 * @param resultHolder the holder of the result is put in element 0 of this array 80 * @return the metaspace Method result or 0 is there is no unique concrete method for 81 * {@code metaspaceMethod} 82 */ 83 long getUniqueConcreteMethod(long metaspaceMethod, HotSpotResolvedObjectType[] resultHolder); 84 85 /** 86 * Used to determine if an interface has exactly one implementor. 87 * 88 * @param interfaceType interface for which the implementor should be returned 89 * @return the unique implementor of the interface or null if the interface has 0 or more than 1 90 * implementor 91 */ 92 ResolvedJavaType getUniqueImplementor(HotSpotResolvedObjectType interfaceType); 93 94 /** 95 * Gets the invocation count for a method. 96 * 97 * @param metaspaceMethod the metaspace Method object to query 98 * @return the invocation count for the method 99 */ 100 int getInvocationCount(long metaspaceMethod); 101 102 /** 103 * Initializes a {@link HotSpotResolvedJavaMethod} object from a metaspace Method object. 104 * 105 * @param metaspaceMethod the metaspace Method object 106 * @param method address of a metaspace Method object 107 */ 108 void initializeMethod(long metaspaceMethod, HotSpotResolvedJavaMethod method); 109 110 /** 111 * Initializes a {@link HotSpotMethodData} object from a metaspace MethodData object. 112 * 113 * @param metaspaceMethodData the metaspace MethodData object 114 * @param methodData the object to initialize from the metaspace object 115 */ 116 void initializeMethodData(long metaspaceMethodData, HotSpotMethodData methodData); 117 118 /** 119 * Converts a name to a Java type. 120 * 121 * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format 122 * @param accessingClass the context of resolution (may be null) 123 * @param eagerResolve force resolution to a {@link ResolvedJavaType}. If true, this method will 124 * either return a {@link ResolvedJavaType} or throw an exception 125 * @return a Java type for {@code name} which is guaranteed to be of type 126 * {@link ResolvedJavaType} if {@code eagerResolve == true} 127 * @throws LinkageError if {@code eagerResolve == true} and the resolution failed 128 */ 129 JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve); 130 131 int constantPoolLength(HotSpotResolvedObjectType pool); 132 133 Object lookupConstantInPool(HotSpotResolvedObjectType pool, int cpi); 134 135 JavaMethod lookupMethodInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode); 136 137 JavaType lookupTypeInPool(HotSpotResolvedObjectType pool, int cpi); 138 139 JavaField lookupFieldInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode); 140 141 void lookupReferencedTypeInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode); 142 143 Object lookupAppendixInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode); 144 145 // Must be kept in sync with enum in graalEnv.hpp 146 public enum CodeInstallResult { 147 OK, DEPENDENCIES_FAILED, CACHE_FULL 148 } 149 150 /** 151 * Installs the result of a compilation into the code cache. 152 * 153 * @param compResult the result of a compilation 154 * @param code if not null, then the code is installed as the non-default compiled code for the 155 * associated method and the details of the installation are written to this object 156 * @return the outcome of the installation as a {@link CodeInstallResult}. 157 */ 158 CodeInstallResult installCode(HotSpotCompilationResult compResult, HotSpotInstalledCode code, SpeculationLog cache); 159 160 void initializeConfiguration(HotSpotVMConfig config); 161 162 JavaMethod resolveMethod(HotSpotResolvedObjectType klass, String name, String signature); 163 164 boolean isTypeInitialized(HotSpotResolvedObjectType klass); 165 166 void initializeType(HotSpotResolvedObjectType klass); 167 168 ResolvedJavaType getResolvedType(Class<?> javaClass); 169 170 HotSpotResolvedJavaField[] getInstanceFields(HotSpotResolvedObjectType klass); 171 172 /** 173 * Gets the compiled code size for a method. 174 * 175 * @param metaspaceMethod the metaspace Method object to query 176 * @return the compiled code size the method 177 */ 178 int getCompiledCodeSize(long metaspaceMethod); 179 180 /** 181 * Gets the metaspace Method object corresponding to a given reflection {@link Method} object. 182 * 183 * @param reflectionMethod 184 * @param resultHolder the holder of the result is put in element 0 of this array 185 * @return the metaspace Method result for {@code reflectionMethod} 186 */ 187 long getMetaspaceMethod(Method reflectionMethod, HotSpotResolvedObjectType[] resultHolder); 188 189 long getMetaspaceConstructor(Constructor reflectionConstructor, HotSpotResolvedObjectType[] resultHolder); 190 191 HotSpotResolvedJavaField getJavaField(Field reflectionField); 192 193 long getMaxCallTargetOffset(long stub); 194 195 String disassembleNMethod(long nmethod); 196 197 /** 198 * Gets a copy of the machine code for an nmethod. 199 * 200 * @return the machine code for {@code nmethod} if it is valid, null otherwise 201 */ 202 byte[] getCode(long nmethod); 203 204 StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); 205 206 Object executeCompiledMethod(long metaspaceMethod, long nmethod, Object arg1, Object arg2, Object arg3); 207 208 Object executeCompiledMethodVarargs(long metaspaceMethod, long nmethod, Object... args); 209 210 int getVtableEntryOffset(long metaspaceMethod); 211 212 long[] getDeoptedLeafGraphIds(); 213 214 long[] getLineNumberTable(HotSpotResolvedJavaMethod method); 215 216 Local[] getLocalVariableTable(HotSpotResolvedJavaMethod method); 217 218 String getFileName(HotSpotResolvedJavaType method); 219 220 void clearQueuedForCompilation(HotSpotResolvedJavaMethod method); 221 222 /** 223 * Invalidates the profiling information and restarts profiling upon the next invocation. 224 * 225 * @param metaspaceMethod the metaspace Method object 226 */ 227 void reprofile(long metaspaceMethod); 228 }