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.amd64; 24 25 import static jdk.vm.ci.amd64.AMD64.rbp; 26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; 27 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL; 28 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL; 29 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS; 30 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL; 31 32 import java.util.ArrayList; 33 import java.util.List; 34 35 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale; 36 import org.graalvm.compiler.core.amd64.AMD64ArithmeticLIRGenerator; 37 import org.graalvm.compiler.core.amd64.AMD64LIRGenerator; 38 import org.graalvm.compiler.core.amd64.AMD64LIRKindTool; 39 import org.graalvm.compiler.core.amd64.AMD64MoveFactoryBase.BackupSlotProvider; 40 import org.graalvm.compiler.core.common.CompressEncoding; 41 import org.graalvm.compiler.core.common.LIRKind; 42 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage; 43 import org.graalvm.compiler.core.common.spi.LIRKindTool; 44 import org.graalvm.compiler.debug.DebugContext; 45 import org.graalvm.compiler.debug.GraalError; 46 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 47 import org.graalvm.compiler.hotspot.HotSpotBackend; 48 import org.graalvm.compiler.hotspot.HotSpotDebugInfoBuilder; 49 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; 50 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult; 51 import org.graalvm.compiler.hotspot.HotSpotLIRGenerator; 52 import org.graalvm.compiler.hotspot.HotSpotLockStack; 53 import org.graalvm.compiler.hotspot.debug.BenchmarkCounters; 54 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction; 55 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 56 import org.graalvm.compiler.hotspot.stubs.Stub; 57 import org.graalvm.compiler.lir.LIR; 58 import org.graalvm.compiler.lir.LIRFrameState; 59 import org.graalvm.compiler.lir.LIRInstruction; 60 import org.graalvm.compiler.lir.LIRInstructionClass; 61 import org.graalvm.compiler.lir.LabelRef; 398 } 399 400 @Override 401 public Value emitLoadObjectAddress(Constant constant) { 402 HotSpotObjectConstant objectConstant = (HotSpotObjectConstant) constant; 403 LIRKind kind = objectConstant.isCompressed() ? getLIRKindTool().getNarrowOopKind() : getLIRKindTool().getObjectKind(); 404 Variable result = newVariable(kind); 405 append(new AMD64HotSpotLoadAddressOp(result, constant, HotSpotConstantLoadAction.RESOLVE)); 406 return result; 407 } 408 409 @Override 410 public Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { 411 HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant; 412 LIRKind kind = metaspaceConstant.isCompressed() ? getLIRKindTool().getNarrowPointerKind() : getLIRKindTool().getWordKind(); 413 Variable result = newVariable(kind); 414 append(new AMD64HotSpotLoadAddressOp(result, constant, action)); 415 return result; 416 } 417 418 @Override 419 public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 420 ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_STRING_BY_SYMBOL); 421 Constant[] constants = new Constant[]{constant}; 422 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; 423 Object[] notes = new Object[]{HotSpotConstantLoadAction.RESOLVE}; 424 append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); 425 AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); 426 return emitMove(result); 427 } 428 429 @Override 430 public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 431 ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_KLASS_BY_SYMBOL); 432 Constant[] constants = new Constant[]{constant}; 433 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; 434 Object[] notes = new Object[]{HotSpotConstantLoadAction.RESOLVE}; 435 append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); 436 AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); 437 return emitMove(result); 438 } 439 440 @Override 441 public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { 442 ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS); 443 Constant[] constants = new Constant[]{method}; 444 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)}; 445 Object[] notes = new Object[]{HotSpotConstantLoadAction.LOAD_COUNTERS}; 446 append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); 447 AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); 448 return emitMove(result); 449 450 } 451 452 @Override 453 public Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 454 ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(INITIALIZE_KLASS_BY_SYMBOL); 455 Constant[] constants = new Constant[]{constant}; 456 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; 457 Object[] notes = new Object[]{HotSpotConstantLoadAction.INITIALIZE}; 458 append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); 459 AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); 460 return emitMove(result); 461 } 462 463 @Override 464 public Value emitLoadConfigValue(int markId, LIRKind kind) { 465 Variable result = newVariable(kind); 466 append(new AMD64HotSpotLoadConfigValueOp(markId, result)); 467 return result; 468 } 469 470 @Override 471 public Value emitRandomSeed() { 472 AMD64ReadTimestampCounter timestamp = new AMD64ReadTimestampCounter(); 473 append(timestamp); 474 return emitMove(timestamp.getLowResult()); 475 } 476 477 @Override 478 public void emitTailcall(Value[] args, Value address) { 479 append(new AMD64TailcallOp(args, address)); 480 } | 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.amd64; 24 25 import static jdk.vm.ci.amd64.AMD64.rbp; 26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; 27 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL; 28 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL; 29 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS; 30 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL; 31 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE; 32 import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.RESOLVE; 33 import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.INITIALIZE; 34 import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.LOAD_COUNTERS; 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale; 40 import org.graalvm.compiler.core.amd64.AMD64ArithmeticLIRGenerator; 41 import org.graalvm.compiler.core.amd64.AMD64LIRGenerator; 42 import org.graalvm.compiler.core.amd64.AMD64LIRKindTool; 43 import org.graalvm.compiler.core.amd64.AMD64MoveFactoryBase.BackupSlotProvider; 44 import org.graalvm.compiler.core.common.CompressEncoding; 45 import org.graalvm.compiler.core.common.LIRKind; 46 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; 47 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage; 48 import org.graalvm.compiler.core.common.spi.LIRKindTool; 49 import org.graalvm.compiler.debug.DebugContext; 50 import org.graalvm.compiler.debug.GraalError; 51 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 52 import org.graalvm.compiler.hotspot.HotSpotBackend; 53 import org.graalvm.compiler.hotspot.HotSpotDebugInfoBuilder; 54 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; 55 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult; 56 import org.graalvm.compiler.hotspot.HotSpotLIRGenerator; 57 import org.graalvm.compiler.hotspot.HotSpotLockStack; 58 import org.graalvm.compiler.hotspot.debug.BenchmarkCounters; 59 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction; 60 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 61 import org.graalvm.compiler.hotspot.stubs.Stub; 62 import org.graalvm.compiler.lir.LIR; 63 import org.graalvm.compiler.lir.LIRFrameState; 64 import org.graalvm.compiler.lir.LIRInstruction; 65 import org.graalvm.compiler.lir.LIRInstructionClass; 66 import org.graalvm.compiler.lir.LabelRef; 403 } 404 405 @Override 406 public Value emitLoadObjectAddress(Constant constant) { 407 HotSpotObjectConstant objectConstant = (HotSpotObjectConstant) constant; 408 LIRKind kind = objectConstant.isCompressed() ? getLIRKindTool().getNarrowOopKind() : getLIRKindTool().getObjectKind(); 409 Variable result = newVariable(kind); 410 append(new AMD64HotSpotLoadAddressOp(result, constant, HotSpotConstantLoadAction.RESOLVE)); 411 return result; 412 } 413 414 @Override 415 public Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { 416 HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant; 417 LIRKind kind = metaspaceConstant.isCompressed() ? getLIRKindTool().getNarrowPointerKind() : getLIRKindTool().getWordKind(); 418 Variable result = newVariable(kind); 419 append(new AMD64HotSpotLoadAddressOp(result, constant, action)); 420 return result; 421 } 422 423 private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, Object[] notes, Constant[] constants, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { 424 ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(foreignCall); 425 append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); 426 AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); 427 return emitMove(result); 428 } 429 430 private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { 431 Constant[] constants = new Constant[]{constant}; 432 Object[] notes = new Object[]{action}; 433 return emitConstantRetrieval(foreignCall, notes, constants, constantDescriptions, frameState); 434 } 435 436 private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, Value constantDescription, LIRFrameState frameState) { 437 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; 438 return emitConstantRetrieval(foreignCall, action, constant, constantDescriptions, frameState); 439 } 440 441 @Override 442 public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 443 return emitConstantRetrieval(RESOLVE_STRING_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); 444 } 445 446 @Override 447 public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 448 return emitConstantRetrieval(RESOLVE_KLASS_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); 449 } 450 451 @Override 452 public Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { 453 return emitConstantRetrieval(INITIALIZE_KLASS_BY_SYMBOL, INITIALIZE, constant, constantDescription, frameState); 454 } 455 456 @Override 457 public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { 458 AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)}; 459 return emitConstantRetrieval(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, LOAD_COUNTERS, method, constantDescriptions, frameState); 460 } 461 462 @Override 463 public Value emitResolveDynamicInvoke(Constant appendix, LIRFrameState frameState) { 464 AllocatableValue[] constantDescriptions = new AllocatableValue[0]; 465 return emitConstantRetrieval(RESOLVE_DYNAMIC_INVOKE, INITIALIZE, appendix, constantDescriptions, frameState); 466 } 467 468 @Override 469 public Value emitLoadConfigValue(int markId, LIRKind kind) { 470 Variable result = newVariable(kind); 471 append(new AMD64HotSpotLoadConfigValueOp(markId, result)); 472 return result; 473 } 474 475 @Override 476 public Value emitRandomSeed() { 477 AMD64ReadTimestampCounter timestamp = new AMD64ReadTimestampCounter(); 478 append(timestamp); 479 return emitMove(timestamp.getLowResult()); 480 } 481 482 @Override 483 public void emitTailcall(Value[] args, Value address) { 484 append(new AMD64TailcallOp(args, address)); 485 } |