# HG changeset patch # User Josef Eisl # Date 1422715914 -3600 # Node ID 684612ee6abbaf52e57fbcbf088c3add7df78446 # Parent d367ad9138f8703e06636d187b7bb3c0dbdda806 LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc. diff -r d367ad9138f8 -r 684612ee6abb graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Sat Jan 31 15:05:26 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java Sat Jan 31 15:51:54 2015 +0100 @@ -233,36 +233,75 @@ } } - private EnumMap> freeSlots = new EnumMap<>(SlotSize.class); + private EnumMap> freeSlots; + + /** + * @return The list of free stack slots for {@code size} or {@code null} if there is none. + */ + private Deque getOrNullFreeSlots(SlotSize size) { + if (freeSlots == null) { + return null; + } + return freeSlots.get(size); + } + /** + * @return the list of free stack slots for {@code size}. If there is none a list is + * created. + */ + private Deque getOrInitFreeSlots(SlotSize size) { + assert size != SlotSize.Illegal; + Deque freeList; + if (freeSlots != null) { + freeList = freeSlots.get(size); + } else { + freeSlots = new EnumMap<>(SlotSize.class); + freeList = null; + } + if (freeList == null) { + freeList = new ArrayDeque<>(); + freeSlots.put(size, freeList); + } + assert freeList != null; + return freeList; + } + + /** + * Gets a free stack slot for {@code slot} or {@code null} if there is none. + */ private StackSlot findFreeSlot(SimpleVirtualStackSlot slot) { assert slot != null; SlotSize size = forKind(slot.getLIRKind()); - LinkedList freeList = size == SlotSize.Illegal ? null : freeSlots.get(size); + if (size == SlotSize.Illegal) { + return null; + } + Deque freeList = getOrNullFreeSlots(size); if (freeList == null) { return null; } - return freeList.pollFirst(); + return freeList.pollLast(); } + /** + * Adds a stack slot to the list of free slots. + */ private void freeSlot(StackSlot slot) { SlotSize size = forKind(slot.getLIRKind()); if (size == SlotSize.Illegal) { return; } - LinkedList freeList = freeSlots.get(size); - if (freeList == null) { - freeList = new LinkedList<>(); - freeSlots.put(size, freeList); - } - freeList.add(slot); + getOrInitFreeSlots(size).addLast(slot); } + /** + * Gets the next unhandled interval and finishes handled intervals. + */ private StackInterval activateNext() { if (unhandled.isEmpty()) { return null; } StackInterval next = unhandled.poll(); + // finish handled intervals for (int id = next.from(); activePeekId() < id;) { finished(active.poll()); } @@ -271,6 +310,10 @@ return next; } + /** + * Gets the lowest {@link StackInterval#to() end position} of all active intervals. If there + * is none {@link Integer#MAX_VALUE} is returned. + */ private int activePeekId() { StackInterval first = active.peek(); if (first == null) { @@ -279,6 +322,9 @@ return first.to(); } + /** + * Finishes {@code interval} by adding its location to the list of free stack slots. + */ private void finished(StackInterval interval) { StackSlot location = interval.location(); Debug.log("finished %s (freeing %s)", interval, location); @@ -323,7 +369,7 @@ // ==================== /** - * Gets the highest instruction id allocated by this object. + * Gets the highest instruction id. */ private int maxOpId() { return maxOpId;