# HG changeset patch # User Gilles Duboscq # Date 1304075957 -7200 # Node ID 274360f98f97657a2f4a5faa9fb4eb847c5adfc1 # Parent 491896f81cae0db9cfb366d2e31b65d262a3da5c Remove inlining (2nd part) removed IRScope diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java Fri Apr 29 13:19:17 2011 +0200 @@ -94,7 +94,7 @@ this.method = method; this.stats = stats == null ? new CiStatistics() : stats; this.registerConfig = method == null ? compiler.globalStubRegisterConfig : runtime.getRegisterConfig(method); - this.placeholderState = method != null && method.minimalDebugInfo() ? new MutableFrameState(new IRScope(null, null, method, -1), 0, 0, 0) : null; + this.placeholderState = method != null && method.minimalDebugInfo() ? new MutableFrameState(method, 0, 0, 0) : null; if (compiler.isObserved()) { compiler.fireCompilationStarted(new CompilationEvent(this)); @@ -241,7 +241,7 @@ C1XTimers.LIR_CREATE.start(); } - initFrameMap(hir.topScope.maxLocks()); + initFrameMap(hir.maxLocks()); lirGenerator = compiler.backend.newLIRGenerator(this); for (BlockBegin begin : hir.linearScanOrder()) { diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java --- a/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Fri Apr 29 13:19:17 2011 +0200 @@ -2084,14 +2084,6 @@ } CiFrame computeFrameForState(int opId, FrameState state, CiBitMap frameRefMap) { - CiFrame callerFrame = null; - - FrameState callerState = state.callerState(); - if (callerState != null) { - // process recursively to compute outermost scope first - callerFrame = computeFrameForState(opId, callerState, frameRefMap); - } - CiValue[] values = new CiValue[state.valuesSize() + state.locksSize()]; int valueIndex = 0; @@ -2117,7 +2109,7 @@ } } - return new CiFrame(callerFrame, state.scope().method, state.bci, values, state.localsSize(), state.stackSize(), state.locksSize()); + return new CiFrame(null, state.method, state.bci, values, state.localsSize(), state.stackSize(), state.locksSize()); } private void computeDebugInfo(IntervalWalker iw, LIRInstruction op) { diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java Fri Apr 29 13:19:17 2011 +0200 @@ -56,8 +56,6 @@ printFrameState(block.stateBefore(), out); out.println(); - out.println("inlining depth " + block.stateBefore().scope().level); - ip.printInstructionListingHeader(); for (Instruction i = block.next(); i != null; i = i.next()) { diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/CFGPrinter.java Fri Apr 29 13:19:17 2011 +0200 @@ -99,6 +99,10 @@ private void end(String string) { out.adjustIndentation(-2); + end("states"); + end("states"); + end("states"); + end("states"); out.println("end_" + string); } @@ -127,6 +131,7 @@ void printBlock(BlockBegin block, List successors, Iterable handlers, boolean printHIR, boolean printLIR) { begin("block"); + end("states"); 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()); @@ -158,6 +163,8 @@ } if (block.isSubroutineEntry()) { out.print("\"sr\" "); + end("states"); + end("states"); } if (block.isBackwardBranchTarget()) { out.print("\"bb\" "); @@ -202,73 +209,68 @@ * @param block the block for which the frame state is to be printed */ private void printState(BlockBegin block) { - begin("states"); + begin("state"); FrameState state = block.stateBefore(); - - do { - int stackSize = state.stackSize(); - if (stackSize > 0) { - begin("stack"); - out.print("size ").println(stackSize); - out.print("method \"").print(CiUtil.toLocation(state.scope().method, state.bci)).println('"'); - - int i = 0; - while (i < stackSize) { - Value value = state.stackAt(i); - out.disableIndentation(); - out.print(block.stateString(i, value)); - printOperand(value); - out.println(); - out.enableIndentation(); - if (value == null) { - i++; - } else { - i += value.kind.sizeInSlots(); - } - } - end("stack"); - } + int stackSize = state.stackSize(); + if (stackSize > 0) { + begin("stack"); + out.print("size ").println(stackSize); + out.print("method \"").print(CiUtil.toLocation(state.method, state.bci)).println('"'); - if (state.locksSize() > 0) { - begin("locks"); - out.print("size ").println(state.locksSize()); - out.print("method \"").print(CiUtil.toLocation(state.scope().method, state.bci)).println('"'); - - for (int i = 0; i < state.locksSize(); ++i) { - Value value = state.lockAt(i); - out.disableIndentation(); - out.print(block.stateString(i, value)); - printOperand(value); - out.println(); - out.enableIndentation(); - } - end("locks"); - } - - begin("locals"); - out.print("size ").println(state.localsSize()); - out.print("method \"").print(CiUtil.toLocation(state.scope().method, state.bci)).println('"'); int i = 0; - while (i < state.localsSize()) { - Value value = state.localAt(i); - if (value != null) { - out.disableIndentation(); - out.print(block.stateString(i, value)); - printOperand(value); - out.println(); - out.enableIndentation(); - // also ignore illegal HiWords - i += value.isIllegal() ? 1 : value.kind.sizeInSlots(); + while (i < stackSize) { + Value value = state.stackAt(i); + out.disableIndentation(); + out.print(block.stateString(i, value)); + printOperand(value); + out.println(); + out.enableIndentation(); + if (value == null) { + i++; } else { - i++; + i += value.kind.sizeInSlots(); } } - state = state.callerState(); - end("locals"); - } while (state != null); + end("stack"); + } + + if (state.locksSize() > 0) { + begin("locks"); + out.print("size ").println(state.locksSize()); + out.print("method \"").print(CiUtil.toLocation(state.method, state.bci)).println('"'); + + for (int i = 0; i < state.locksSize(); ++i) { + Value value = state.lockAt(i); + out.disableIndentation(); + out.print(block.stateString(i, value)); + printOperand(value); + out.println(); + out.enableIndentation(); + } + end("locks"); + } - end("states"); + begin("locals"); + out.print("size ").println(state.localsSize()); + out.print("method \"").print(CiUtil.toLocation(state.method, state.bci)).println('"'); + int i = 0; + while (i < state.localsSize()) { + Value value = state.localAt(i); + if (value != null) { + out.disableIndentation(); + out.print(block.stateString(i, value)); + printOperand(value); + out.println(); + out.enableIndentation(); + // also ignore illegal HiWords + i += value.isIllegal() ? 1 : value.kind.sizeInSlots(); + } else { + i++; + } + } + end("locals"); + end("state"); } /** @@ -280,49 +282,45 @@ } StringBuilder buf = new StringBuilder(); - - do { - buf.append(CiUtil.toLocation(state.scope().method, state.bci)); - buf.append('\n'); - if (state.stackSize() > 0) { - int i = 0; - buf.append("stack: "); - while (i < state.stackSize()) { - if (i == 0) { - buf.append(' '); - } - Value value = state.stackAt(i); - buf.append(stateValueToString(value, operandFmt)).append(' '); - i++; - } - buf.append("\n"); - } - - if (state.locksSize() > 0) { - buf.append("locks: "); - for (int i = 0; i < state.locksSize(); ++i) { - if (i == 0) { - buf.append(' '); - } - Value value = state.lockAt(i); - buf.append(stateValueToString(value, operandFmt)).append(' '); - } - buf.append("\n"); - } - - buf.append("locals: "); + buf.append(CiUtil.toLocation(state.method, state.bci)); + buf.append('\n'); + if (state.stackSize() > 0) { int i = 0; - while (i < state.localsSize()) { + buf.append("stack: "); + while (i < state.stackSize()) { if (i == 0) { buf.append(' '); } - Value value = state.localAt(i); + Value value = state.stackAt(i); buf.append(stateValueToString(value, operandFmt)).append(' '); i++; } buf.append("\n"); - state = state.callerState(); - } while (state != null); + } + + if (state.locksSize() > 0) { + buf.append("locks: "); + for (int i = 0; i < state.locksSize(); ++i) { + if (i == 0) { + buf.append(' '); + } + Value value = state.lockAt(i); + buf.append(stateValueToString(value, operandFmt)).append(' '); + } + buf.append("\n"); + } + + buf.append("locals: "); + int i = 0; + while (i < state.localsSize()) { + if (i == 0) { + buf.append(' '); + } + Value value = state.localAt(i); + buf.append(stateValueToString(value, operandFmt)).append(' '); + i++; + } + buf.append("\n"); return buf.toString(); } diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Fri Apr 29 13:19:17 2011 +0200 @@ -1283,17 +1283,9 @@ moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index)); } - // walk up the inlined scopes until locals match - while (curState.scope() != suxState.scope()) { - curState = curState.callerState(); - assert curState != null : "scopes don't match up"; - } - for (int index = 0; index < suxState.localsSize(); index++) { moveToPhi(resolver, curState.localAt(index), suxState.localAt(index)); } - - assert curState.scope().callerState == suxState.scope().callerState : "caller states must be equal"; resolver.dispose(); } } @@ -1390,26 +1382,20 @@ } 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(); + } - while (s != null) { - IRScope scope = s.scope(); - 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); - if (value != null) { - if (!value.isIllegal()) { - walkStateValue(value); - } + for (int index = 0; index < s.localsSize(); index++) { + final Value value = s.localAt(index); + if (value != null) { + if (!value.isIllegal()) { + walkStateValue(value); } } - bci = scope.callerBCI(); - s = s.callerState(); } } diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Fri Apr 29 13:19:17 2011 +0200 @@ -103,7 +103,7 @@ * Builds the graph for a the specified {@code IRScope}. * @param scope the top IRScope */ - public void build(IRScope scope) { + public void build() { RiMethod rootMethod = compilation.method; if (log != null) { @@ -116,9 +116,9 @@ BlockBegin startBlock = ir.startBlock; // 2. compute the block map and get the entrypoint(s) - BlockMap blockMap = compilation.getBlockMap(scope.method); + BlockMap blockMap = compilation.getBlockMap(rootMethod); BlockBegin stdEntry = blockMap.get(0); - pushRootScope(scope, blockMap, startBlock); + pushRootScope(rootMethod, blockMap, startBlock); MutableFrameState initialState = stateAtEntry(rootMethod); startBlock.mergeOrClone(initialState); BlockBegin syncHandler = null; @@ -173,10 +173,10 @@ stdEntry.mergeOrClone(stateAfter); } - void pushRootScope(IRScope scope, BlockMap blockMap, BlockBegin start) { - BytecodeStream stream = new BytecodeStream(scope.method.code()); - RiConstantPool constantPool = compilation.runtime.getConstantPool(scope.method); - scopeData = new ScopeData(null, scope, blockMap, stream, constantPool); + void pushRootScope(RiMethod method, BlockMap blockMap, BlockBegin start) { + BytecodeStream stream = new BytecodeStream(method.code()); + RiConstantPool constantPool = compilation.runtime.getConstantPool(method); + scopeData = new ScopeData(null, method, blockMap, stream, constantPool); curBlock = start; } @@ -184,20 +184,8 @@ return scopeData.hasHandler(); } - public IRScope scope() { - return scopeData.scope; - } - - public IRScope rootScope() { - IRScope root = scope(); - while (root.caller != null) { - root = root.caller; - } - return root; - } - public RiMethod method() { - return scopeData.scope.method; + return compilation.method; } public BytecodeStream stream() { @@ -328,7 +316,7 @@ // Also check parent jsrs (if any) at this time to see whether // they are using this local. We don't handle skipping over a // ret. - for (ScopeData cur = scopeData.parent; cur != null && cur.parsingJsr() && cur.scope == scope(); cur = cur.parent) { + for (ScopeData cur = scopeData.parent; cur != null && cur.parsingJsr(); cur = cur.parent) { if (cur.jsrEntryReturnAddressLocal() == index) { throw new CiBailout("subroutine overwrites return address from previous subroutine"); } @@ -347,40 +335,21 @@ assert stateBefore != null : "exception handler state must be available for " + x; FrameState state = stateBefore; - do { - assert curScopeData.scope == state.scope() : "scopes do not match"; - assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == curScopeData.stream.currentBCI() : "invalid bci"; + assert bci == Instruction.SYNCHRONIZATION_ENTRY_BCI || bci == curScopeData.stream.currentBCI() : "invalid bci"; - // join with all potential exception handlers - List handlers = curScopeData.exceptionHandlers(); - if (handlers != null) { - for (ExceptionHandler handler : handlers) { - if (handler.covers(bci)) { - // if the handler covers this bytecode index, add it to the list - if (addExceptionHandler(exceptionHandlers, handler, curScopeData, state, scopeCount)) { - // if the handler was a default handler, we are done - return exceptionHandlers; - } + // join with all potential exception handlers + List handlers = curScopeData.exceptionHandlers(); + if (handlers != null) { + for (ExceptionHandler handler : handlers) { + if (handler.covers(bci)) { + // if the handler covers this bytecode index, add it to the list + if (addExceptionHandler(exceptionHandlers, handler, curScopeData, state, scopeCount)) { + // if the handler was a default handler, we are done + return exceptionHandlers; } } } - // pop the scope to the next IRScope level - // if parsing a JSR, skip scopes until the next IRScope level - IRScope curScope = curScopeData.scope; - while (curScopeData.parent != null && curScopeData.parent.scope == curScope) { - curScopeData = curScopeData.parent; - } - if (curScopeData.parent == null) { - // no more levels, done - break; - } - // there is another level, pop - state = state.callerState(); - bci = curScopeData.scope.callerBCI(); - curScopeData = curScopeData.parent; - scopeCount++; - - } while (true); + } return exceptionHandlers; } @@ -1108,7 +1077,7 @@ } MonitorEnter monitorEnter = new MonitorEnter(x, lockAddress, lockNumber, null); appendWithoutOptimization(monitorEnter, bci); - curState.lock(scope(), x, lockNumber + 1); + curState.lock(ir, x, lockNumber + 1); monitorEnter.setStateAfter(curState.immutableCopy(bci)); killMemoryMap(); // prevent any optimizations across synchronization } @@ -1129,7 +1098,7 @@ } void genJsr(int dest) { - for (ScopeData cur = scopeData; cur != null && cur.parsingJsr() && cur.scope == scope(); cur = cur.parent) { + for (ScopeData cur = scopeData; cur != null && cur.parsingJsr(); cur = cur.parent) { if (cur.jsrEntryBCI() == dest) { // the jsr/ret pattern includes a recursive invocation throw new CiBailout("recursive jsr/ret structure"); @@ -1333,9 +1302,9 @@ } void pushScopeForJsr(BlockBegin jsrCont, int jsrStart) { - BytecodeStream stream = new BytecodeStream(scope().method.code()); + BytecodeStream stream = new BytecodeStream(compilation.method.code()); RiConstantPool constantPool = scopeData.constantPool; - ScopeData data = new ScopeData(scopeData, scope(), scopeData.blockMap, stream, constantPool, jsrStart); + ScopeData data = new ScopeData(scopeData, compilation.method, scopeData.blockMap, stream, constantPool, jsrStart); BlockBegin continuation = scopeData.continuation(); data.setContinuation(continuation); if (continuation != null) { @@ -1347,7 +1316,7 @@ } MutableFrameState stateAtEntry(RiMethod method) { - MutableFrameState state = new MutableFrameState(scope(), -1, method.maxLocals(), method.maxStackSize()); + MutableFrameState state = new MutableFrameState(method, -1, method.maxLocals(), method.maxStackSize()); int index = 0; if (!isStatic(method.accessFlags())) { // add the receiver and assume it is non null @@ -1521,7 +1490,7 @@ private void traceState() { if (C1XOptions.TraceBytecodeParserLevel >= TRACELEVEL_STATE && !TTY.isSuppressed()) { - log.println(String.format("| state [nr locals = %d, stack depth = %d, method = %s]", curState.localsSize(), curState.stackSize(), curState.scope().method)); + log.println(String.format("| state [nr locals = %d, stack depth = %d, method = %s]", curState.localsSize(), curState.stackSize(), method())); for (int i = 0; i < curState.localsSize(); ++i) { Value value = curState.localAt(i); log.println(String.format("| local[%d] = %-8s : %s", i, value == null ? "bogus" : value.kind.javaName, value)); diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Fri Apr 29 13:19:17 2011 +0200 @@ -54,10 +54,7 @@ */ public BlockBegin osrEntryBlock; - /** - * The top IRScope. - */ - public IRScope topScope; + private int maxLocks; /** * The linear-scan ordered list of blocks. @@ -95,10 +92,8 @@ } private void buildGraph() { - topScope = new IRScope(null, null, compilation.method, -1); - // Graph builder must set the startBlock and the osrEntryBlock - new GraphBuilder(compilation, this).build(topScope); + new GraphBuilder(compilation, this).build(); assert startBlock != null; verifyAndPrint("After graph building"); @@ -259,4 +254,23 @@ public int numLoops() { return compilation.stats.loopCount; } + + /** + * Updates the maximum number of locks held at any one time. + * + * @param locks a lock count that will replace the current {@linkplain #maxLocks() max locks} if it is greater + */ + public void updateMaxLocks(int locks) { + if (locks > maxLocks) { + maxLocks = locks; + } + } + + /** + * Gets the number of locks + * @return the number of locks + */ + public final int maxLocks() { + return maxLocks; + } } diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/graph/ScopeData.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/ScopeData.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/ScopeData.java Fri Apr 29 13:19:17 2011 +0200 @@ -63,8 +63,8 @@ final ScopeData parent; - // the IR scope - final IRScope scope; + // + final RiMethod method; // bci-to-block mapping final BlockMap blockMap; // the bytecode stream @@ -132,9 +132,9 @@ * @param stream the bytecode stream * @param constantPool the constant pool */ - public ScopeData(ScopeData parent, IRScope scope, BlockMap blockMap, BytecodeStream stream, RiConstantPool constantPool) { + public ScopeData(ScopeData parent, RiMethod method, BlockMap blockMap, BytecodeStream stream, RiConstantPool constantPool) { this.parent = parent; - this.scope = scope; + this.method = method; this.blockMap = blockMap; this.stream = stream; this.constantPool = constantPool; @@ -148,16 +148,16 @@ if (parent.hasHandler()) { flags |= HasHandler.mask; } - if (parent.noSafepoints() || scope.method.noSafepoints()) { + if (parent.noSafepoints() || method.noSafepoints()) { flags |= NoSafepoints.mask; } } else { maxInlineSize = C1XOptions.MaximumInlineSize; - if (scope.method.noSafepoints()) { + if (method.noSafepoints()) { flags |= NoSafepoints.mask; } } - RiExceptionHandler[] handlers = scope.method.exceptionHandlers(); + RiExceptionHandler[] handlers = method.exceptionHandlers(); if (handlers != null && handlers.length > 0) { exceptionHandlers = new ArrayList(handlers.length); for (RiExceptionHandler ch : handlers) { @@ -179,16 +179,16 @@ * @param constantPool the constant pool * @param jsrEntryBci the bytecode index of the entrypoint of the JSR */ - public ScopeData(ScopeData parent, IRScope scope, BlockMap blockMap, BytecodeStream stream, RiConstantPool constantPool, int jsrEntryBci) { + public ScopeData(ScopeData parent, RiMethod method, BlockMap blockMap, BytecodeStream stream, RiConstantPool constantPool, int jsrEntryBci) { this.parent = parent; - this.scope = scope; + this.method = method; this.blockMap = blockMap; this.stream = stream; this.constantPool = constantPool; assert jsrEntryBci > 0 : "jsr cannot jump to BCI 0"; assert parent != null : "jsr must have parent scope"; this.jsrEntryBci = jsrEntryBci; - this.jsrDuplicatedBlocks = new BlockBegin[scope.method.code().length]; + this.jsrDuplicatedBlocks = new BlockBegin[method.code().length]; this.jsrRetAddrLocal = -1; maxInlineSize = (int) (C1XOptions.MaximumInlineRatio * parent.maxInlineSize()); @@ -271,15 +271,6 @@ } /** - * Gets the size of the stack at the caller. - * @return the size of the stack - */ - public int callerStackSize() { - FrameState state = scope.callerState; - return state == null ? 0 : state.stackSize(); - } - - /** * Gets the block continuation for this ScopeData. * @return the continuation */ @@ -502,9 +493,9 @@ @Override public String toString() { if (parsingJsr()) { - return "jsr@" + jsrEntryBci + " data for " + scope.toString(); + return "jsr@" + jsrEntryBci + " data for " + method.toString(); } else { - return "data for " + scope.toString(); + return "data for " + method.toString(); } } diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Fri Apr 29 13:19:17 2011 +0200 @@ -409,7 +409,7 @@ if (C1XOptions.UseStackMapTableLiveness) { // if a liveness map is available, use it to invalidate dead locals - CiBitMap[] livenessMap = newState.scope().method.livenessMap(); + CiBitMap[] livenessMap = newState.method.livenessMap(); if (livenessMap != null && bci() >= 0) { assert bci() < livenessMap.length; CiBitMap liveness = livenessMap[bci()]; @@ -431,14 +431,6 @@ throw new CiBailout("stack or locks do not match"); } - // while (existingState.scope() != newState.scope()) { - // // XXX: original code is not sure if this is necessary - // newState = newState.scope().callerState(); - // assert newState != null : "could not match scopes"; - // } - // above code replaced with assert for the moment - assert existingState.scope() == newState.scope(); - assert existingState.localsSize() == newState.localsSize(); assert existingState.stackSize() == newState.stackSize(); @@ -471,19 +463,10 @@ newState.setupPhiForStack(this, i); } int localsSize = newState.localsSize(); - CiBitMap requiresPhi = newState.scope().getStoresInLoops(); for (int i = 0; i < localsSize; i++) { Value x = newState.localAt(i); if (x != null) { - if (requiresPhi != null) { - if (requiresPhi.get(i) || x.kind.isDoubleWord() && requiresPhi.get(i + 1)) { - // selectively do a phi - newState.setupPhiForLocal(this, i); - } - } else { - // always setup a phi - newState.setupPhiForLocal(this, i); - } + newState.setupPhiForLocal(this, i); } } } @@ -792,19 +775,16 @@ } } - do { - for (i = 0; !hasPhisInLocals && i < state.localsSize();) { - Value value = state.localAt(i); - hasPhisInLocals = isPhiAtBlock(value); - // also ignore illegal HiWords - if (value != null && !value.isIllegal()) { - i += value.kind.sizeInSlots(); - } else { - i++; - } + for (i = 0; !hasPhisInLocals && i < state.localsSize();) { + Value value = state.localAt(i); + hasPhisInLocals = isPhiAtBlock(value); + // also ignore illegal HiWords + if (value != null && !value.isIllegal()) { + i += value.kind.sizeInSlots(); + } else { + i++; } - state = state.callerState(); - } while (state != null); + } } // print values in locals @@ -813,21 +793,18 @@ out.println("Locals:"); FrameState state = stateBefore(); - do { - int i = 0; - while (i < state.localsSize()) { - Value value = state.localAt(i); - if (value != null) { - out.println(stateString(i, value)); - // also ignore illegal HiWords - i += value.isIllegal() ? 1 : value.kind.sizeInSlots(); - } else { - i++; - } + int i = 0; + while (i < state.localsSize()) { + Value value = state.localAt(i); + if (value != null) { + out.println(stateString(i, value)); + // also ignore illegal HiWords + i += value.isIllegal() ? 1 : value.kind.sizeInSlots(); + } else { + i++; } - out.println(); - state = state.callerState(); - } while (state != null); + } + out.println(); } // print values on stack diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/ir/IRScope.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/IRScope.java Fri Apr 29 11:50:28 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.c1x.ir; - -import com.sun.c1x.value.*; -import com.sun.cri.ci.*; -import com.sun.cri.ri.*; - -/** - * The {@code IRScope} class represents an inlining context in the compilation - * of a method. - * - * @author Ben L. Titzer - */ -public class IRScope { - - public final IRScope caller; - public final RiMethod method; - public final int level; - CiCodePos callerCodePos; - - /** - * The frame state at the call site of this scope's caller or {@code null} - * if this is not a nested scope. - */ - public final FrameState callerState; - - /** - * The maximum number of locks held in this scope at any one time - * (c.f. maxStack and maxLocals of the Code attribute in a class file). - */ - int maxLocks; - - CiBitMap storesInLoops; - - public IRScope(IRScope caller, FrameState callerState, RiMethod method, int osrBCI) { - this.caller = caller; - this.callerState = callerState; - this.method = method; - this.level = caller == null ? 0 : 1 + caller.level; - } - - /** - * Updates the maximum number of locks held in this scope at any one time. - * - * @param locks a lock count that will replace the current {@linkplain #maxLocks() max locks} for this scope if it is greater - */ - public void updateMaxLocks(int locks) { - if (locks > maxLocks) { - maxLocks = locks; - } - } - - /** - * Gets the number of locks in this IR scope. - * @return the number of locks - */ - public final int maxLocks() { - return maxLocks; - } - - /** - * Gets the bytecode index of the call site that called this method. - * @return the call site's bytecode index - */ - public final int callerBCI() { - return callerState == null ? -1 : callerState.bci; - } - - /** - * Returns whether this IR scope is the top scope (i.e. has no caller). - * @return {@code true} if this inlining scope has no parent - */ - public final boolean isTopScope() { - return caller == null; - } - - /** - * Gets the phi bitmap for this IR scope. The phi bitmap stores - * whether a phi instruction is required for each local variable. - * @return the phi bitmap for this IR scope - */ - public final CiBitMap getStoresInLoops() { - return storesInLoops; - } - - public final void setStoresInLoops(CiBitMap storesInLoops) { - this.storesInLoops = storesInLoops; - } - - @Override - public String toString() { - if (caller == null) { - return "root-scope: " + method; - } else { - return "inlined-scope: " + method + " [caller bci: " + callerState.bci + "]"; - } - } - - public CiCodePos callerCodePos() { - if (caller != null && callerCodePos == null) { - callerCodePos = caller.toCodePos(callerBCI()); - } - return callerCodePos; - } - - public CiCodePos toCodePos(int bci) { - return new CiCodePos(callerCodePos(), method, bci); - } -} diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Fri Apr 29 13:19:17 2011 +0200 @@ -62,7 +62,9 @@ */ protected final int maxLocals; - protected final IRScope scope; + //XXX temporary while removing IRScope + @Deprecated + public final RiMethod method; /** * The bytecode index to which this frame state applies. This will be {@code -1} @@ -92,8 +94,8 @@ * @param maxLocals maximum number of locals * @param maxStack maximum size of the stack */ - public FrameState(IRScope irScope, int bci, int maxLocals, int maxStack) { - this.scope = irScope; + public FrameState(RiMethod method, int bci, int maxLocals, int maxStack) { + this.method = method; this.bci = bci; this.values = new Value[maxLocals + Math.max(maxStack, MINIMUM_STACK_SLOTS)]; this.maxLocals = maxLocals; @@ -111,7 +113,7 @@ * @return a new frame state with the specified components */ public MutableFrameState copy(int bci, boolean withLocals, boolean withStack, boolean withLocks) { - final MutableFrameState other = new MutableFrameState(scope, bci, localsSize(), maxStackSize()); + final MutableFrameState other = new MutableFrameState(method, bci, localsSize(), maxStackSize()); if (withLocals && withStack) { // fast path: use array copy int valuesSize = valuesSize(); @@ -176,15 +178,6 @@ } /** - * Returns the inlining context associated with this frame state. - * - * @return the inlining context - */ - public IRScope scope() { - return scope; - } - - /** * Returns the size of the local variables. * * @return the size of the local variables @@ -200,8 +193,9 @@ return locks == null ? 0 : locks.size(); } + @Deprecated public int totalLocksSize() { - return locksSize() + ((callerState() == null) ? 0 : callerState().totalLocksSize()); + return locksSize(); } /** @@ -373,11 +367,6 @@ return maxLocals + stackIndex; } - public final int callerStackSize() { - FrameState callerState = scope().callerState; - return callerState == null ? 0 : callerState.stackSize(); - } - public void checkPhis(BlockBegin block, FrameState other) { checkSize(other); final int max = valuesSize(); @@ -525,24 +514,21 @@ * @param closure the closure to apply to each value */ public static void valuesDo(FrameState state, ValueClosure closure) { - do { - final int max = state.valuesSize(); - for (int i = 0; i < max; i++) { - if (state.values[i] != null) { - Value newValue = closure.apply(state.values[i]); - state.values[i] = newValue; + final int max = state.valuesSize(); + for (int i = 0; i < max; i++) { + if (state.values[i] != null) { + Value newValue = closure.apply(state.values[i]); + state.values[i] = newValue; + } + } + if (state.locks != null) { + for (int i = 0; i < state.locks.size(); i++) { + Value instr = state.locks.get(i); + if (instr != null) { + state.locks.set(i, closure.apply(instr)); } } - if (state.locks != null) { - for (int i = 0; i < state.locks.size(); i++) { - Value instr = state.locks.get(i); - if (instr != null) { - state.locks.set(i, closure.apply(instr)); - } - } - } - state = state.callerState(); - } while (state != null); + } } /** @@ -558,95 +544,36 @@ * @param proc the call back called to process each live value traversed */ public final void forEachLiveStateValue(ValueProcedure proc) { - FrameState state = this; - while (state != null) { - final int max = state.valuesSize(); - for (int i = 0; i < max; i++) { - Value value = state.values[i]; - if (value != null) { - proc.doValue(value); - } - } - state = state.callerState(); - } - } - - public static String toString(FrameState fs) { - StringBuilder sb = new StringBuilder(); - String nl = String.format("%n"); - while (fs != null) { - if (fs.scope == null) { - sb.append("").append(" [bci: ").append(fs.bci).append(']'); - break; - } else { - CiUtil.appendLocation(sb, fs.scope.method, fs.bci).append(nl); - for (int i = 0; i < fs.localsSize(); ++i) { - Value value = fs.localAt(i); - sb.append(String.format(" local[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); - } - for (int i = 0; i < fs.stackSize(); ++i) { - Value value = fs.stackAt(i); - sb.append(String.format(" stack[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); - } - for (int i = 0; i < fs.locksSize(); ++i) { - Value value = fs.lockAt(i); - sb.append(String.format(" lock[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); - } - fs = fs.callerState(); + final int max = this.valuesSize(); + for (int i = 0; i < max; i++) { + Value value = this.values[i]; + if (value != null) { + proc.doValue(value); } } - return sb.toString(); } @Override public String toString() { - return toString(this); + StringBuilder sb = new StringBuilder(); + String nl = String.format("%n"); + CiUtil.appendLocation(sb, this.method, this.bci).append(nl); + for (int i = 0; i < this.localsSize(); ++i) { + Value value = this.localAt(i); + sb.append(String.format(" local[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); + } + for (int i = 0; i < this.stackSize(); ++i) { + Value value = this.stackAt(i); + sb.append(String.format(" stack[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); + } + for (int i = 0; i < this.locksSize(); ++i) { + Value value = this.lockAt(i); + sb.append(String.format(" lock[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); + } + return sb.toString(); } public CiCodePos toCodePos() { - FrameState caller = callerState(); - CiCodePos callerCodePos = null; - if (caller != null) { - callerCodePos = caller.toCodePos(); - } - return new CiCodePos(callerCodePos, scope.method, bci); - } - - /** - * Creates a new {@code MutableFrameState} corresponding to inlining the specified method into this point in this frame state. - * @param scope the IRScope representing the inlined method - * @return a new frame state representing the state at the beginning of inlining the specified method into this one - */ - public MutableFrameState pushScope(IRScope scope) { - assert scope.caller == this.scope; - RiMethod method = scope.method; - return new MutableFrameState(scope, -1, method.maxLocals(), method.maxStackSize()); - } - - /** - * Creates a new {@code MutableFrameState} corresponding to the state upon returning from this inlined method into the outer - * IRScope. - * @return a new frame state representing the state at exit from this frame state - */ - public MutableFrameState popScope() { - IRScope callingScope = scope.caller; - assert callingScope != null; - FrameState callerState = scope.callerState; - MutableFrameState res = new MutableFrameState(callingScope, bci, callerState.maxLocals, callerState.maxStackSize() + stackIndex); - System.arraycopy(callerState.values, 0, res.values, 0, callerState.values.length); - System.arraycopy(values, maxLocals, res.values, res.maxLocals + callerState.stackIndex, stackIndex); - res.stackIndex = callerState.stackIndex + stackIndex; - assert res.stackIndex >= 0; - res.replaceLocks(callerState); - return res; - } - - /** - * Gets the caller frame state. - * - * @return the caller frame state or {@code null} if this is a top-level state - */ - public FrameState callerState() { - return scope.callerState; + return new CiCodePos(null, method, bci); } } diff -r 491896f81cae -r 274360f98f97 graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java Fri Apr 29 11:50:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java Fri Apr 29 13:19:17 2011 +0200 @@ -24,9 +24,11 @@ import java.util.*; +import com.sun.c1x.graph.*; import com.sun.c1x.ir.*; import com.sun.c1x.util.*; import com.sun.cri.ci.*; +import com.sun.cri.ri.*; /** @@ -43,8 +45,8 @@ */ public final class MutableFrameState extends FrameState { - public MutableFrameState(IRScope irScope, int bci, int maxLocals, int maxStack) { - super(irScope, bci, maxLocals, maxStack); + public MutableFrameState(RiMethod method, int bci, int maxLocals, int maxStack) { + super(method, bci, maxLocals, maxStack); } /** @@ -328,12 +330,12 @@ * @param scope the IRScope in which this locking operation occurs * @param obj the object being locked */ - public void lock(IRScope scope, Value obj, int totalNumberOfLocks) { + public void lock(IR ir, Value obj, int totalNumberOfLocks) { if (locks == null) { locks = new ArrayList(4); } locks.add(obj); - scope.updateMaxLocks(totalNumberOfLocks); + ir.updateMaxLocks(totalNumberOfLocks); } /**