001/*
002 * Copyright (c) 2012, 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.amd64.*;
026import jdk.internal.jvmci.code.*;
027import jdk.internal.jvmci.hotspot.*;
028import jdk.internal.jvmci.meta.*;
029import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
030import static jdk.internal.jvmci.code.ValueUtil.*;
031
032import com.oracle.graal.asm.amd64.*;
033import com.oracle.graal.lir.*;
034import com.oracle.graal.lir.amd64.*;
035import com.oracle.graal.lir.amd64.AMD64Call.IndirectCallOp;
036import com.oracle.graal.lir.asm.*;
037
038/**
039 * A register indirect call that complies with the extra conventions for such calls in HotSpot. In
040 * particular, the metaspace Method of the callee must be in RBX for the case where a vtable entry's
041 * _from_compiled_entry is the address of an C2I adapter. Such adapters expect the target method to
042 * be in RBX.
043 */
044@Opcode("CALL_INDIRECT")
045final class AMD64IndirectCallOp extends IndirectCallOp {
046    public static final LIRInstructionClass<AMD64IndirectCallOp> TYPE = LIRInstructionClass.create(AMD64IndirectCallOp.class);
047
048    /**
049     * Vtable stubs expect the metaspace Method in RBX.
050     */
051    public static final Register METHOD = AMD64.rbx;
052
053    @Use({REG}) protected Value metaspaceMethod;
054
055    private final HotSpotVMConfig config;
056
057    AMD64IndirectCallOp(ResolvedJavaMethod targetMethod, Value result, Value[] parameters, Value[] temps, Value metaspaceMethod, Value targetAddress, LIRFrameState state, HotSpotVMConfig config) {
058        super(TYPE, targetMethod, result, parameters, temps, targetAddress, state);
059        this.metaspaceMethod = metaspaceMethod;
060        this.config = config;
061    }
062
063    @Override
064    public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
065        crb.recordMark(config.MARKID_INLINE_INVOKE);
066        Register callReg = asRegister(targetAddress);
067        assert !callReg.equals(METHOD);
068        AMD64Call.indirectCall(crb, masm, callReg, callTarget, state);
069    }
070
071    @Override
072    public void verify() {
073        super.verify();
074        assert asRegister(metaspaceMethod).equals(METHOD);
075    }
076}