< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotMove.java

Print this page




   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.amd64;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;
  27 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL;
  28 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
  29 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
  30 import static jdk.vm.ci.code.ValueUtil.asRegister;
  31 import static jdk.vm.ci.code.ValueUtil.isRegister;
  32 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  33 
  34 import org.graalvm.compiler.asm.Label;
  35 import org.graalvm.compiler.asm.amd64.AMD64Address;
  36 import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
  37 import org.graalvm.compiler.core.common.CompressEncoding;
  38 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
  39 import org.graalvm.compiler.debug.GraalError;
  40 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  41 import org.graalvm.compiler.lir.LIRInstructionClass;
  42 import org.graalvm.compiler.lir.StandardOp.LoadConstantOp;
  43 import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
  44 import org.graalvm.compiler.lir.amd64.AMD64Move;
  45 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  46 
  47 import jdk.vm.ci.amd64.AMD64Kind;
  48 import jdk.vm.ci.code.Register;
  49 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
  50 import jdk.vm.ci.hotspot.HotSpotObjectConstant;
  51 import jdk.vm.ci.meta.AllocatableValue;
  52 import jdk.vm.ci.meta.Constant;
  53 
  54 public class AMD64HotSpotMove {
  55 
  56     public static final class HotSpotLoadObjectConstantOp extends AMD64LIRInstruction implements LoadConstantOp {
  57         public static final LIRInstructionClass<HotSpotLoadObjectConstantOp> TYPE = LIRInstructionClass.create(HotSpotLoadObjectConstantOp.class);
  58 
  59         @Def({REG, STACK}) private AllocatableValue result;
  60         private final HotSpotObjectConstant input;
  61 
  62         public HotSpotLoadObjectConstantOp(AllocatableValue result, HotSpotObjectConstant input) {
  63             super(TYPE);
  64             this.result = result;
  65             this.input = input;
  66         }
  67 


 160                 }
 161             } else {
 162                 assert isStackSlot(result);
 163                 if (compressed) {
 164                     crb.recordInlineDataInCode(input);
 165                     masm.movl((AMD64Address) crb.asAddress(result), 0xDEADDEAD);
 166                 } else {
 167                     throw GraalError.shouldNotReachHere("Cannot store 64-bit constants to memory");
 168                 }
 169             }
 170         }
 171 
 172         @Override
 173         public Constant getConstant() {
 174             return input;
 175         }
 176 
 177         @Override
 178         public AllocatableValue getResult() {
 179             return result;
 180         }
 181     }
 182 
 183     public static final class CompressPointer extends AMD64LIRInstruction {
 184         public static final LIRInstructionClass<CompressPointer> TYPE = LIRInstructionClass.create(CompressPointer.class);
 185 
 186         private final CompressEncoding encoding;
 187         private final boolean nonNull;
 188 
 189         @Def({REG, HINT}) protected AllocatableValue result;
 190         @Use({REG}) protected AllocatableValue input;
 191         @Alive({REG, ILLEGAL}) protected AllocatableValue baseRegister;
 192 
 193         public CompressPointer(AllocatableValue result, AllocatableValue input, AllocatableValue baseRegister, CompressEncoding encoding, boolean nonNull) {
 194             super(TYPE);
 195             this.result = result;
 196             this.input = input;
 197             this.baseRegister = baseRegister;
 198             this.encoding = encoding;
 199             this.nonNull = nonNull;
 200         }
 201 
 202         @Override
 203         public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
 204             AMD64Move.move(AMD64Kind.QWORD, crb, masm, result, input);
 205 
 206             Register resReg = asRegister(result);
 207             if (encoding.hasBase() || GeneratePIC.getValue(crb.getOptions())) {
 208                 Register baseReg = asRegister(baseRegister);
 209                 if (!nonNull) {
 210                     masm.testq(resReg, resReg);
 211                     masm.cmovq(ConditionFlag.Equal, resReg, baseReg);
 212                 }
 213                 masm.subq(resReg, baseReg);
 214             }
 215 
 216             if (encoding.hasShift()) {
 217                 masm.shrq(resReg, encoding.getShift());
 218             }
 219         }
 220     }
 221 
 222     public static final class UncompressPointer extends AMD64LIRInstruction {
 223         public static final LIRInstructionClass<UncompressPointer> TYPE = LIRInstructionClass.create(UncompressPointer.class);
 224 
 225         private final CompressEncoding encoding;
 226         private final boolean nonNull;
 227 
 228         @Def({REG, HINT}) protected AllocatableValue result;
 229         @Use({REG}) protected AllocatableValue input;
 230         @Alive({REG, ILLEGAL}) protected AllocatableValue baseRegister;
 231 
 232         public UncompressPointer(AllocatableValue result, AllocatableValue input, AllocatableValue baseRegister, CompressEncoding encoding, boolean nonNull) {
 233             super(TYPE);
 234             this.result = result;
 235             this.input = input;
 236             this.baseRegister = baseRegister;
 237             this.encoding = encoding;
 238             this.nonNull = nonNull;
 239         }
 240 
 241         @Override
 242         public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
 243             AMD64Move.move(AMD64Kind.DWORD, crb, masm, result, input);
 244 
 245             Register resReg = asRegister(result);
 246             if (encoding.getShift() != 0) {
 247                 masm.shlq(resReg, encoding.getShift());
 248             }
 249 
 250             if (encoding.hasBase() || GeneratePIC.getValue(crb.getOptions())) {
 251                 if (nonNull) {
 252                     masm.addq(resReg, asRegister(baseRegister));
 253                 } else {
 254                     if (!encoding.hasShift()) {
 255                         // if encoding.shift != 0, the flags are already set by the shlq
 256                         masm.testq(resReg, resReg);
 257                     }
 258 
 259                     Label done = new Label();
 260                     masm.jccb(ConditionFlag.Equal, done);
 261                     masm.addq(resReg, asRegister(baseRegister));
 262                     masm.bind(done);
 263                 }
 264             }
 265         }
 266     }
 267 
 268     public static void decodeKlassPointer(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register register, Register scratch, AMD64Address address, GraalHotSpotVMConfig config) {
 269         CompressEncoding encoding = config.getKlassEncoding();
 270         masm.movl(register, address);
 271         if (encoding.getShift() != 0) {
 272             masm.shlq(register, encoding.getShift());
 273         }
 274         boolean pic = GeneratePIC.getValue(crb.getOptions());
 275         if (pic || encoding.hasBase()) {
 276             if (pic) {
 277                 masm.movq(scratch, masm.getPlaceholder(-1));
 278                 crb.recordMark(config.MARKID_NARROW_KLASS_BASE_ADDRESS);
 279             } else {
 280                 assert encoding.getBase() != 0;
 281                 masm.movq(scratch, encoding.getBase());
 282             }
 283             masm.addq(register, scratch);
 284         }


   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.amd64;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;

  27 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
  28 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
  29 import static jdk.vm.ci.code.ValueUtil.asRegister;
  30 import static jdk.vm.ci.code.ValueUtil.isRegister;
  31 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  32 

  33 import org.graalvm.compiler.asm.amd64.AMD64Address;

  34 import org.graalvm.compiler.core.common.CompressEncoding;
  35 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  38 import org.graalvm.compiler.lir.LIRInstructionClass;
  39 import org.graalvm.compiler.lir.StandardOp.LoadConstantOp;
  40 import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;

  41 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  42 

  43 import jdk.vm.ci.code.Register;
  44 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
  45 import jdk.vm.ci.hotspot.HotSpotObjectConstant;
  46 import jdk.vm.ci.meta.AllocatableValue;
  47 import jdk.vm.ci.meta.Constant;
  48 
  49 public class AMD64HotSpotMove {
  50 
  51     public static final class HotSpotLoadObjectConstantOp extends AMD64LIRInstruction implements LoadConstantOp {
  52         public static final LIRInstructionClass<HotSpotLoadObjectConstantOp> TYPE = LIRInstructionClass.create(HotSpotLoadObjectConstantOp.class);
  53 
  54         @Def({REG, STACK}) private AllocatableValue result;
  55         private final HotSpotObjectConstant input;
  56 
  57         public HotSpotLoadObjectConstantOp(AllocatableValue result, HotSpotObjectConstant input) {
  58             super(TYPE);
  59             this.result = result;
  60             this.input = input;
  61         }
  62 


 155                 }
 156             } else {
 157                 assert isStackSlot(result);
 158                 if (compressed) {
 159                     crb.recordInlineDataInCode(input);
 160                     masm.movl((AMD64Address) crb.asAddress(result), 0xDEADDEAD);
 161                 } else {
 162                     throw GraalError.shouldNotReachHere("Cannot store 64-bit constants to memory");
 163                 }
 164             }
 165         }
 166 
 167         @Override
 168         public Constant getConstant() {
 169             return input;
 170         }
 171 
 172         @Override
 173         public AllocatableValue getResult() {
 174             return result;





















































































 175         }
 176     }
 177 
 178     public static void decodeKlassPointer(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register register, Register scratch, AMD64Address address, GraalHotSpotVMConfig config) {
 179         CompressEncoding encoding = config.getKlassEncoding();
 180         masm.movl(register, address);
 181         if (encoding.getShift() != 0) {
 182             masm.shlq(register, encoding.getShift());
 183         }
 184         boolean pic = GeneratePIC.getValue(crb.getOptions());
 185         if (pic || encoding.hasBase()) {
 186             if (pic) {
 187                 masm.movq(scratch, masm.getPlaceholder(-1));
 188                 crb.recordMark(config.MARKID_NARROW_KLASS_BASE_ADDRESS);
 189             } else {
 190                 assert encoding.getBase() != 0;
 191                 masm.movq(scratch, encoding.getBase());
 192             }
 193             masm.addq(register, scratch);
 194         }
< prev index next >