001/*
002 * Copyright (c) 2012, 2013, 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.sparc;
024
025import jdk.internal.jvmci.code.*;
026import jdk.internal.jvmci.hotspot.*;
027import jdk.internal.jvmci.meta.*;
028import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
029import static jdk.internal.jvmci.code.ValueUtil.*;
030import static jdk.internal.jvmci.sparc.SPARC.*;
031
032import com.oracle.graal.asm.sparc.*;
033import com.oracle.graal.lir.*;
034import com.oracle.graal.lir.asm.*;
035import com.oracle.graal.lir.sparc.*;
036import com.oracle.graal.lir.sparc.SPARCCall.IndirectCallOp;
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 g5 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 g5.
043 */
044@Opcode("CALL_INDIRECT")
045final class SPARCIndirectCallOp extends IndirectCallOp {
046    public static final LIRInstructionClass<SPARCIndirectCallOp> TYPE = LIRInstructionClass.create(SPARCIndirectCallOp.class);
047    public static final SizeEstimate SIZE = SizeEstimate.create(2);
048
049    /**
050     * Vtable stubs expect the metaspace Method in g5.
051     */
052    public static final Register METHOD = g5;
053
054    @Use({REG}) protected Value metaspaceMethod;
055
056    private final HotSpotVMConfig config;
057
058    SPARCIndirectCallOp(ResolvedJavaMethod targetMethod, Value result, Value[] parameters, Value[] temps, Value metaspaceMethod, Value targetAddress, LIRFrameState state, HotSpotVMConfig config) {
059        super(TYPE, SIZE, targetMethod, result, parameters, temps, targetAddress, state);
060        this.metaspaceMethod = metaspaceMethod;
061        this.config = config;
062    }
063
064    @Override
065    public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
066        crb.recordMark(config.MARKID_INLINE_INVOKE);
067        Register callReg = asRegister(targetAddress);
068        assert !callReg.equals(METHOD);
069        SPARCCall.indirectCall(crb, masm, callReg, callTarget, state);
070    }
071
072    @Override
073    public void verify() {
074        super.verify();
075        assert asRegister(metaspaceMethod).equals(METHOD);
076    }
077}