# HG changeset patch # User Josef Eisl # Date 1414079326 -7200 # Node ID b2b37b36a25473f2411f76f74a8bc9080352335f # Parent b856446ff7e08f58b650c4cc17a8151c17e457fb Move freeSpillSlot() from FrameMap to ForwardingFrameMapBuilder. diff -r b856446ff7e0 -r b2b37b36a254 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 23 14:55:04 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 23 17:48:46 2014 +0200 @@ -88,7 +88,7 @@ /** * The slot reserved for saving RBP. */ - final StackSlotValue reservedSlot; + final VirtualStackSlot reservedSlot; public SaveRbp(NoOp placeholder) { this.placeholder = placeholder; diff -r b856446ff7e0 -r b2b37b36a254 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMapBuilder.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMapBuilder.java Thu Oct 23 14:55:04 2014 +0200 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMapBuilder.java Thu Oct 23 17:48:46 2014 +0200 @@ -38,8 +38,8 @@ * For non-leaf methods, RBP is preserved in the special stack slot required by the HotSpot * runtime for walking/inspecting frames of such methods. */ - public StackSlotValue allocateRBPSpillSlot() { - StackSlotValue reservedSlot = allocateSpillSlot(LIRKind.value(Kind.Long)); + public VirtualStackSlot allocateRBPSpillSlot() { + VirtualStackSlot reservedSlot = allocateSpillSlot(LIRKind.value(Kind.Long)); assert asStackSlot(reservedSlot).getRawOffset() == -16 : asStackSlot(reservedSlot).getRawOffset(); return reservedSlot; } diff -r b856446ff7e0 -r b2b37b36a254 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ForwardingFrameMapBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ForwardingFrameMapBuilder.java Thu Oct 23 14:55:04 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ForwardingFrameMapBuilder.java Thu Oct 23 17:48:46 2014 +0200 @@ -22,12 +22,11 @@ */ package com.oracle.graal.lir; -import static com.oracle.graal.api.code.ValueUtil.*; - import java.util.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.*; import com.oracle.graal.lir.gen.*; /** @@ -51,8 +50,24 @@ this.frameMap = factory.newFrameMap(this); } - public StackSlot allocateSpillSlot(LIRKind kind) { - return frameMap.allocateSpillSlot(kind); + private Set freedSlots; + + public VirtualStackSlot allocateSpillSlot(LIRKind kind) { + if (freedSlots != null) { + for (Iterator iter = freedSlots.iterator(); iter.hasNext();) { + VirtualStackSlot s = iter.next(); + if (s.getLIRKind().equals(kind)) { + iter.remove(); + if (freedSlots.isEmpty()) { + freedSlots = null; + } + return s; + } + } + } + int size = frameMap.spillSlotSize(kind); + frameMap.spillSize = NumUtil.roundUp(frameMap.spillSize + size, size); + return frameMap.allocateNewSpillSlot(kind, 0); } public StackSlot allocateStackSlots(int slots, BitSet objects, List outObjectStackSlots) { @@ -67,8 +82,11 @@ return codeCache; } - public void freeSpillSlot(StackSlotValue slot) { - frameMap.freeSpillSlot(asStackSlot(slot)); + public void freeSpillSlot(VirtualStackSlot slot) { + if (freedSlots == null) { + freedSlots = new HashSet<>(); + } + freedSlots.add(slot); } public void callsMethod(CallingConvention cc) { @@ -76,6 +94,20 @@ } public FrameMap buildFrameMap(LIRGenerationResult res) { + if (freedSlots != null) { + // If the freed slots cover the complete spill area (except for the return + // address slot), then the spill size is reset to its initial value. + // Without this, frameNeedsAllocating() would never return true. + int total = 0; + for (VirtualStackSlot s : freedSlots) { + total += frameMap.getTarget().getSizeInBytes(s.getKind()); + } + if (total == frameMap.spillSize - frameMap.initialSpillSize) { + // reset spill area size + frameMap.spillSize = frameMap.initialSpillSize; + } + freedSlots = null; + } frameMap.finish(); return frameMap; } diff -r b856446ff7e0 -r b2b37b36a254 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Thu Oct 23 14:55:04 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Thu Oct 23 17:48:46 2014 +0200 @@ -172,21 +172,6 @@ * be requested. */ public void finish() { - assert this.frameSize == -1 : "must only be set once"; - if (freedSlots != null) { - // If the freed slots cover the complete spill area (except for the return - // address slot), then the spill size is reset to its initial value. - // Without this, frameNeedsAllocating() would never return true. - int total = 0; - for (StackSlot s : freedSlots) { - total += getTarget().getSizeInBytes(s.getKind()); - } - if (total == spillSize - initialSpillSize) { - // reset spill area size - spillSize = initialSpillSize; - } - freedSlots = null; - } frameSize = currentFrameSize(); if (frameSize > getRegisterConfig().getMaximumFrameSize()) { throw new BailoutException("Frame size (%d) exceeded maximum allowed frame size (%d).", frameSize, getRegisterConfig().getMaximumFrameSize()); @@ -271,38 +256,13 @@ * @param kind The kind of the spill slot to be reserved. * @return A spill slot denoting the reserved memory area. */ - public StackSlot allocateSpillSlot(LIRKind kind) { + protected StackSlot allocateSpillSlot(LIRKind kind) { assert frameSize == -1 : "frame size must not yet be fixed"; - if (freedSlots != null) { - for (Iterator iter = freedSlots.iterator(); iter.hasNext();) { - StackSlot s = iter.next(); - if (s.getLIRKind().equals(kind)) { - iter.remove(); - if (freedSlots.isEmpty()) { - freedSlots = null; - } - return s; - } - } - } int size = spillSlotSize(kind); spillSize = NumUtil.roundUp(spillSize + size, size); return allocateNewSpillSlot(kind, 0); } - private Set freedSlots; - - /** - * Frees a spill slot that was obtained via {@link #allocateSpillSlot(LIRKind)} such that it can - * be reused for the next allocation request for the same kind of slot. - */ - public void freeSpillSlot(StackSlot slot) { - if (freedSlots == null) { - freedSlots = new HashSet<>(); - } - freedSlots.add(slot); - } - /** * Reserves a number of contiguous slots in the frame of the method being compiled. If the * requested number of slots is 0, this method returns {@code null}. diff -r b856446ff7e0 -r b2b37b36a254 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMapBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMapBuilder.java Thu Oct 23 14:55:04 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMapBuilder.java Thu Oct 23 17:48:46 2014 +0200 @@ -67,7 +67,7 @@ * Frees a spill slot that was obtained via {@link #allocateSpillSlot(LIRKind)} such that it can * be reused for the next allocation request for the same kind of slot. */ - void freeSpillSlot(StackSlotValue reservedSlot); + void freeSpillSlot(VirtualStackSlot reservedSlot); /** * Informs the frame map that the compiled code calls a particular method, which may need stack