Mercurial > hg > graal-jvmci-8
view graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java @ 5547:b6617d13ea44
Dropping Ci* prefixes. Some additional renamings in the api.code interface.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 09 Jun 2012 20:10:05 +0200 |
parents | e42c0df7212a |
children | 141b15521a39 |
line wrap: on
line source
/* * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.lir.amd64; import static com.oracle.graal.api.code.ValueUtil.*; import java.util.*; import com.oracle.max.asm.target.amd64.*; import com.oracle.max.cri.xir.CiXirAssembler.XirMark; import com.oracle.graal.api.code.*; import com.oracle.graal.api.code.CompilationResult.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; public class AMD64Call { public static class DirectCallOp extends AMD64LIRInstruction implements StandardOp.CallOp { private final Object targetMethod; private final Map<XirMark, Mark> marks; public DirectCallOp(Object targetMethod, Value result, Value[] parameters, LIRDebugInfo info, Map<XirMark, Mark> marks) { super("CALL_DIRECT", new Value[] {result}, info, parameters, LIRInstruction.NO_OPERANDS, LIRInstruction.NO_OPERANDS); this.targetMethod = targetMethod; this.marks = marks; } @Override public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { callAlignment(tasm, masm); if (marks != null) { marks.put(XirMark.CALLSITE, tasm.recordMark(null, new Mark[0])); } directCall(tasm, masm, targetMethod, info); } @Override protected EnumSet<OperandFlag> flagsFor(OperandMode mode, int index) { if (mode == OperandMode.Input) { return EnumSet.of(OperandFlag.Register, OperandFlag.Stack); } else if (mode == OperandMode.Output) { return EnumSet.of(OperandFlag.Register, OperandFlag.Illegal); } throw GraalInternalError.shouldNotReachHere(); } } public static class IndirectCallOp extends AMD64LIRInstruction implements StandardOp.CallOp { private final Object targetMethod; private final Map<XirMark, Mark> marks; private static Value[] concat(Value[] parameters, Value targetAddress) { Value[] result = Arrays.copyOf(parameters, parameters.length + 1); result[result.length - 1] = targetAddress; return result; } public IndirectCallOp(Object targetMethod, Value result, Value[] parameters, Value targetAddress, LIRDebugInfo info, Map<XirMark, Mark> marks) { super("CALL_INDIRECT", new Value[] {result}, info, concat(parameters, targetAddress), LIRInstruction.NO_OPERANDS, LIRInstruction.NO_OPERANDS); this.targetMethod = targetMethod; this.marks = marks; } private Value targetAddress() { return input(inputs.length - 1); } @Override public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { callAlignment(tasm, masm); if (marks != null) { marks.put(XirMark.CALLSITE, tasm.recordMark(null, new Mark[0])); } indirectCall(tasm, masm, asRegister(targetAddress()), targetMethod, info); } @Override protected EnumSet<OperandFlag> flagsFor(OperandMode mode, int index) { if (mode == OperandMode.Input) { return EnumSet.of(OperandFlag.Register, OperandFlag.Stack); } else if (mode == OperandMode.Output) { return EnumSet.of(OperandFlag.Register, OperandFlag.Illegal); } throw GraalInternalError.shouldNotReachHere(); } } public static void callAlignment(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { // make sure that the displacement word of the call ends up word aligned int offset = masm.codeBuffer.position(); offset += tasm.target.arch.machineCodeCallDisplacementOffset; while (offset++ % tasm.target.wordSize != 0) { masm.nop(); } } public static void directCall(TargetMethodAssembler tasm, AMD64MacroAssembler masm, Object target, LIRDebugInfo info) { int before = masm.codeBuffer.position(); if (target instanceof RuntimeCall) { long maxOffset = tasm.runtime.getMaxCallTargetOffset((RuntimeCall) target); if (maxOffset != (int) maxOffset) { // offset might not fit a 32-bit immediate, generate an // indirect call with a 64-bit immediate Register scratch = tasm.frameMap.registerConfig.getScratchRegister(); // TODO (cwimmer): we want to get rid of a generally reserved scratch register. masm.movq(scratch, 0L); masm.call(scratch); } else { masm.call(); } } else { masm.call(); } int after = masm.codeBuffer.position(); tasm.recordDirectCall(before, after, tasm.runtime.asCallTarget(target), info); tasm.recordExceptionHandlers(after, info); masm.ensureUniquePC(); } public static void directJmp(TargetMethodAssembler tasm, AMD64MacroAssembler masm, Object target) { int before = masm.codeBuffer.position(); masm.jmp(0, true); int after = masm.codeBuffer.position(); tasm.recordDirectCall(before, after, tasm.runtime.asCallTarget(target), null); masm.ensureUniquePC(); } public static void indirectCall(TargetMethodAssembler tasm, AMD64MacroAssembler masm, Register dst, Object target, LIRDebugInfo info) { int before = masm.codeBuffer.position(); masm.call(dst); int after = masm.codeBuffer.position(); tasm.recordIndirectCall(before, after, tasm.runtime.asCallTarget(target), info); tasm.recordExceptionHandlers(after, info); masm.ensureUniquePC(); } public static void shouldNotReachHere(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { boolean assertions = false; assert (assertions = true) == true; if (assertions) { directCall(tasm, masm, RuntimeCall.Debug, null); masm.hlt(); } } }