# HG changeset patch # User Thomas Wuerthinger # Date 1305894160 -7200 # Node ID 0d268cf66e24e248a8f89fdc2c736de5d0705d2b # Parent 0fe79e7435c370a0252f890060610a90994f0917# Parent 6048da34036451d1324b5d7aea7899af48acc1e7 Merge. diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Fri May 20 14:22:40 2011 +0200 @@ -106,8 +106,6 @@ private final FrameStateBuilder frameState; // the current execution state private Instruction lastInstr; // the last instruction added - private Instruction placeholder; - private final LogStream log; @@ -117,8 +115,6 @@ private BlockBegin unwindBlock; - private final Set loopHeaders = new HashSet(); - /** * Creates a new, initialized, {@code GraphBuilder} instance for a given compilation. * @@ -158,23 +154,12 @@ blockList = new Block[rootMethod.code().length]; for (int i = 0; i < blockMap.blocks.size(); i++) { + int blockID = ir.nextBlockNumber(); + assert blockID == i; Block block = blockMap.blocks.get(i); - -// if (block.isLoopHeader) { - BlockBegin blockBegin = new BlockBegin(block.startBci, ir.nextBlockNumber(), graph); - - block.firstInstruction = blockBegin; - blockList[block.startBci] = block; - - if (block.isLoopHeader) { - loopHeaders.add(blockBegin); - } -// } else { -// blockList[block.startBci] = new Placeholder(graph); -// } + blockList[block.startBci] = block; } - // 1. create the start block Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); @@ -197,14 +182,12 @@ flags |= Flag.HasHandler.mask; } - assert !loopHeaders.contains(startBlock); mergeOrClone(startBlockBegin, frameState, false); // 3. setup internal state for appending instructions lastInstr = startBlockBegin; lastInstr.appendNext(null); - Instruction entryBlock = blockAt(0); BlockBegin syncHandler = null; Block syncBlock = null; if (isSynchronized(rootMethod.accessFlags())) { @@ -212,7 +195,7 @@ rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); // 4A.2 finish the start block - finishStartBlock(startBlockBegin, entryBlock); + finishStartBlock(startBlock); // 4A.3 setup an exception handler to unlock the root method synchronized object syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); @@ -225,7 +208,7 @@ addExceptionHandler(h); } else { // 4B.1 simply finish the start block - finishStartBlock(startBlockBegin, entryBlock); + finishStartBlock(startBlock); } // 5. SKIPPED: look for intrinsics @@ -268,28 +251,21 @@ return blocksVisited.contains(block); } - private void finishStartBlock(BlockBegin startBlock, Instruction stdEntry) { + private void finishStartBlock(Block startBlock) { assert bci() == 0; FrameState stateAfter = frameState.create(bci()); - Goto base = new Goto((BlockBegin) stdEntry, stateAfter, graph); + Instruction target = createTargetAt(0, stateAfter); + Goto base = new Goto(target, stateAfter, graph); appendWithBCI(base); - startBlock.setEnd(base); -// assert stdEntry instanceof Placeholder; - assert ((BlockBegin) stdEntry).stateBefore() == null; - prepareTarget(0); - mergeOrClone(stdEntry, stateAfter, loopHeaders.contains(stdEntry)); + ((BlockBegin) startBlock.firstInstruction).setEnd(base); } - private void prepareTarget(int bci) { - } - - public void mergeOrClone(Block target, FrameStateAccess newState) { + assert target.firstInstruction instanceof BlockBegin; if (target.isLoopHeader) { - assert target.firstInstruction instanceof BlockBegin; mergeOrClone(target.firstInstruction, newState, true); - - + } else { + mergeOrClone(target.firstInstruction, newState, false); } } @@ -392,7 +368,7 @@ int current = exceptionHandlers.size() - 1; if (exceptionHandlers.get(current).isCatchAll()) { - successor = exceptionHandlers.get(current).entryBlock().firstInstruction; + successor = createTarget(exceptionHandlers.get(current).entryBlock(), null); current--; } else { if (unwindBlock == null) { @@ -423,14 +399,15 @@ BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); if (handler.handler.catchType().isResolved()) { - ExceptionDispatch end = new ExceptionDispatch(null, (BlockBegin) handler.entryBlock().firstInstruction, null, handler, null, graph); - end.setBlockSuccessor(0, (BlockBegin) successor); + Instruction entry = createTarget(handler.entryBlock(), null); + ExceptionDispatch end = new ExceptionDispatch(null, entry, null, handler, null, graph); + end.setBlockSuccessor(0, successor); dispatchEntry.appendNext(end); dispatchEntry.setEnd(end); } else { Deoptimize deopt = new Deoptimize(graph); dispatchEntry.appendNext(deopt); - Goto end = new Goto((BlockBegin) successor, null, graph); + Goto end = new Goto(successor, null, graph); deopt.appendNext(end); dispatchEntry.setEnd(end); } @@ -447,7 +424,7 @@ ExceptionObject exception = new ExceptionObject(graph); entry.appendNext(exception); FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); - BlockEnd end = new Goto((BlockBegin) successor, stateWithException, graph); + BlockEnd end = new Goto(successor, stateWithException, graph); exception.appendNext(end); entry.setEnd(end); @@ -505,7 +482,7 @@ // fill in exception handler subgraph lazily if (!isVisited(entry)) { if (handler.handlerBCI() != Instruction.SYNCHRONIZATION_ENTRY_BCI) { - addToWorkList(blockList[handler.handlerBCI()]); + addToWorkList(entry); } } else { // This will occur for exception handlers that cover themselves. This code @@ -689,13 +666,13 @@ } private void genGoto(int fromBCI, int toBCI) { - append(new Goto((BlockBegin) createTargetAt(toBCI, frameState), null, graph)); + append(new Goto(createTargetAt(toBCI, frameState), null, graph)); } private void ifNode(Value x, Condition cond, Value y) { Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); Instruction fsucc = createTargetAt(stream().nextBCI(), frameState); - append(new If(x, cond, y, (BlockBegin) tsucc, (BlockBegin) fsucc, null, graph)); + append(new If(x, cond, y, tsucc, fsucc, null, graph)); } private void genIfZero(Condition cond) { @@ -1059,6 +1036,7 @@ private void genTableswitch() { int bci = bci(); + Value value = frameState.ipop(); BytecodeTableSwitch ts = new BytecodeTableSwitch(stream(), bci); int max = ts.numberOfCases(); List list = new ArrayList(max + 1); @@ -1074,19 +1052,12 @@ list.add(createTargetAt(bci + offset, frameState)); boolean isSafepoint = isBackwards && !noSafepoints(); FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; - append(new TableSwitch(frameState.ipop(), (List) list, ts.lowKey(), stateAfter, graph)); - } - - private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { - return createTarget(blockList[bci], stateAfter); - } - - private Instruction createTarget(Block block, FrameStateAccess stateAfter) { - return block.firstInstruction; + append(new TableSwitch(value, list, ts.lowKey(), stateAfter, graph)); } private void genLookupswitch() { int bci = bci(); + Value value = frameState.ipop(); BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); int max = ls.numberOfCases(); List list = new ArrayList(max + 1); @@ -1104,7 +1075,7 @@ list.add(createTargetAt(bci + offset, frameState)); boolean isSafepoint = isBackwards && !noSafepoints(); FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; - append(new LookupSwitch(frameState.ipop(), (List) list, keys, stateAfter, graph)); + append(new LookupSwitch(value, list, keys, stateAfter, graph)); } private Value appendConstant(CiConstant constant) { @@ -1124,10 +1095,6 @@ assert x.next() == null : "instruction should not have been appended yet"; assert lastInstr.next() == null : "cannot append instruction to instruction which isn't end (" + lastInstr + "->" + lastInstr.next() + ")"; - if (placeholder != null) { - placeholder = null; - } - lastInstr = lastInstr.appendNext(x); if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { // bailout if we've exceeded the maximum inlining size @@ -1147,6 +1114,22 @@ return result; } + private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { + return createTarget(blockList[bci], stateAfter); + } + + private Instruction createTarget(Block block, FrameStateAccess stateAfter) { + if (block.firstInstruction == null) { + BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, graph); + block.firstInstruction = blockBegin; + } + if (stateAfter != null) { + mergeOrClone(block, stateAfter); + } + addToWorkList(block); + return block.firstInstruction; + } + private Value synchronizedObject(FrameStateAccess state, RiMethod target) { if (isStatic(target.accessFlags())) { Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); @@ -1203,17 +1186,8 @@ if (!isVisited(block)) { markVisited(block); // now parse the block - if (block.firstInstruction instanceof Placeholder) { - assert false; - placeholder = block.firstInstruction; - frameState.initializeFrom(((Placeholder) placeholder).stateBefore()); - lastInstr = null; - } else { - assert block.firstInstruction instanceof BlockBegin; - placeholder = null; - frameState.initializeFrom(((BlockBegin) block.firstInstruction).stateBefore()); - lastInstr = block.firstInstruction; - } + frameState.initializeFrom(((BlockBegin) block.firstInstruction).stateBefore()); + lastInstr = block.firstInstruction; assert block.firstInstruction.next() == null; iterateBytecodesForBlock(block); @@ -1235,7 +1209,8 @@ Block nextBlock = blockList[bci]; if (nextBlock != null && nextBlock != block) { // we fell through to the next block, add a goto and break - end = new Goto((BlockBegin) nextBlock.firstInstruction, null, graph); + Instruction next = createTarget(nextBlock, frameState); + end = new Goto(next, null, graph); lastInstr = lastInstr.appendNext(end); break; } @@ -1274,13 +1249,6 @@ if (block.firstInstruction instanceof BlockBegin) { ((BlockBegin) block.firstInstruction).setEnd(end); } - - // propagate the state - for (BlockBegin succ : end.blockSuccessors()) { - assert succ.blockPredecessors().contains(end); - mergeOrClone(succ, stateAtEnd, loopHeaders.contains(succ)); - addToWorkList(blockList[succ.bci()]); - } return end; } diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Fri May 20 14:22:40 2011 +0200 @@ -25,13 +25,11 @@ import java.util.*; import com.oracle.graal.graph.*; -import com.sun.c1x.*; import com.sun.c1x.debug.*; import com.sun.c1x.lir.*; import com.sun.c1x.util.*; import com.sun.c1x.value.*; import com.sun.cri.ci.*; -import com.sun.cri.ri.*; /** * Denotes the beginning of a basic block, and holds information diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Fri May 20 14:22:40 2011 +0200 @@ -77,8 +77,9 @@ return (BlockBegin) successors().get(super.successorCount() + SUCCESSOR_COUNT + index); } - public BlockBegin setBlockSuccessor(int index, BlockBegin n) { + public Instruction setBlockSuccessor(int index, Instruction n) { assert index >= 0 && index < blockSuccessorCount; + assert n instanceof BlockBegin : "only BlockBegins, for now..."; return (BlockBegin) successors().set(super.successorCount() + SUCCESSOR_COUNT + index, n); } @@ -93,7 +94,7 @@ * @param isSafepoint {@code true} if this instruction is a safepoint instruction * @param successors the list of successor blocks. If {@code null}, a new one will be created. */ - public BlockEnd(CiKind kind, FrameState stateAfter, List blockSuccessors, int inputCount, int successorCount, Graph graph) { + public BlockEnd(CiKind kind, FrameState stateAfter, List blockSuccessors, int inputCount, int successorCount, Graph graph) { this(kind, stateAfter, blockSuccessors.size(), inputCount, successorCount, graph); for (int i = 0; i < blockSuccessors.size(); i++) { setBlockSuccessor(i, blockSuccessors.get(i)); @@ -166,7 +167,7 @@ */ public void reorderSuccessor(int i, int backEdgeIndex) { assert i >= 0 && i < blockSuccessorCount; - BlockBegin successor = blockSuccessor(i); + Instruction successor = blockSuccessor(i); if (successor != null) { successors().set(super.successorCount() + SUCCESSOR_COUNT + i, Node.Null); successors().set(super.successorCount() + SUCCESSOR_COUNT + i, successor, backEdgeIndex); diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionDispatch.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionDispatch.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionDispatch.java Fri May 20 14:22:40 2011 +0200 @@ -64,7 +64,7 @@ /** * Constructs a new ExceptionDispatch instruction. */ - public ExceptionDispatch(Value exception, BlockBegin catchSuccessor, BlockBegin otherSuccessor, ExceptionHandler handler, FrameState stateAfter, Graph graph) { + public ExceptionDispatch(Value exception, Instruction catchSuccessor, Instruction otherSuccessor, ExceptionHandler handler, FrameState stateAfter, Graph graph) { super(CiKind.Int, stateAfter, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); setException(exception); setBlockSuccessor(0, otherSuccessor); diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/Goto.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Goto.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Goto.java Fri May 20 14:22:40 2011 +0200 @@ -42,7 +42,7 @@ * @param isSafepoint {@code true} if the goto should be considered a safepoint (e.g. backward branch) * @param graph */ - public Goto(BlockBegin succ, FrameState stateAfter, Graph graph) { + public Goto(Instruction succ, FrameState stateAfter, Graph graph) { super(CiKind.Illegal, stateAfter, 1, INPUT_COUNT, SUCCESSOR_COUNT, graph); setBlockSuccessor(0, succ); } diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/If.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Fri May 20 14:22:40 2011 +0200 @@ -86,8 +86,7 @@ * @param isSafepoint {@code true} if this branch should be considered a safepoint * @param graph */ - public If(Value x, Condition cond, Value y, - BlockBegin trueSucc, BlockBegin falseSucc, FrameState stateAfter, Graph graph) { + public If(Value x, Condition cond, Value y, Instruction trueSucc, Instruction falseSucc, FrameState stateAfter, Graph graph) { super(CiKind.Illegal, stateAfter, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); assert Util.archKindsEqual(x, y); condition = cond; diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/LookupSwitch.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/LookupSwitch.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/LookupSwitch.java Fri May 20 14:22:40 2011 +0200 @@ -50,7 +50,7 @@ * @param isSafepoint {@code true} if this instruction is a safepoint * @param graph */ - public LookupSwitch(Value value, List successors, int[] keys, FrameState stateAfter, Graph graph) { + public LookupSwitch(Value value, List successors, int[] keys, FrameState stateAfter, Graph graph) { super(value, successors, stateAfter, INPUT_COUNT, SUCCESSOR_COUNT, graph); this.keys = keys; } diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/Switch.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Switch.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Switch.java Fri May 20 14:22:40 2011 +0200 @@ -67,7 +67,7 @@ * @param isSafepoint {@code true} if this switch is a safepoint * @param graph */ - public Switch(Value value, List successors, FrameState stateAfter, int inputCount, int successorCount, Graph graph) { + public Switch(Value value, List successors, FrameState stateAfter, int inputCount, int successorCount, Graph graph) { super(CiKind.Illegal, stateAfter, successors, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph); setValue(value); } diff -r 0fe79e7435c3 -r 0d268cf66e24 graal/GraalCompiler/src/com/sun/c1x/ir/TableSwitch.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/TableSwitch.java Fri May 20 14:22:22 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/TableSwitch.java Fri May 20 14:22:40 2011 +0200 @@ -49,7 +49,7 @@ * @param isSafepoint {@code true} if this instruction is a safepoint * @param graph */ - public TableSwitch(Value value, List successors, int lowKey, FrameState stateAfter, Graph graph) { + public TableSwitch(Value value, List successors, int lowKey, FrameState stateAfter, Graph graph) { super(value, successors, stateAfter, INPUT_COUNT, SUCCESSOR_COUNT, graph); this.lowKey = lowKey; }