001/*
002 * Copyright (c) 2014, 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.sparc;
024
025import jdk.internal.jvmci.code.*;
026import static jdk.internal.jvmci.sparc.SPARC.*;
027
028import com.oracle.graal.asm.sparc.*;
029import com.oracle.graal.hotspot.*;
030import com.oracle.graal.lir.*;
031import com.oracle.graal.lir.asm.*;
032import com.oracle.graal.lir.sparc.*;
033
034/**
035 * Emits code that leaves a stack frame which is tailored to call the C++ method
036 * {@link HotSpotBackend#UNPACK_FRAMES Deoptimization::unpack_frames}.
037 */
038@Opcode("LEAVE_UNPACK_FRAMES_STACK_FRAME")
039final class SPARCHotSpotLeaveUnpackFramesStackFrameOp extends SPARCLIRInstruction {
040    public static final LIRInstructionClass<SPARCHotSpotLeaveUnpackFramesStackFrameOp> TYPE = LIRInstructionClass.create(SPARCHotSpotLeaveUnpackFramesStackFrameOp.class);
041
042    private final Register thread;
043    private final int threadLastJavaSpOffset;
044    private final int threadLastJavaPcOffset;
045    private final int threadJavaFrameAnchorFlagsOffset;
046
047    SPARCHotSpotLeaveUnpackFramesStackFrameOp(Register thread, int threadLastJavaSpOffset, int threadLastJavaPcOffset, int threadJavaFrameAnchorFlagsOffset) {
048        super(TYPE);
049        this.thread = thread;
050        this.threadLastJavaSpOffset = threadLastJavaSpOffset;
051        this.threadLastJavaPcOffset = threadLastJavaPcOffset;
052        this.threadJavaFrameAnchorFlagsOffset = threadJavaFrameAnchorFlagsOffset;
053    }
054
055    @Override
056    public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
057        /*
058         * Safe thread register manually since we are not using LEAF_SP for {@link
059         * DeoptimizationStub#UNPACK_FRAMES}.
060         */
061        masm.mov(l7, thread);
062
063        SPARCAddress lastJavaPc = new SPARCAddress(thread, threadLastJavaPcOffset);
064
065        // We borrow the threads lastJavaPC to transfer the value from float to i0
066        masm.stdf(SPARCSaveRegistersOp.RETURN_REGISTER_STORAGE, lastJavaPc);
067        masm.ldx(lastJavaPc, i0);
068
069        // Clear last Java frame values.
070        masm.stx(g0, lastJavaPc);
071        masm.stx(g0, new SPARCAddress(thread, threadLastJavaSpOffset));
072        masm.stw(g0, new SPARCAddress(thread, threadJavaFrameAnchorFlagsOffset));
073    }
074}