1 /* 2 * Copyright (c) 2012, 2016, 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 package org.graalvm.compiler.hotspot; 24 25 import org.graalvm.compiler.core.common.LIRKind; 26 import org.graalvm.compiler.debug.GraalError; 27 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction; 28 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 29 import org.graalvm.compiler.hotspot.nodes.DeoptimizationFetchUnrollInfoCallNode; 30 import org.graalvm.compiler.hotspot.nodes.EnterUnpackFramesStackFrameNode; 31 import org.graalvm.compiler.hotspot.nodes.GraalHotSpotVMConfigNode; 32 import org.graalvm.compiler.hotspot.nodes.LeaveCurrentStackFrameNode; 33 import org.graalvm.compiler.hotspot.nodes.LeaveDeoptimizedStackFrameNode; 34 import org.graalvm.compiler.hotspot.nodes.LeaveUnpackFramesStackFrameNode; 35 import org.graalvm.compiler.hotspot.nodes.PushInterpreterFrameNode; 36 import org.graalvm.compiler.hotspot.nodes.SaveAllRegistersNode; 37 import org.graalvm.compiler.hotspot.nodes.UncommonTrapCallNode; 38 import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode; 39 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode; 40 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode; 41 import org.graalvm.compiler.hotspot.nodes.profiling.RandomSeedNode; 42 import org.graalvm.compiler.hotspot.replacements.EncodedSymbolConstant; 43 import org.graalvm.compiler.lir.LIRFrameState; 44 import org.graalvm.compiler.lir.StandardOp.SaveRegistersOp; 45 import org.graalvm.compiler.lir.VirtualStackSlot; 46 import org.graalvm.compiler.lir.gen.LIRGenerator; 47 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 48 49 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant; 50 import jdk.vm.ci.hotspot.HotSpotObjectConstant; 51 import jdk.vm.ci.meta.Constant; 52 import jdk.vm.ci.meta.DeoptimizationAction; 53 import jdk.vm.ci.meta.DeoptimizationReason; 54 import jdk.vm.ci.meta.ResolvedJavaMethod; 55 import jdk.vm.ci.meta.Value; 56 57 /** 58 * This interface defines the contract a HotSpot backend LIR generator needs to fulfill in addition 59 * to abstract methods from {@link LIRGenerator} and {@link LIRGeneratorTool}. 60 */ 61 public interface HotSpotLIRGenerator extends LIRGeneratorTool { 62 63 /** 64 * Emits an operation to make a tail call. 65 * 66 * @param args the arguments of the call 67 * @param address the target address of the call 68 */ 69 void emitTailcall(Value[] args, Value address); 70 71 void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason); 72 73 /** 74 * Emits code for a {@link SaveAllRegistersNode}. 75 * 76 * @return a {@link SaveRegistersOp} operation 77 */ 78 SaveRegistersOp emitSaveAllRegisters(); 79 80 /** 81 * Emits code for a {@link LeaveCurrentStackFrameNode}. 82 * 83 * @param saveRegisterOp saved registers 84 */ 85 default void emitLeaveCurrentStackFrame(SaveRegistersOp saveRegisterOp) { 86 throw GraalError.unimplemented(); 87 } 88 89 /** 90 * Emits code for a {@link LeaveDeoptimizedStackFrameNode}. 91 * 92 * @param frameSize 93 * @param initialInfo 94 */ 95 default void emitLeaveDeoptimizedStackFrame(Value frameSize, Value initialInfo) { 96 throw GraalError.unimplemented(); 97 } 98 99 /** 100 * Emits code for a {@link EnterUnpackFramesStackFrameNode}. 101 * 102 * @param framePc 103 * @param senderSp 104 * @param senderFp 105 * @param saveRegisterOp 106 */ 107 default void emitEnterUnpackFramesStackFrame(Value framePc, Value senderSp, Value senderFp, SaveRegistersOp saveRegisterOp) { 108 throw GraalError.unimplemented(); 109 } 110 111 /** 112 * Emits code for a {@link LeaveUnpackFramesStackFrameNode}. 113 * 114 * @param saveRegisterOp 115 */ 116 default void emitLeaveUnpackFramesStackFrame(SaveRegistersOp saveRegisterOp) { 117 throw GraalError.unimplemented(); 118 } 119 120 /** 121 * Emits code for a {@link PushInterpreterFrameNode}. 122 * 123 * @param frameSize 124 * @param framePc 125 * @param senderSp 126 * @param initialInfo 127 */ 128 default void emitPushInterpreterFrame(Value frameSize, Value framePc, Value senderSp, Value initialInfo) { 129 throw GraalError.unimplemented(); 130 } 131 132 /** 133 * Emits code for a {@link LoadConstantIndirectlyNode}. 134 * 135 * @param constant 136 * @return value of loaded address in register 137 */ 138 default Value emitLoadObjectAddress(Constant constant) { 139 throw GraalError.unimplemented(); 140 } 141 142 /** 143 * Emits code for a {@link LoadConstantIndirectlyNode}. 144 * 145 * @param constant original constant 146 * @param action action to perform on the metaspace object 147 * @return Value of loaded address in register 148 */ 149 default Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { 150 throw GraalError.unimplemented(); 151 } 152 153 /** 154 * Emits code for a {@link GraalHotSpotVMConfigNode}. 155 * 156 * @param markId id of the value to load 157 * @param kind type of the value to load 158 * @return value of loaded global in register 159 */ 160 default Value emitLoadConfigValue(int markId, LIRKind kind) { 161 throw GraalError.unimplemented(); 162 } 163 164 /** 165 * Emits code for a {@link ResolveConstantNode} to resolve a {@link HotSpotObjectConstant}. 166 * 167 * @param constant original constant 168 * @param constantDescription a description of the string that need to be materialized (and 169 * interned) as java.lang.String, generated with {@link EncodedSymbolConstant} 170 * @param frameState frame state for the runtime call 171 * @return Returns the address of the requested constant. 172 */ 173 default Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 174 throw GraalError.unimplemented(); 175 } 176 177 /** 178 * Emits code for a {@link ResolveConstantNode} to resolve a {@link HotSpotMetaspaceConstant}. 179 * 180 * @param constant original constant 181 * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant} 182 * generated by {@link EncodedSymbolConstant} 183 * @param frameState frame state for the runtime call 184 * @return Returns the address of the requested constant. 185 */ 186 default Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 187 throw GraalError.unimplemented(); 188 } 189 190 /** 191 * Emits code for a {@link ResolveMethodAndLoadCountersNode} to resolve a 192 * {@link HotSpotMetaspaceConstant} that represents a {@link ResolvedJavaMethod} and return the 193 * corresponding MethodCounters object. 194 * 195 * @param method original constant 196 * @param klassHint a klass in which the method is declared 197 * @param methodDescription is symbolic description of the constant generated by 198 * {@link EncodedSymbolConstant} 199 * @param frameState frame state for the runtime call 200 * @return Returns the address of the requested constant. 201 */ 202 default Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { 203 throw GraalError.unimplemented(); 204 } 205 206 /** 207 * Emits code for a {@link ResolveConstantNode} to resolve a klass 208 * {@link HotSpotMetaspaceConstant} and run static initializer. 209 * 210 * 211 * @param constant original constant 212 * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant} 213 * generated by {@link EncodedSymbolConstant} 214 * @param frameState frame state for the runtime call 215 * @return Returns the address of the requested constant. 216 */ 217 default Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 218 throw GraalError.unimplemented(); 219 } 220 221 /** 222 * Emits code for a {@link RandomSeedNode}. 223 * 224 * @return value of the counter 225 */ 226 default Value emitRandomSeed() { 227 throw GraalError.unimplemented(); 228 } 229 230 /** 231 * Emits code for a {@link UncommonTrapCallNode}. 232 * 233 * @param trapRequest 234 * @param mode 235 * @param saveRegisterOp 236 * @return a {@code Deoptimization::UnrollBlock} pointer 237 */ 238 default Value emitUncommonTrapCall(Value trapRequest, Value mode, SaveRegistersOp saveRegisterOp) { 239 throw GraalError.unimplemented(); 240 } 241 242 /** 243 * Emits code for a {@link DeoptimizationFetchUnrollInfoCallNode}. 244 * 245 * @param mode 246 * @param saveRegisterOp 247 * @return a {@code Deoptimization::UnrollBlock} pointer 248 */ 249 default Value emitDeoptimizationFetchUnrollInfoCall(Value mode, SaveRegistersOp saveRegisterOp) { 250 throw GraalError.unimplemented(); 251 } 252 253 /** 254 * Gets a stack slot for a lock at a given lock nesting depth. 255 */ 256 VirtualStackSlot getLockSlot(int lockDepth); 257 258 @Override 259 HotSpotProviders getProviders(); 260 261 Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull); 262 263 Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull); 264 265 }