# HG changeset patch # User Thomas Wuerthinger # Date 1305806395 -7200 # Node ID c1a9bf38da2836bf716656734ba3bfa338567f84 # Parent 3ac3dd97d8df385638d6aed85a841552ba770259 Removed bci from the Instruction class. diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java Thu May 19 13:59:55 2011 +0200 @@ -128,8 +128,8 @@ begin("block"); out.print("name \"B").print(block.blockID).println('"'); - out.print("from_bci ").println(block.bci()); - out.print("to_bci ").println(block.end() == null ? -1 : block.end().bci()); + out.print("from_bci -1"); + out.print("to_bci -1"); out.print("predecessors "); for (Instruction pred : block.blockPredecessors()) { @@ -519,7 +519,7 @@ * @param i the instruction for which HIR will be printed */ private void printInstructionHIR(Instruction i) { - out.print("bci ").print(i.bci()).println(COLUMN_END); + out.print("bci ").print(-1).println(COLUMN_END); if (i.operand().isLegal()) { out.print("result ").print(new CFGOperandFormatter(false).format(i.operand())).println(COLUMN_END); } diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java Thu May 19 13:59:55 2011 +0200 @@ -131,7 +131,7 @@ public void printInstructionListing(Value instruction) { int indentation = out.indentationLevel(); out.fillTo(BCI.position + indentation, ' '). - print(instruction instanceof Instruction ? ((Instruction) instruction).bci() : 0). + print(0). fillTo(USE.position + indentation, ' '). print("0"). fillTo(VALUE.position + indentation, ' '). diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Thu May 19 13:59:55 2011 +0200 @@ -42,6 +42,7 @@ import com.sun.c1x.util.*; import com.sun.c1x.value.*; import com.sun.c1x.value.FrameState.PhiProcedure; +import com.sun.cri.bytecode.*; import com.sun.cri.bytecode.Bytecodes.MemoryBarriers; import com.sun.cri.ci.*; import com.sun.cri.ri.*; @@ -447,7 +448,7 @@ } protected FrameState stateBeforeInvokeReturn(Invoke invoke) { - return invoke.stateAfter().duplicateModified(invoke.bci(), invoke.kind/*, args*/); + return invoke.stateAfter().duplicateModified(getBeforeInvokeBci(invoke), invoke.kind); } protected FrameState stateBeforeInvokeWithArguments(Invoke invoke) { @@ -455,7 +456,15 @@ for (int i = 0; i < invoke.argumentCount(); i++) { args[i] = invoke.argument(i); } - return invoke.stateAfter().duplicateModified(invoke.bci(), invoke.kind, args); + return invoke.stateAfter().duplicateModified(getBeforeInvokeBci(invoke), invoke.kind, args); + } + + private int getBeforeInvokeBci(Invoke invoke) { + int length = 3; + if (invoke.opcode() == Bytecodes.INVOKEINTERFACE) { + length += 2; + } + return invoke.stateAfter().bci - length; } @Override @@ -1393,17 +1402,8 @@ walkStateValue(value); } } - FrameState s = state; - int bci = x.bci(); - if (bci == Instruction.SYNCHRONIZATION_ENTRY_BCI) { - assert x instanceof ExceptionObject || - x instanceof Throw || - x instanceof MonitorEnter || - x instanceof MonitorExit : x + ", " + x.getClass(); - } - - for (int index = 0; index < s.localsSize(); index++) { - final Value value = s.localAt(index); + for (int index = 0; index < state.localsSize(); index++) { + final Value value = state.localAt(index); if (value != null) { if (!value.isIllegal()) { walkStateValue(value); diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Thu May 19 13:59:55 2011 +0200 @@ -189,7 +189,7 @@ // 3. setup internal state for appending instructions curBlock = startBlock; lastInstr = startBlock; - lastInstr.appendNext(null, -1); + lastInstr.appendNext(null); BlockBegin entryBlock = blockList[0]; if (isSynchronized(rootMethod.accessFlags())) { @@ -247,7 +247,7 @@ assert curBlock == startBlock; FrameState stateAfter = frameState.create(bci()); Goto base = new Goto(stdEntry, stateAfter, graph); - appendWithoutOptimization(base, 0); + appendWithBCI(base); startBlock.setEnd(base); assert stdEntry.stateBefore() == null; stdEntry.mergeOrClone(stateAfter, method()); @@ -315,7 +315,7 @@ if (unwindBlock == null) { unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); Unwind unwind = new Unwind(null, graph); - unwindBlock.appendNext(unwind, bci); + unwindBlock.appendNext(unwind); unwindBlock.setEnd(unwind); } successor = unwindBlock; @@ -341,13 +341,13 @@ if (handler.handler.catchType().isResolved()) { ExceptionDispatch end = new ExceptionDispatch(null, handler.entryBlock(), null, handler, null, graph); end.setBlockSuccessor(0, successor); - dispatchEntry.appendNext(end, handler.handlerBCI()); + dispatchEntry.appendNext(end); dispatchEntry.setEnd(end); } else { Deoptimize deopt = new Deoptimize(graph); - dispatchEntry.appendNext(deopt, bci); + dispatchEntry.appendNext(deopt); Goto end = new Goto(successor, null, graph); - deopt.appendNext(end, bci); + deopt.appendNext(end); dispatchEntry.setEnd(end); } newBlocks.add(dispatchEntry); @@ -360,10 +360,10 @@ BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), graph); entry.setStateBefore(entryState); ExceptionObject exception = new ExceptionObject(graph); - entry.appendNext(exception, bci); + entry.appendNext(exception); FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); BlockEnd end = new Goto(successor, stateWithException, graph); - exception.appendNext(end, bci); + exception.appendNext(end); entry.setEnd(end); if (x instanceof Invoke) { @@ -611,14 +611,8 @@ private void ifNode(Value x, Condition cond, Value y, FrameState stateBefore) { BlockBegin tsucc = blockAt(stream().readBranchDest()); BlockBegin fsucc = blockAt(stream().nextBCI()); - int bci = stream().currentBCI(); - boolean isSafepoint = !noSafepoints() && (tsucc.bci() <= bci || fsucc.bci() <= bci); - if (isSafepoint) { - append(new If(x, cond, y, tsucc, fsucc, stateBefore, graph)); - } else { - append(new If(x, cond, y, tsucc, fsucc, null, graph)); - stateBefore.delete(); - } + append(new If(x, cond, y, tsucc, fsucc, null, graph)); + stateBefore.delete(); } private void genIfZero(Condition cond) { @@ -646,7 +640,8 @@ FrameState stateBefore = frameState.create(bci); Throw t = new Throw(frameState.apop(), graph); t.setStateBefore(stateBefore); - appendWithoutOptimization(t, bci); + appendWithBCI(t); + handleException(t, bci); } private void genCheckCast() { @@ -863,7 +858,9 @@ private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool) { CiKind resultType = returnKind(target); - Value result = append(new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph)); + Invoke invoke = new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), graph); + Value result = appendWithBCI(invoke); + handleException(invoke, bci()); frameState.pushReturn(resultType, result); } @@ -968,7 +965,7 @@ append(lockAddress); } MonitorEnter monitorEnter = new MonitorEnter(x, lockAddress, lockNumber, graph); - appendWithoutOptimization(monitorEnter, bci); + appendWithBCI(monitorEnter); frameState.lock(ir, x, lockNumber + 1); if (bci == Instruction.SYNCHRONIZATION_ENTRY_BCI) { monitorEnter.setStateAfter(frameState.create(0)); @@ -985,7 +982,7 @@ lockAddress = new MonitorAddress(lockNumber, graph); append(lockAddress); } - appendWithoutOptimization(new MonitorExit(x, lockAddress, lockNumber, graph), bci); + appendWithBCI(new MonitorExit(x, lockAddress, lockNumber, graph)); frameState.unlock(); } @@ -1040,18 +1037,14 @@ } private Value appendConstant(CiConstant constant) { - return appendWithBCI(new Constant(constant, graph), bci()); + return appendWithBCI(new Constant(constant, graph)); } private Value append(Instruction x) { - return appendWithBCI(x, bci()); + return appendWithBCI(x); } - private Value appendWithoutOptimization(Instruction x, int bci) { - return appendWithBCI(x, bci); - } - - private Value appendWithBCI(Instruction x, int bci) { + private Value appendWithBCI(Instruction x) { if (x.isAppended()) { // the instruction has already been added return x; @@ -1060,17 +1053,12 @@ 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() + ")"; - lastInstr = lastInstr.appendNext(x, bci); + lastInstr = lastInstr.appendNext(x); if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { // bailout if we've exceeded the maximum inlining size throw new CiBailout("Method and/or inlining is too large"); } - if (x instanceof ExceptionEdgeInstruction) { - // connect the instruction to any exception handlers - handleException(x, bci); - } - return x; } @@ -1087,7 +1075,7 @@ private Value synchronizedObject(FrameStateAccess state, RiMethod target) { if (isStatic(target.accessFlags())) { Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); - return appendWithoutOptimization(classConstant, Instruction.SYNCHRONIZATION_ENTRY_BCI); + return appendWithBCI(classConstant); } else { return state.localAt(0); } @@ -1112,7 +1100,7 @@ if (lock instanceof Instruction) { Instruction l = (Instruction) lock; if (!l.isAppended()) { - lock = appendWithoutOptimization(l, Instruction.SYNCHRONIZATION_ENTRY_BCI); + lock = appendWithBCI(l); } } // exit the monitor @@ -1145,7 +1133,7 @@ curBlock = b; frameState.initializeFrom(b.stateBefore()); lastInstr = b; - b.appendNext(null, -1); + b.appendNext(null); iterateBytecodesForBlock(b.bci()); } @@ -1158,7 +1146,6 @@ BlockBegin block = curBlock; BlockEnd end = null; - int prevBCI = bci; int endBCI = stream.endBCI(); boolean blockStart = true; @@ -1167,7 +1154,7 @@ if (nextBlock != null && nextBlock != block) { // we fell through to the next block, add a goto and break end = new Goto(nextBlock, null, graph); - lastInstr = lastInstr.appendNext(end, prevBCI); + lastInstr = lastInstr.appendNext(end); break; } // read the opcode @@ -1177,8 +1164,6 @@ traceInstruction(bci, stream, opcode, blockStart); processBytecode(bci, stream, opcode); - prevBCI = bci; - if (lastInstr instanceof BlockEnd) { end = (BlockEnd) lastInstr; break; diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Thu May 19 13:59:55 2011 +0200 @@ -155,12 +155,7 @@ * @return the new block inserted */ public BlockBegin splitEdge(BlockBegin source, BlockBegin target) { - int bci; - if (target.blockPredecessors().size() == 1) { - bci = target.bci(); - } else { - bci = source.end().bci(); - } + int bci = -2; int backEdgeIndex = target.predecessors().indexOf(source.end()); @@ -169,7 +164,7 @@ // This goto is not a safepoint. Goto e = new Goto(target, null, compilation.graph); - newSucc.appendNext(e, bci); + newSucc.appendNext(e); newSucc.setEnd(e); e.reorderSuccessor(0, backEdgeIndex); // setup states diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Thu May 19 13:59:55 2011 +0200 @@ -108,6 +108,12 @@ public final LIRBlock lirBlock = new LIRBlock(); /** + * Index of bytecode that generated this node when appended in a basic block. + * Negative values indicate special cases. + */ + private int bci; + + /** * Constructs a new BlockBegin at the specified bytecode index. * @param bci the bytecode index of the start * @param blockID the ID of the block @@ -288,6 +294,22 @@ } } + /** + * Gets the bytecode index of this instruction. + * @return the bytecode index of this instruction + */ + public int bci() { + return bci; + } + + /** + * Sets the bytecode index of this instruction. + * @param bci the new bytecode index for this instruction + */ + public void setBCI(int bci) { + this.bci = bci; + } + private void iterate(IdentityHashMap mark, BlockClosure closure) { if (!mark.containsKey(this)) { mark.put(this, this); @@ -311,9 +333,6 @@ iterateReverse(mark, closure, excBlocks); } -// if (exceptionHandlerBlocks != null) { -// iterateReverse(mark, closure, exceptionHandlerBlocks); -// } assert e != null : "block must have block end"; iterateReverse(mark, closure, e.blockSuccessors()); } @@ -336,7 +355,6 @@ if (existingState == null) { // copy state because it is modified FrameState duplicate = newState.duplicate(bci()); - assert duplicate.bci == bci() : "duplicate.bci=" + duplicate.bci + " my bci=" + bci(); if (C1XOptions.UseStackMapTableLiveness && method != null) { // if a liveness map is available, use it to invalidate dead locals @@ -429,8 +447,6 @@ builder.append(blockID); builder.append(","); builder.append(depthFirstNumber); - builder.append(" @ "); - builder.append(bci()); builder.append(" ["); boolean hasFlag = false; for (BlockFlag f : BlockFlag.values()) { @@ -540,7 +556,7 @@ } // print block bci range - out.print('[').print(bci()).print(", ").print(end == null ? -1 : end.bci()).print(']'); + out.print('[').print(-1).print(", ").print(-1).print(']'); // print block successors if (end != null && end.blockSuccessors().size() > 0) { diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java Thu May 19 13:59:55 2011 +0200 @@ -71,12 +71,6 @@ public static final int SYNCHRONIZATION_ENTRY_BCI = -1; - /** - * Index of bytecode that generated this node when appended in a basic block. - * Negative values indicate special cases. - */ - private int bci; - private boolean isAppended = false; /** @@ -91,23 +85,6 @@ } /** - * Gets the bytecode index of this instruction. - * @return the bytecode index of this instruction - */ - public final int bci() { - return bci; - } - - /** - * Sets the bytecode index of this instruction. - * @param bci the new bytecode index for this instruction - */ - public final void setBCI(int bci) { - assert bci >= 0 || bci == SYNCHRONIZATION_ENTRY_BCI; - this.bci = bci; - } - - /** * Checks whether this instruction has already been added to its basic block. * @return {@code true} if this instruction has been added to the basic block containing it */ @@ -123,11 +100,10 @@ * @param bci the bytecode index of the next instruction * @return the new next instruction */ - public final Instruction appendNext(Instruction next, int bci) { + public final Instruction appendNext(Instruction next) { setNext(next); if (next != null) { assert !(this instanceof BlockEnd); - next.setBCI(bci); next.isAppended = true; } return next; @@ -135,7 +111,6 @@ @Override public BlockBegin block() { - // TODO(tw): Make this more efficient. Instruction cur = this; while (!(cur instanceof BlockEnd)) { cur = cur.next(); diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/ir/Value.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java Thu May 19 13:59:55 2011 +0200 @@ -273,10 +273,6 @@ builder.append(' '); } builder.append(getClass().getSimpleName()); - if (this instanceof Instruction) { - builder.append(" @ "); - builder.append(((Instruction) this).bci()); - } builder.append(" [").append(flagsToString()).append("]"); return builder.toString(); } diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/lir/LIRAssembler.java --- a/graal/GraalCompiler/src/com/sun/c1x/lir/LIRAssembler.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/lir/LIRAssembler.java Thu May 19 13:59:55 2011 +0200 @@ -118,7 +118,7 @@ assert block.lir() != null : "must have LIR"; if (C1XOptions.CommentedAssembly) { - String st = String.format(" block B%d [%d, %d]", block.blockID, block.bci(), block.end().bci()); + String st = String.format(" block B%d", block.blockID); tasm.blockComment(st); } diff -r 3ac3dd97d8df -r c1a9bf38da28 graal/GraalCompiler/src/com/sun/c1x/lir/LIRList.java --- a/graal/GraalCompiler/src/com/sun/c1x/lir/LIRList.java Thu May 19 13:21:31 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/lir/LIRList.java Thu May 19 13:59:55 2011 +0200 @@ -390,7 +390,6 @@ public static void printBlock(BlockBegin x) { // print block id - BlockEnd end = x.end(); TTY.print("B%d ", x.blockID); // print flags @@ -402,7 +401,7 @@ } // print block bci range - TTY.print("[%d, %d] ", x.bci(), (end == null ? -1 : end.bci())); + TTY.print("[%d, %d] ", -1, -1); // print predecessors and successors if (x.numberOfPreds() > 0) {