# HG changeset patch # User Thomas Wuerthinger # Date 1424281716 -3600 # Node ID 13d2019e24f163e7c1417417bdbb8cf458a0879f # Parent 625633886e255ef18d3d4736616a39db9eb09494 Move mutable parts of BciBlock to BytecodeParser. diff -r 625633886e25 -r 13d2019e24f1 graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Wed Feb 18 18:36:11 2015 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Wed Feb 18 18:48:36 2015 +0100 @@ -32,7 +32,6 @@ import com.oracle.graal.bytecode.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; -import com.oracle.graal.nodes.*; /** * Builds a mapping between bytecodes and basic blocks and builds a conservative control flow graph @@ -85,11 +84,6 @@ protected List successors; private int predecessorCount; - private FixedWithNextNode firstInstruction; - private AbstractFrameStateBuilder entryState; - private FixedWithNextNode[] firstInstructionArray; - private AbstractFrameStateBuilder[] entryStateArray; - private boolean visited; private boolean active; public long loops; @@ -324,66 +318,6 @@ this.getOrCreateJSRData().jsrReturnBci = bci; } - public FixedWithNextNode getFirstInstruction(int dimension) { - if (dimension == 0) { - return firstInstruction; - } else { - if (firstInstructionArray != null && dimension - 1 < firstInstructionArray.length) { - return firstInstructionArray[dimension - 1]; - } else { - return null; - } - } - } - - public void setFirstInstruction(int dimension, FixedWithNextNode firstInstruction) { - if (dimension == 0) { - this.firstInstruction = firstInstruction; - } else { - if (firstInstructionArray == null) { - firstInstructionArray = new FixedWithNextNode[4]; - } - if (dimension - 1 < firstInstructionArray.length) { - // We are within bounds. - } else { - // We are out of bounds. - firstInstructionArray = Arrays.copyOf(firstInstructionArray, Math.max(firstInstructionArray.length * 2, dimension)); - } - - firstInstructionArray[dimension - 1] = firstInstruction; - } - } - - public AbstractFrameStateBuilder getEntryState(int dimension) { - if (dimension == 0) { - return entryState; - } else { - if (entryStateArray != null && dimension - 1 < entryStateArray.length) { - return entryStateArray[dimension - 1]; - } else { - return null; - } - } - } - - public void setEntryState(int dimension, AbstractFrameStateBuilder entryState) { - if (dimension == 0) { - this.entryState = entryState; - } else { - if (entryStateArray == null) { - entryStateArray = new AbstractFrameStateBuilder[4]; - } - if (dimension - 1 < entryStateArray.length) { - // We are within bounds. - } else { - // We are out of bounds. - entryStateArray = Arrays.copyOf(entryStateArray, Math.max(entryStateArray.length * 2, dimension)); - } - - entryStateArray[dimension - 1] = entryState; - } - } - public int getSuccessorCount() { return successors.size(); } @@ -1060,4 +994,8 @@ public int getLoopCount() { return nextLoop; } + + public int getBlockCount() { + return blocks.length; + } } diff -r 625633886e25 -r 13d2019e24f1 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Feb 18 18:36:11 2015 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Feb 18 18:48:36 2015 +0100 @@ -195,6 +195,11 @@ private int nextPeelIteration = 1; private boolean controlFlowSplit; + private FixedWithNextNode[] firstInstruction; + private AbstractFrameStateBuilder[] entryState; + private FixedWithNextNode[][] firstInstructionArray; + private AbstractFrameStateBuilder[][] entryStateArray; + /** * @param isReplacement specifies if this object is being used to parse a method that * implements the semantics of another method (i.e., an intrinsic) or @@ -245,6 +250,8 @@ // compute the block map, setup exception handlers and get the entrypoint(s) this.blockMap = BciBlockMapping.create(stream, method); + this.firstInstruction = new FixedWithNextNode[blockMap.getBlockCount()]; + this.entryState = new AbstractFrameStateBuilder[blockMap.getBlockCount()]; if (graphBuilderConfig.doLivenessAnalysis()) { try (Scope s = Debug.scope("LivenessAnalysis")) { @@ -1211,16 +1218,80 @@ return new Target(target, state); } - private void setEntryState(BciBlock block, int operatingDimension, AbstractFrameStateBuilder entryState) { - block.setEntryState(operatingDimension, entryState); + private AbstractFrameStateBuilder getEntryState(BciBlock block, int dimension) { + int id = block.id; + if (dimension == 0) { + return entryState[id]; + } else { + if (entryStateArray != null && dimension - 1 < entryStateArray.length) { + AbstractFrameStateBuilder[] entryStateArrayEntry = entryStateArray[dimension - 1]; + if (entryStateArrayEntry == null) { + return null; + } + return entryStateArrayEntry[id]; + } else { + return null; + } + } } - private void setFirstInstruction(BciBlock block, int operatingDimension, FixedWithNextNode firstInstruction) { - block.setFirstInstruction(operatingDimension, firstInstruction); + private void setEntryState(BciBlock block, int dimension, AbstractFrameStateBuilder entryState) { + int id = block.id; + if (dimension == 0) { + this.entryState[id] = entryState; + } else { + if (entryStateArray == null) { + entryStateArray = new AbstractFrameStateBuilder[4][]; + } + if (dimension - 1 < entryStateArray.length) { + // We are within bounds. + } else { + // We are out of bounds. + entryStateArray = Arrays.copyOf(entryStateArray, Math.max(entryStateArray.length * 2, dimension)); + } + if (entryStateArray[dimension - 1] == null) { + entryStateArray[dimension - 1] = new AbstractFrameStateBuilder[blockMap.getBlockCount()]; + } + entryStateArray[dimension - 1][id] = entryState; + } + } + + private void setFirstInstruction(BciBlock block, int dimension, FixedWithNextNode firstInstruction) { + int id = block.id; + if (dimension == 0) { + this.firstInstruction[id] = firstInstruction; + } else { + if (firstInstructionArray == null) { + firstInstructionArray = new FixedWithNextNode[4][]; + } + if (dimension - 1 < firstInstructionArray.length) { + // We are within bounds. + } else { + // We are out of bounds. + firstInstructionArray = Arrays.copyOf(firstInstructionArray, Math.max(firstInstructionArray.length * 2, dimension)); + } + if (firstInstructionArray[dimension - 1] == null) { + firstInstructionArray[dimension - 1] = new FixedWithNextNode[blockMap.getBlockCount()]; + } + firstInstructionArray[dimension - 1][id] = firstInstruction; + } } private FixedWithNextNode getFirstInstruction(BciBlock block, int dimension) { - return block.getFirstInstruction(dimension); + int id = block.id; + if (dimension == 0) { + return firstInstruction[id]; + } else { + if (firstInstructionArray != null && dimension - 1 < firstInstructionArray.length) { + FixedWithNextNode[] firstInstructionArrayEntry = firstInstructionArray[dimension - 1]; + if (firstInstructionArrayEntry == null) { + return null; + } + return firstInstructionArrayEntry[id]; + } else { + return null; + } + } } private FixedNode createTarget(double probability, BciBlock block, HIRFrameStateBuilder stateAfter) { @@ -1259,9 +1330,9 @@ targetNode = getFirstInstruction(block, operatingDimension); Target target = checkLoopExit(targetNode, block, state); FixedNode result = target.fixed; - AbstractFrameStateBuilder entryState = target.state == state ? state.copy() : target.state; - setEntryState(block, operatingDimension, entryState); - entryState.clearNonLiveLocals(block, liveness, true); + AbstractFrameStateBuilder currentEntryState = target.state == state ? state.copy() : target.state; + setEntryState(block, operatingDimension, currentEntryState); + currentEntryState.clearNonLiveLocals(block, liveness, true); Debug.log("createTarget %s: first visit, result: %s", block, targetNode); return result; @@ -1329,10 +1400,6 @@ return result; } - private AbstractFrameStateBuilder getEntryState(BciBlock block, int operatingDimension) { - return block.getEntryState(operatingDimension); - } - private int findOperatingDimension(BciBlock block) { if (this.explodeLoops && this.explodeLoopsContext != null && !this.explodeLoopsContext.isEmpty()) { return findOperatingDimensionWithLoopExplosion(block); @@ -1396,7 +1463,7 @@ Debug.log("Ignoring block %s", block); return; } - try (Indent indent = Debug.logAndIndent("Parsing block %s firstInstruction: %s loopHeader: %b", block, block.getFirstInstruction(this.getCurrentDimension()), block.isLoopHeader)) { + try (Indent indent = Debug.logAndIndent("Parsing block %s firstInstruction: %s loopHeader: %b", block, getFirstInstruction(block, this.getCurrentDimension()), block.isLoopHeader)) { lastInstr = getFirstInstruction(block, this.getCurrentDimension()); frameState = (HIRFrameStateBuilder) getEntryState(block, this.getCurrentDimension());