# HG changeset patch # User Thomas Wuerthinger # Date 1426259942 -3600 # Node ID 05a2fbf0e9a0f7e29114aaf77e5387f406c72cef # Parent 79d5fbcc6978e13830c580f52344ae9e83ea0953 Fix for FindBugs false positive. diff -r 79d5fbcc6978 -r 05a2fbf0e9a0 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Fri Mar 13 15:38:23 2015 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Fri Mar 13 16:19:02 2015 +0100 @@ -36,6 +36,8 @@ import com.oracle.graal.nodes.extended.*; import com.oracle.graal.phases.*; +import edu.umd.cs.findbugs.annotations.*; + public final class SchedulePhase extends Phase { /** @@ -110,69 +112,7 @@ latestBlockToNodesMap.put(b, new ArrayList()); } - BlockMap> watchListMap = null; - for (Block b : cfg.postOrder()) { - List blockToNodes = earliestBlockToNodesMap.get(b); - LocationSet killed = null; - int previousIndex = blockToNodes.size(); - for (int i = blockToNodes.size() - 1; i >= 0; --i) { - Node currentNode = blockToNodes.get(i); - assert currentNodeMap.get(currentNode) == b; - assert !(currentNode instanceof PhiNode) && !(currentNode instanceof ProxyNode); - assert visited.isMarked(currentNode); - if (currentNode instanceof FixedNode) { - // For these nodes, the earliest is at the same time the latest block. - } else { - Block currentBlock = b; - assert currentBlock != null; - Block latestBlock = calcLatestBlock(b, isOutOfLoops, currentNode, currentNodeMap); - assert AbstractControlFlowGraph.dominates(currentBlock, latestBlock) || currentNode instanceof VirtualState : currentNode + " " + currentBlock + " " + latestBlock; - if (latestBlock != currentBlock) { - if (currentNode instanceof FloatingReadNode) { - - FloatingReadNode floatingReadNode = (FloatingReadNode) currentNode; - LocationIdentity location = floatingReadNode.getLocationIdentity(); - if (location.isMutable()) { - if (currentBlock.canKill(location)) { - if (killed == null) { - killed = new LocationSet(); - } - fillKillSet(killed, blockToNodes.subList(i + 1, previousIndex)); - previousIndex = i; - if (killed.contains(location)) { - latestBlock = currentBlock; - } - } - - if (latestBlock != currentBlock) { - // We are not constraint within currentBlock. Check if - // we are contraint while walking down the dominator - // line. - Block newLatestBlock = adjustLatestForRead(currentBlock, latestBlock, location); - assert dominates(newLatestBlock, latestBlock); - assert dominates(currentBlock, newLatestBlock); - latestBlock = newLatestBlock; - - if (newLatestBlock != currentBlock && latestBlock.canKill(location)) { - if (watchListMap == null) { - watchListMap = new BlockMap<>(cfg); - } - if (watchListMap.get(latestBlock) == null) { - watchListMap.put(latestBlock, new ArrayList<>()); - } - watchListMap.get(latestBlock).add(floatingReadNode); - } - } - } - } - currentNodeMap.set(currentNode, latestBlock); - currentBlock = latestBlock; - } - latestBlockToNodesMap.get(currentBlock).add(currentNode); - } - } - } - + BlockMap> watchListMap = calcLatestBlocks(isOutOfLoops, currentNodeMap, earliestBlockToNodesMap, visited, latestBlockToNodesMap); sortNodesLatestWithinBlock(cfg, earliestBlockToNodesMap, latestBlockToNodesMap, currentNodeMap, watchListMap, visited); this.blockToNodesMap = latestBlockToNodesMap; @@ -184,6 +124,74 @@ } } + @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "false positive found by findbugs") + private BlockMap> calcLatestBlocks(boolean isOutOfLoops, NodeMap currentNodeMap, BlockMap> earliestBlockToNodesMap, NodeBitMap visited, + BlockMap> latestBlockToNodesMap) { + BlockMap> watchListMap = null; + for (Block b : cfg.postOrder()) { + List blockToNodes = earliestBlockToNodesMap.get(b); + LocationSet killed = null; + int previousIndex = blockToNodes.size(); + for (int i = blockToNodes.size() - 1; i >= 0; --i) { + Node currentNode = blockToNodes.get(i); + assert currentNodeMap.get(currentNode) == b; + assert !(currentNode instanceof PhiNode) && !(currentNode instanceof ProxyNode); + assert visited.isMarked(currentNode); + if (currentNode instanceof FixedNode) { + // For these nodes, the earliest is at the same time the latest block. + } else { + Block currentBlock = b; + assert currentBlock != null; + Block latestBlock = calcLatestBlock(b, isOutOfLoops, currentNode, currentNodeMap); + assert AbstractControlFlowGraph.dominates(currentBlock, latestBlock) || currentNode instanceof VirtualState : currentNode + " " + currentBlock + " " + latestBlock; + if (latestBlock != currentBlock) { + if (currentNode instanceof FloatingReadNode) { + + FloatingReadNode floatingReadNode = (FloatingReadNode) currentNode; + LocationIdentity location = floatingReadNode.getLocationIdentity(); + if (location.isMutable()) { + if (currentBlock.canKill(location)) { + if (killed == null) { + killed = new LocationSet(); + } + fillKillSet(killed, blockToNodes.subList(i + 1, previousIndex)); + previousIndex = i; + if (killed.contains(location)) { + latestBlock = currentBlock; + } + } + + if (latestBlock != currentBlock) { + // We are not constraint within currentBlock. Check if + // we are contraint while walking down the dominator + // line. + Block newLatestBlock = adjustLatestForRead(currentBlock, latestBlock, location); + assert dominates(newLatestBlock, latestBlock); + assert dominates(currentBlock, newLatestBlock); + latestBlock = newLatestBlock; + + if (newLatestBlock != currentBlock && latestBlock.canKill(location)) { + if (watchListMap == null) { + watchListMap = new BlockMap<>(cfg); + } + if (watchListMap.get(latestBlock) == null) { + watchListMap.put(latestBlock, new ArrayList<>()); + } + watchListMap.get(latestBlock).add(floatingReadNode); + } + } + } + } + currentNodeMap.set(currentNode, latestBlock); + currentBlock = latestBlock; + } + latestBlockToNodesMap.get(currentBlock).add(currentNode); + } + } + } + return watchListMap; + } + private static boolean verifySchedule(ControlFlowGraph cfg, BlockMap> blockToNodesMap, NodeMap nodeMap) { for (Block b : cfg.getBlocks()) { List nodes = blockToNodesMap.get(b);