1 /* 2 * Copyright (c) 2012, 2017, 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.GraalHotSpotVMConfigNode; 30 import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode; 31 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode; 32 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode; 33 import org.graalvm.compiler.hotspot.nodes.profiling.RandomSeedNode; 34 import org.graalvm.compiler.hotspot.replacements.EncodedSymbolConstant; 35 import org.graalvm.compiler.lir.LIRFrameState; 36 import org.graalvm.compiler.lir.VirtualStackSlot; 37 import org.graalvm.compiler.lir.gen.LIRGenerator; 38 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 39 40 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant; 41 import jdk.vm.ci.hotspot.HotSpotObjectConstant; 42 import jdk.vm.ci.meta.Constant; 43 import jdk.vm.ci.meta.DeoptimizationAction; 44 import jdk.vm.ci.meta.DeoptimizationReason; 45 import jdk.vm.ci.meta.ResolvedJavaMethod; 46 import jdk.vm.ci.meta.Value; 47 48 /** 49 * This interface defines the contract a HotSpot backend LIR generator needs to fulfill in addition 50 * to abstract methods from {@link LIRGenerator} and {@link LIRGeneratorTool}. 51 */ 52 public interface HotSpotLIRGenerator extends LIRGeneratorTool { 53 54 /** 55 * Emits an operation to make a tail call. 56 * 57 * @param args the arguments of the call 58 * @param address the target address of the call 59 */ 60 void emitTailcall(Value[] args, Value address); 61 62 void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason); 63 64 /** 65 * Emits code for a {@link LoadConstantIndirectlyNode}. 66 * 67 * @param constant 68 * @return value of loaded address in register 69 */ 70 default Value emitLoadObjectAddress(Constant constant) { 71 throw new GraalError("Emitting code to load an object address is not currently supported on %s", target().arch); 72 } 73 74 /** 75 * Emits code for a {@link LoadConstantIndirectlyNode}. 76 * 77 * @param constant original constant 78 * @param action action to perform on the metaspace object 79 * @return Value of loaded address in register 80 */ 81 default Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { 82 throw new GraalError("Emitting code to load a metaspace address is not currently supported on %s", target().arch); 83 } 84 85 /** 86 * Emits code for a {@link GraalHotSpotVMConfigNode}. 87 * 88 * @param markId id of the value to load 89 * @param kind type of the value to load 90 * @return value of loaded global in register 91 */ 92 default Value emitLoadConfigValue(int markId, LIRKind kind) { 93 throw new GraalError("Emitting code to load a config value is not currently supported on %s", target().arch); 94 } 95 96 /** 97 * Emits code for a {@link ResolveConstantNode} to resolve a {@link HotSpotObjectConstant}. 98 * 99 * @param constant original constant 100 * @param constantDescription a description of the string that need to be materialized (and 101 * interned) as java.lang.String, generated with {@link EncodedSymbolConstant} 102 * @param frameState frame state for the runtime call 103 * @return the address of the requested constant. 104 */ 105 default Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 106 throw new GraalError("Emitting code to resolve an object constant is not currently supported on %s", target().arch); 107 } 108 109 /** 110 * Emits code to resolve a dynamic constant. 111 * 112 * @param constant original constant 113 * @param frameState frame state for the runtime call 114 * @return the address of the requested constant. 115 */ 116 default Value emitResolveDynamicInvoke(Constant constant, LIRFrameState frameState) { 117 throw new GraalError("Emitting code to resolve a dynamic constant is not currently supported on %s", target().arch); 118 } 119 120 /** 121 * Emits code for a {@link ResolveConstantNode} to resolve a {@link HotSpotMetaspaceConstant}. 122 * 123 * @param constant original constant 124 * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant} 125 * generated by {@link EncodedSymbolConstant} 126 * @param frameState frame state for the runtime call 127 * @return the address of the requested constant. 128 */ 129 default Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 130 throw new GraalError("Emitting code to resolve a metaspace constant is not currently supported on %s", target().arch); 131 } 132 133 /** 134 * Emits code for a {@link ResolveMethodAndLoadCountersNode} to resolve a 135 * {@link HotSpotMetaspaceConstant} that represents a {@link ResolvedJavaMethod} and return the 136 * corresponding MethodCounters object. 137 * 138 * @param method original constant 139 * @param klassHint a klass in which the method is declared 140 * @param methodDescription is symbolic description of the constant generated by 141 * {@link EncodedSymbolConstant} 142 * @param frameState frame state for the runtime call 143 * @return the address of the requested constant. 144 */ 145 default Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { 146 throw new GraalError("Emitting code to resolve a method and load counters is not currently supported on %s", target().arch); 147 } 148 149 /** 150 * Emits code for a {@link ResolveConstantNode} to resolve a klass 151 * {@link HotSpotMetaspaceConstant} and run static initializer. 152 * 153 * 154 * @param constant original constant 155 * @param constantDescription a symbolic description of the {@link HotSpotMetaspaceConstant} 156 * generated by {@link EncodedSymbolConstant} 157 * @param frameState frame state for the runtime call 158 * @return the address of the requested constant. 159 */ 160 default Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 161 throw new GraalError("Emitting code to initialize a class is not currently supported on %s", target().arch); 162 } 163 164 /** 165 * Emits code for a {@link RandomSeedNode}. 166 * 167 * @return value of the counter 168 */ 169 default Value emitRandomSeed() { 170 throw new GraalError("Emitting code to return a random seed is not currently supported on %s", target().arch); 171 } 172 173 /** 174 * Gets a stack slot for a lock at a given lock nesting depth. 175 */ 176 VirtualStackSlot getLockSlot(int lockDepth); 177 178 @Override 179 HotSpotProviders getProviders(); 180 181 }