# HG changeset patch # User Christos Kotselidis # Date 1377777145 -7200 # Node ID 95a56d151d27fdd11af79867a7491297cc860f36 # Parent dafee8e3eecd8ef99bcf90f6c631e225f9037d7b Rewrite compute block order function to be non-recursive due to stack overflow when G1 is used in eclipse diff -r dafee8e3eecd -r 95a56d151d27 graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java --- a/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java Wed Aug 28 15:22:51 2013 +0200 +++ b/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java Thu Aug 29 13:52:25 2013 +0200 @@ -152,39 +152,40 @@ /** * Add a linear path to the code emission order greedily following the most likely successor. */ - private static void addPathToCodeEmittingOrder(Block block, List order, PriorityQueue worklist, BitSet visitedBlocks, NodesToDoubles nodeProbabilities) { - - // Skip loop headers if there is only a single loop end block to make the backward jump be a - // conditional jump. - if (!skipLoopHeader(block)) { + private static void addPathToCodeEmittingOrder(Block initialBlock, List order, PriorityQueue worklist, BitSet visitedBlocks, NodesToDoubles nodeProbabilities) { + Block block = initialBlock; + while (block != null) { + // Skip loop headers if there is only a single loop end block to + // make the backward jump be a conditional jump. + if (!skipLoopHeader(block)) { - // Align unskipped loop headers as they are the target of the backward jump. - if (block.isLoopHeader()) { - block.setAlign(true); + // Align unskipped loop headers as they are the target of the backward jump. + if (block.isLoopHeader()) { + block.setAlign(true); + } + addBlock(block, order); } - addBlock(block, order); - } - Loop loop = block.getLoop(); - if (block.isLoopEnd() && skipLoopHeader(loop.header)) { + Loop loop = block.getLoop(); + if (block.isLoopEnd() && skipLoopHeader(loop.header)) { + + // This is the only loop end of a skipped loop header. + // Add the header immediately afterwards. + addBlock(loop.header, order); - // This is the only loop end of a skipped loop header. Add the header immediately - // afterwards. - addBlock(loop.header, order); - - // Make sure the loop successors of the loop header are aligned as they are the target - // of the backward jump. - for (Block successor : loop.header.getSuccessors()) { - if (successor.getLoopDepth() == block.getLoopDepth()) { - successor.setAlign(true); + // Make sure the loop successors of the loop header are aligned + // as they are the target + // of the backward jump. + for (Block successor : loop.header.getSuccessors()) { + if (successor.getLoopDepth() == block.getLoopDepth()) { + successor.setAlign(true); + } } } - } - Block mostLikelySuccessor = findAndMarkMostLikelySuccessor(block, visitedBlocks, nodeProbabilities); - enqueueSuccessors(block, worklist, visitedBlocks); - if (mostLikelySuccessor != null) { - addPathToCodeEmittingOrder(mostLikelySuccessor, order, worklist, visitedBlocks, nodeProbabilities); + Block mostLikelySuccessor = findAndMarkMostLikelySuccessor(block, visitedBlocks, nodeProbabilities); + enqueueSuccessors(block, worklist, visitedBlocks); + block = mostLikelySuccessor; } }