001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.hotspot.amd64; 024 025import jdk.internal.jvmci.hotspot.*; 026import jdk.internal.jvmci.meta.*; 027import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; 028 029import com.oracle.graal.asm.amd64.*; 030import com.oracle.graal.asm.amd64.AMD64Assembler.*; 031import com.oracle.graal.lir.*; 032import com.oracle.graal.lir.amd64.*; 033import com.oracle.graal.lir.asm.*; 034 035public class AMD64HotSpotBinaryConsumer { 036 037 /** 038 * Instruction that has one {@link AllocatableValue} operand and one {@link HotSpotConstant} 039 * operand. 040 */ 041 public static class ConstOp extends AMD64BinaryConsumer.ConstOp { 042 public static final LIRInstructionClass<ConstOp> TYPE = LIRInstructionClass.create(ConstOp.class); 043 044 protected final HotSpotConstant c; 045 046 public ConstOp(AMD64MIOp opcode, AllocatableValue x, HotSpotConstant c) { 047 super(TYPE, opcode, DWORD, x, asImm32(c)); 048 this.c = c; 049 } 050 051 @Override 052 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { 053 assert crb.target.inlineObjects || !(c instanceof HotSpotObjectConstant); 054 crb.recordInlineDataInCode(c); 055 super.emitCode(crb, masm); 056 } 057 } 058 059 /** 060 * Instruction that has one {@link AMD64AddressValue memory} operand and one 061 * {@link HotSpotConstant} operand. 062 */ 063 public static class MemoryConstOp extends AMD64BinaryConsumer.MemoryConstOp { 064 public static final LIRInstructionClass<MemoryConstOp> TYPE = LIRInstructionClass.create(MemoryConstOp.class); 065 066 protected final HotSpotConstant c; 067 068 public MemoryConstOp(AMD64MIOp opcode, AMD64AddressValue x, HotSpotConstant c, LIRFrameState state) { 069 super(TYPE, opcode, DWORD, x, asImm32(c), state); 070 this.c = c; 071 072 } 073 074 @Override 075 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { 076 assert crb.target.inlineObjects || !(c instanceof HotSpotObjectConstant); 077 crb.recordInlineDataInCode(c); 078 super.emitCode(crb, masm); 079 } 080 } 081 082 private static int asImm32(HotSpotConstant c) { 083 assert c.isCompressed(); 084 if (c instanceof HotSpotMetaspaceConstant) { 085 return (int) ((HotSpotMetaspaceConstant) c).rawValue(); 086 } else { 087 assert c instanceof HotSpotObjectConstant; 088 return 0xDEADDEAD; 089 } 090 } 091}