1 /* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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.sparc; 24 25 import static jdk.vm.ci.sparc.SPARC.g0; 26 import static jdk.vm.ci.sparc.SPARC.i0; 27 import static jdk.vm.ci.sparc.SPARC.l7; 28 29 import org.graalvm.compiler.asm.sparc.SPARCAddress; 30 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler; 31 import org.graalvm.compiler.hotspot.HotSpotBackend; 32 import org.graalvm.compiler.lir.LIRInstructionClass; 33 import org.graalvm.compiler.lir.Opcode; 34 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 35 import org.graalvm.compiler.lir.sparc.SPARCLIRInstruction; 36 import org.graalvm.compiler.lir.sparc.SPARCSaveRegistersOp; 37 38 import jdk.vm.ci.code.Register; 39 40 /** 41 * Emits code that leaves a stack frame which is tailored to call the C++ method 42 * {@link HotSpotBackend#UNPACK_FRAMES Deoptimization::unpack_frames}. 43 */ 44 @Opcode("LEAVE_UNPACK_FRAMES_STACK_FRAME") 45 final class SPARCHotSpotLeaveUnpackFramesStackFrameOp extends SPARCLIRInstruction { 46 public static final LIRInstructionClass<SPARCHotSpotLeaveUnpackFramesStackFrameOp> TYPE = LIRInstructionClass.create(SPARCHotSpotLeaveUnpackFramesStackFrameOp.class); 47 48 private final Register thread; 49 private final int threadLastJavaSpOffset; 50 private final int threadLastJavaPcOffset; 51 private final int threadJavaFrameAnchorFlagsOffset; 52 53 SPARCHotSpotLeaveUnpackFramesStackFrameOp(Register thread, int threadLastJavaSpOffset, int threadLastJavaPcOffset, int threadJavaFrameAnchorFlagsOffset) { 54 super(TYPE); 55 this.thread = thread; 56 this.threadLastJavaSpOffset = threadLastJavaSpOffset; 57 this.threadLastJavaPcOffset = threadLastJavaPcOffset; 58 this.threadJavaFrameAnchorFlagsOffset = threadJavaFrameAnchorFlagsOffset; 59 } 60 61 @Override 62 public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 63 /* 64 * Safe thread register manually since we are not using LEAF_SP for {@link 65 * DeoptimizationStub#UNPACK_FRAMES}. 66 */ 67 masm.mov(l7, thread); 68 69 SPARCAddress lastJavaPc = new SPARCAddress(thread, threadLastJavaPcOffset); 70 71 // We borrow the threads lastJavaPC to transfer the value from float to i0 72 masm.stdf(SPARCSaveRegistersOp.RETURN_REGISTER_STORAGE, lastJavaPc); 73 masm.ldx(lastJavaPc, i0); 74 75 // Clear last Java frame values. 76 masm.stx(g0, lastJavaPc); 77 masm.stx(g0, new SPARCAddress(thread, threadLastJavaSpOffset)); 78 masm.stw(g0, new SPARCAddress(thread, threadJavaFrameAnchorFlagsOffset)); 79 } 80 }