changeset 18426:b2b37b36a254

Move freeSpillSlot() from FrameMap to ForwardingFrameMapBuilder.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 23 Oct 2014 17:48:46 +0200
parents b856446ff7e0
children 9bf59aa9d8c6
files graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMapBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ForwardingFrameMapBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMapBuilder.java
diffstat 5 files changed, 43 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;
     }
--- 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<VirtualStackSlot> freedSlots;
+
+    public VirtualStackSlot allocateSpillSlot(LIRKind kind) {
+        if (freedSlots != null) {
+            for (Iterator<VirtualStackSlot> 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<StackSlot> 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;
     }
--- 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<StackSlot> 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<StackSlot> 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}.
--- 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