1 /* 2 * Copyright (c) 2013, 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.lir.sparc; 24 25 import org.graalvm.compiler.core.common.LIRKind; 26 import org.graalvm.compiler.lir.framemap.FrameMap; 27 28 import jdk.vm.ci.code.CodeCacheProvider; 29 import jdk.vm.ci.code.RegisterConfig; 30 import jdk.vm.ci.code.StackSlot; 31 import jdk.vm.ci.meta.ValueKind; 32 import jdk.vm.ci.sparc.SPARC; 33 import jdk.vm.ci.sparc.SPARCKind; 34 35 /** 36 * SPARC specific frame map. 37 * 38 * This is the format of a SPARC stack frame: 39 * 40 * <pre> 41 * Base Contents 42 * : : ----- 43 * caller | incoming overflow argument n | ^ 44 * frame : ... : | positive 45 * | incoming overflow argument 0 | | offsets 46 * +--------------------------------+ | 47 * | | | 48 * : register save area : | 49 * | | | 50 * ---------+--------------------------------+--------------------------- 51 * | spill slot 0 | | negative ^ ^ 52 * : ... : v offsets | | 53 * | spill slot n | ----- total | 54 * +--------------------------------+ frame | 55 * current | alignment padding | size | 56 * frame +--------------------------------+ ----- | | 57 * | outgoing overflow argument n | ^ | frame 58 * : ... : | positive | size 59 * | outgoing overflow argument 0 | | offsets | | 60 * +--------------------------------+ | | | 61 * | return address | | | | 62 * +--------------------------------+ | | | 63 * | | | | | 64 * : callee save area : | | | 65 * | | | v v 66 * %sp--> +--------------------------------+--------------------------- 67 * 68 * </pre> 69 * 70 * The spill slot area also includes stack allocated memory blocks (ALLOCA blocks). The size of such 71 * a block may be greater than the size of a normal spill slot or the word size. 72 * <p> 73 * A runtime can reserve space at the beginning of the overflow argument area. The calling 74 * convention can specify that the first overflow stack argument is not at offset 0, but at a 75 * specified offset. Use {@link CodeCacheProvider#getMinimumOutgoingSize()} to make sure that 76 * call-free methods also have this space reserved. Then the VM can use the memory at offset 0 77 * relative to the stack pointer. 78 */ 79 public final class SPARCFrameMap extends FrameMap { 80 81 public SPARCFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig, ReferenceMapBuilderFactory referenceMapFactory) { 82 super(codeCache, registerConfig, referenceMapFactory); 83 // Initial spill size is set to register save area size (SPARC register window) 84 initialSpillSize = 0; 85 spillSize = initialSpillSize; 86 } 87 88 @Override 89 public int totalFrameSize() { 90 return frameSize(); 91 } 92 93 @Override 94 public int currentFrameSize() { 95 return alignFrameSize(SPARC.REGISTER_SAFE_AREA_SIZE + outgoingSize + spillSize); 96 } 97 98 /** 99 * In SPARC we have spill slots word aligned. 100 */ 101 @Override 102 public int spillSlotSize(ValueKind<?> kind) { 103 return kind.getPlatformKind().getSizeInBytes(); 104 } 105 106 @Override 107 public int offsetForStackSlot(StackSlot slot) { 108 // @formatter:off 109 assert (!slot.getRawAddFrameSize() && slot.getRawOffset() < outgoingSize + SPARC.REGISTER_SAFE_AREA_SIZE) || 110 (slot.getRawAddFrameSize() && slot.getRawOffset() < 0 && -slot.getRawOffset() <= spillSize) || 111 (slot.getRawAddFrameSize() && slot.getRawOffset() >= 0) : 112 String.format("RawAddFrameSize: %b RawOffset: 0x%x spillSize: 0x%x outgoingSize: 0x%x", slot.getRawAddFrameSize(), slot.getRawOffset(), spillSize, outgoingSize); 113 // @formatter:on 114 return super.offsetForStackSlot(slot); 115 } 116 117 @Override 118 public boolean frameNeedsAllocating() { 119 return super.frameNeedsAllocating() || spillSize > 0; 120 } 121 122 public StackSlot allocateDeoptimizationRescueSlot() { 123 assert spillSize == initialSpillSize : "Deoptimization rescue slot must be the first stack slot"; 124 return allocateSpillSlot(LIRKind.value(SPARCKind.XWORD)); 125 } 126 }