# HG changeset patch # User Niclas Adlertz # Date 1395338981 0 # Node ID 2ed3233503b8feb99f1db9d7fc23c1c107c99d24 # Parent 17a735726670aadc22de25171512e96d86d6f6f0 Starting point of the baseline bytecode parser diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/KindInterface.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/KindInterface.java Thu Mar 20 18:09:41 2014 +0000 @@ -0,0 +1,9 @@ +package com.oracle.graal.api.meta; + +import com.oracle.graal.api.meta.*; + +public interface KindInterface { + + public Kind getKind(); + +} diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Thu Mar 20 18:09:41 2014 +0000 @@ -28,7 +28,7 @@ * Abstract base class for values manipulated by the compiler. All values have a {@linkplain Kind * kind} and are immutable. */ -public abstract class Value implements Serializable { +public abstract class Value implements Serializable, KindInterface { private static final long serialVersionUID = -6909397188697766469L; diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java Thu Mar 20 18:09:41 2014 +0000 @@ -42,7 +42,7 @@ import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.graph.*; import com.oracle.graal.java.*; -import com.oracle.graal.java.BciBlockMapping.Block; +import com.oracle.graal.java.BciBlockMapping.BciBlock; import com.oracle.graal.java.BciBlockMapping.ExceptionDispatchBlock; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; @@ -71,13 +71,18 @@ private ProfilingInfo profilingInfo; private BytecodeStream stream; // the bytecode stream - private Block currentBlock; + private Backend backend; + private LIRGenerator lirGen; + private LIRFrameStateBuilder frameState; + private LIRGenerationResult lirGenRes; + + private BciBlock currentBlock; private ValueNode methodSynchronizedObject; private ExceptionDispatchBlock unwindBlock; private final GraphBuilderConfiguration graphBuilderConfig; - private Block[] loopHeaders; + private BciBlock[] loopHeaders; /** * Meters the number of actual bytecodes parsed. @@ -92,6 +97,7 @@ CompilationResultBuilderFactory factory) { this.method = method; this.entryBCI = entryBCI; + this.backend = backend; profilingInfo = method.getProfilingInfo(); assert method.getCode() != null : "method must contain bytecodes: " + method; this.stream = new BytecodeStream(method.getCode()); @@ -100,58 +106,14 @@ methodSynchronizedObject = null; TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); - // build blocks + frameState = new LIRFrameStateBuilder(method); + + // build blocks and LIR instructions try { build(); } finally { filter.remove(); } - // begin fake cfg - LIRBlock b = new LIRBlock(0); - LIRBlock[] blocks = new LIRBlock[1]; - blocks[0] = b; - - AbstractControlFlowGraph cfg = new LIRControlFlowGraph(blocks, new Loop[0]); - - BlocksToDoubles blockProbabilities = new BlocksToDoubles(blocks.length); - blockProbabilities.put(b, 1); - // end fake cfg - - // emitLIR - List> linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, b, blockProbabilities); - List> codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, b, blockProbabilities); - LIR lir = new LIR(cfg, linearScanOrder, codeEmittingOrder); - - LIRGenerationResult lirGenRes = null; - - try (Scope ds = Debug.scope("BackEnd", lir)) { - FrameMap frameMap = backend.newFrameMap(); - TargetDescription target = backend.getTarget(); - CallingConvention cc = CodeUtil.getCallingConvention(backend.getProviders().getCodeCache(), CallingConvention.Type.JavaCallee, method, false); - lirGenRes = backend.newLIRGenerationResult(lir, frameMap, null); - LIRGenerator lirGen = backend.newLIRGenerator(null, cc, lirGenRes); - - try (Scope s = Debug.scope("LIRGen", lirGen)) { - for (AbstractBlock block : linearScanOrder) { - lirGen.doBlock(block, method); - } - lirGen.beforeRegisterAllocation(); - - Debug.dump(lir, "After LIR generation"); - } catch (Throwable e) { - throw Debug.handle(e); - } - - try (Scope s = Debug.scope("Allocator", lirGen)) { - if (backend.shouldAllocateRegisters()) { - new LinearScan(target, lir, frameMap).allocate(); - } - } catch (Throwable e) { - throw Debug.handle(e); - } - } catch (Throwable e) { - throw Debug.handle(e); - } // emitCode Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); @@ -166,7 +128,7 @@ TTY.println(MetaUtil.indent(MetaUtil.profileToString(profilingInfo, method, CodeUtil.NEW_LINE), " ")); } - Indent indent = Debug.logAndIndent("build graph for %s", method); + // Indent indent = Debug.logAndIndent("build graph for %s", method); // compute the block map, setup exception handlers and get the entrypoint(s) BciBlockMapping blockMap = BciBlockMapping.create(method); @@ -183,11 +145,59 @@ throw GraalInternalError.unimplemented("Handle start block as loop header"); } - /* - * for (Block block : blockMap.blocks) { processBlock(block); } - */ + // create the control flow graph + LIRControlFlowGraph cfg = new LIRControlFlowGraph(blockMap.blocks.toArray(new BciBlock[0]), new Loop[0]); + + BlocksToDoubles blockProbabilities = new BlocksToDoubles(blockMap.blocks.size()); + for (BciBlock b : blockMap.blocks) { + blockProbabilities.put(b, 1); + } + + // create the LIR + List> linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blockMap.blocks.size(), blockMap.startBlock, blockProbabilities); + List> codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blockMap.blocks.size(), blockMap.startBlock, blockProbabilities); + LIR lir = new LIR(cfg, linearScanOrder, codeEmittingOrder); + + FrameMap frameMap = backend.newFrameMap(); + TargetDescription target = backend.getTarget(); + CallingConvention cc = CodeUtil.getCallingConvention(backend.getProviders().getCodeCache(), CallingConvention.Type.JavaCallee, method, false); + this.lirGenRes = backend.newLIRGenerationResult(lir, frameMap, null); + this.lirGen = backend.newLIRGenerator(null, cc, lirGenRes); + + try (Scope ds = Debug.scope("BackEnd", lir)) { + try (Scope s = Debug.scope("LIRGen", lirGen)) { + + lirGen.emitPrologue(method); + + // possibly add all the arguments to slots in the local variable array - indent.outdent(); + for (BciBlock block : blockMap.blocks) { + + lirGen.doBlockStart(block); + + processBlock(block); + + lirGen.doBlockEnd(block); + } + // indent.outdent(); + + lirGen.beforeRegisterAllocation(); + Debug.dump(lir, "After LIR generation"); + } catch (Throwable e) { + throw Debug.handle(e); + } + + try (Scope s = Debug.scope("Allocator", lirGen)) { + + if (backend.shouldAllocateRegisters()) { + new LinearScan(target, lir, frameMap).allocate(); + } + } catch (Throwable e) { + throw Debug.handle(e); + } + } catch (Throwable e) { + throw Debug.handle(e); + } } public BytecodeStream stream() { @@ -302,7 +312,10 @@ } private void genArithmeticOp(Kind result, int opcode) { - throw GraalInternalError.unimplemented(); + Value a = frameState.ipop(); + Value b = frameState.ipop(); + Value r = lirGen.emitAdd(a, b); + frameState.ipush(r); } private void genIntegerDivOp(Kind result, int opcode) { @@ -486,7 +499,7 @@ throw GraalInternalError.unimplemented(); } - private void processBlock(Block block) { + private void processBlock(BciBlock block) { Indent indent = Debug.logAndIndent("Parsing block %s firstInstruction: %s loopHeader: %b", block, block.firstInstruction, block.isLoopHeader); currentBlock = block; iterateBytecodesForBlock(block); @@ -497,7 +510,7 @@ throw GraalInternalError.unimplemented(); } - private void iterateBytecodesForBlock(Block block) { + private void iterateBytecodesForBlock(BciBlock block) { int endBCI = stream.endBCI(); diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRControlFlowGraph.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRControlFlowGraph.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRControlFlowGraph.java Thu Mar 20 18:09:41 2014 +0000 @@ -22,19 +22,20 @@ */ package com.oracle.graal.baseline; +import com.oracle.graal.java.BciBlockMapping.BciBlock; import com.oracle.graal.nodes.cfg.*; -public class LIRControlFlowGraph implements AbstractControlFlowGraph { +public class LIRControlFlowGraph implements AbstractControlFlowGraph { - private LIRBlock[] blocks; + private BciBlock[] blocks; private Loop[] loops; - public LIRControlFlowGraph(LIRBlock[] blocks, Loop[] loops) { + public LIRControlFlowGraph(BciBlock[] blocks, Loop[] loops) { this.blocks = blocks; this.loops = loops; } - public LIRBlock[] getBlocks() { + public BciBlock[] getBlocks() { return blocks; } @@ -42,7 +43,7 @@ return loops; } - public LIRBlock getStartBlock() { + public BciBlock getStartBlock() { if (blocks.length > 0) return blocks[0]; return null; diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRFrameStateBuilder.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRFrameStateBuilder.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/LIRFrameStateBuilder.java Thu Mar 20 18:09:41 2014 +0000 @@ -4,18 +4,18 @@ import com.oracle.graal.java.*; import com.oracle.graal.lir.*; -public class LIRFrameStateBuilder extends AbstractFrameStateBuilder { +public class LIRFrameStateBuilder extends AbstractFrameStateBuilder { - private final Variable[] locals; - private final Variable[] stack; - private Variable[] lockedObjects; + private final Value[] locals; + private final Value[] stack; + private Value[] lockedObjects; public LIRFrameStateBuilder(ResolvedJavaMethod method) { super(method); - this.locals = new Variable[method.getMaxLocals()]; + this.locals = new Value[method.getMaxLocals()]; // we always need at least one stack slot (for exceptions) - this.stack = new Variable[Math.max(1, method.getMaxStackSize())]; + this.stack = new Value[Math.max(1, method.getMaxStackSize())]; } protected LIRFrameStateBuilder(LIRFrameStateBuilder other) { @@ -32,25 +32,25 @@ } @Override - public Variable localAt(int i) { + public Value localAt(int i) { return locals[i]; } @Override - public Variable stackAt(int i) { + public Value stackAt(int i) { return stack[i]; } @Override - public Variable loadLocal(int i) { - Variable x = locals[i]; + public Value loadLocal(int i) { + Value x = locals[i]; assert !isTwoSlot(x.getKind()) || locals[i + 1] == null; assert i == 0 || locals[i - 1] == null || !isTwoSlot(locals[i - 1].getKind()); return x; } @Override - public void storeLocal(int i, Variable x) { + public void storeLocal(int i, Value x) { assert x == null || x.getKind() != Kind.Void && x.getKind() != Kind.Illegal : "unexpected value: " + x; locals[i] = x; if (x != null && isTwoSlot(x.getKind())) { @@ -58,7 +58,7 @@ locals[i + 1] = null; } if (x != null && i > 0) { - Variable p = locals[i - 1]; + Value p = locals[i - 1]; if (p != null && isTwoSlot(p.getKind())) { // if there was a double word at i - 1, then kill it locals[i - 1] = null; @@ -67,13 +67,13 @@ } @Override - public void storeStack(int i, Variable x) { + public void storeStack(int i, Value x) { assert x == null || (stack[i] == null || x.getKind() == stack[i].getKind()) : "Method does not handle changes from one-slot to two-slot values or non-alive values"; stack[i] = x; } @Override - public void push(Kind kind, Variable x) { + public void push(Kind kind, Value x) { assert x.getKind() != Kind.Void && x.getKind() != Kind.Illegal; xpush(assertKind(kind, x)); if (isTwoSlot(kind)) { @@ -82,46 +82,46 @@ } @Override - public void xpush(Variable x) { + public void xpush(Value x) { assert x == null || (x.getKind() != Kind.Void && x.getKind() != Kind.Illegal); stack[stackSize++] = x; } @Override - public void ipush(Variable x) { + public void ipush(Value x) { xpush(assertInt(x)); } @Override - public void fpush(Variable x) { + public void fpush(Value x) { xpush(assertFloat(x)); } @Override - public void apush(Variable x) { + public void apush(Value x) { xpush(assertObject(x)); } @Override - public void lpush(Variable x) { + public void lpush(Value x) { xpush(assertLong(x)); } @Override - public void dpush(Variable x) { + public void dpush(Value x) { xpush(assertDouble(x)); } @Override - public void pushReturn(Kind kind, Variable x) { + public void pushReturn(Kind kind, Value x) { if (kind != Kind.Void) { push(kind.getStackKind(), x); } } @Override - public Variable pop(Kind kind) { + public Value pop(Kind kind) { assert kind != Kind.Void; if (isTwoSlot(kind)) { xpop(); @@ -130,46 +130,46 @@ } @Override - public Variable xpop() { - Variable result = stack[--stackSize]; + public Value xpop() { + Value result = stack[--stackSize]; return result; } @Override - public Variable ipop() { + public Value ipop() { return assertInt(xpop()); } @Override - public Variable fpop() { + public Value fpop() { return assertFloat(xpop()); } @Override - public Variable apop() { + public Value apop() { return assertObject(xpop()); } @Override - public Variable lpop() { + public Value lpop() { assertHigh(xpop()); return assertLong(xpop()); } @Override - public Variable dpop() { + public Value dpop() { assertHigh(xpop()); return assertDouble(xpop()); } @Override - public Variable[] popArguments(int slotSize, int argSize) { + public Value[] popArguments(int slotSize, int argSize) { int base = stackSize - slotSize; - Variable[] r = new Variable[argSize]; + Value[] r = new Value[argSize]; int argIndex = 0; int stackindex = 0; while (stackindex < slotSize) { - Variable element = stack[base + stackindex]; + Value element = stack[base + stackindex]; assert element != null; r[argIndex++] = element; stackindex += stackSlots(element.getKind()); @@ -179,7 +179,7 @@ } @Override - public Variable peek(int argumentNumber) { + public Value peek(int argumentNumber) { int idx = stackSize() - 1; for (int i = 0; i < argumentNumber; i++) { if (stackAt(idx) == null) { @@ -191,37 +191,37 @@ return stackAt(idx); } - private static Variable assertKind(Kind kind, Variable x) { + private static Value assertKind(Kind kind, Value x) { assert x != null && x.getKind() == kind : "kind=" + kind + ", value=" + x + ((x == null) ? "" : ", value.kind=" + x.getKind()); return x; } - private static Variable assertLong(Variable x) { + private static Value assertLong(Value x) { assert x != null && (x.getKind() == Kind.Long); return x; } - private static Variable assertInt(Variable x) { + private static Value assertInt(Value x) { assert x != null && (x.getKind() == Kind.Int); return x; } - private static Variable assertFloat(Variable x) { + private static Value assertFloat(Value x) { assert x != null && (x.getKind() == Kind.Float); return x; } - private static Variable assertObject(Variable x) { + private static Value assertObject(Value x) { assert x != null && (x.getKind() == Kind.Object); return x; } - private static Variable assertDouble(Variable x) { + private static Value assertDouble(Value x) { assert x != null && (x.getKind() == Kind.Double); return x; } - private static void assertHigh(Variable x) { + private static void assertHigh(Value x) { assert x == null; } } diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/BaselineLIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/BaselineLIRGenerator.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/BaselineLIRGenerator.java Thu Mar 20 18:09:41 2014 +0000 @@ -26,7 +26,4 @@ import com.oracle.graal.nodes.cfg.*; public interface BaselineLIRGenerator { - - void doBlock(AbstractBlock block, ResolvedJavaMethod method); - } diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Mar 20 18:09:41 2014 +0000 @@ -408,7 +408,7 @@ res.getLIR().getLIRforBlock(currentBlock).add(op); } - private final void doBlockStart(AbstractBlock block) { + public final void doBlockStart(AbstractBlock block) { if (printIRWithLIR) { TTY.print(block.toString()); } @@ -426,7 +426,7 @@ } } - private final void doBlockEnd(AbstractBlock block) { + public final void doBlockEnd(AbstractBlock block) { if (traceLevel >= 1) { TTY.println("END Generating LIR for block B" + block.getId()); @@ -442,22 +442,18 @@ /** * For Baseline compilation */ - public void doBlock(AbstractBlock block, ResolvedJavaMethod method) { - doBlockStart(block); - - if (block == res.getLIR().getControlFlowGraph().getStartBlock()) { - assert block.getPredecessorCount() == 0; - emitPrologue(method); - } else { - assert block.getPredecessorCount() > 0; - } - - // add instruction - Value add = emitAdd(Constant.forLong(42), Constant.forLong(73)); - emitReturn(add); - - doBlockEnd(block); - } + /* + * public void doBlock(AbstractBlock block, ResolvedJavaMethod method) { doBlockStart(block); + * + * if (block == res.getLIR().getControlFlowGraph().getStartBlock()) { assert + * block.getPredecessorCount() == 0; emitPrologue(method); } else { assert + * block.getPredecessorCount() > 0; } + * + * // add instruction Value add = emitAdd(Constant.forLong(42), Constant.forLong(73)); + * emitReturn(add); + * + * doBlockEnd(block); } + */ public void doBlock(Block block, StructuredGraph graph, BlockMap> blockMap) { doBlockStart(block); @@ -574,7 +570,7 @@ } } - protected void emitPrologue(ResolvedJavaMethod method) { + public void emitPrologue(ResolvedJavaMethod method) { CallingConvention incomingArguments = getCallingConvention(); Value[] params = new Value[incomingArguments.getArgumentCount()]; @@ -592,13 +588,15 @@ Signature sig = method.getSignature(); boolean isStatic = Modifier.isStatic(method.getModifiers()); - + Value[] arguments = new Value[sig.getParameterCount(!isStatic)]; for (int i = 0; i < sig.getParameterCount(!isStatic); i++) { Value paramValue = params[i]; assert paramValue.getKind() == sig.getParameterKind(i).getStackKind(); // TODO setResult(param, emitMove(paramValue)); - emitMove(paramValue); + arguments[i] = emitMove(paramValue); } + + // return arguments; } public void emitIncomingValues(Value[] params) { diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Mar 20 18:09:41 2014 +0000 @@ -174,7 +174,7 @@ } @Override - protected void emitPrologue(ResolvedJavaMethod method) { + public void emitPrologue(ResolvedJavaMethod method) { CallingConvention incomingArguments = getCallingConvention(); diff -r 17a735726670 -r 2ed3233503b8 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 Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Mar 20 18:09:41 2014 +0000 @@ -33,6 +33,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.cfg.*; /** * Builds a mapping between bytecodes and basic blocks and builds a conservative control flow graph @@ -73,7 +74,7 @@ */ public final class BciBlockMapping { - public static class Block implements Cloneable { + public static class BciBlock implements Cloneable, AbstractBlock { public int startBci; public int endBci; @@ -85,21 +86,21 @@ public FixedWithNextNode firstInstruction; public HIRFrameStateBuilder entryState; - public ArrayList successors = new ArrayList<>(2); + public ArrayList successors = new ArrayList<>(2); public long exits; private boolean visited; private boolean active; public long loops; - public HashMap jsrAlternatives; + public HashMap jsrAlternatives; public JsrScope jsrScope = JsrScope.EMPTY_SCOPE; - public Block jsrSuccessor; + public BciBlock jsrSuccessor; public int jsrReturnBci; - public Block retSuccessor; + public BciBlock retSuccessor; public boolean endsWithRet = false; - public Block exceptionDispatchBlock() { + public BciBlock exceptionDispatchBlock() { if (successors.size() > 0 && successors.get(successors.size() - 1) instanceof ExceptionDispatchBlock) { return successors.get(successors.size() - 1); } @@ -113,9 +114,9 @@ return successors.size(); } - public Block copy() { + public BciBlock copy() { try { - Block block = (Block) super.clone(); + BciBlock block = (BciBlock) super.clone(); block.successors = new ArrayList<>(successors); return block; } catch (CloneNotSupportedException e) { @@ -139,9 +140,82 @@ sb.append(']'); return sb.toString(); } + + public int getId() { + return blockID; + } + + public Loop getLoop() { + // TODO Auto-generated method stub + return null; + } + + public int getLoopDepth() { + // TODO Auto-generated method stub + return 0; + } + + public boolean isLoopHeader() { + return isLoopHeader; + } + + public boolean isLoopEnd() { + // TODO Auto-generated method stub + return false; + } + + public boolean isExceptionEntry() { + // TODO Auto-generated method stub + return false; + } + + public List getPredecessors() { + // TODO Auto-generated method stub + return null; + } + + public int getPredecessorCount() { + // TODO Auto-generated method stub + return 0; + } + + public List getSuccessors() { + // TODO Auto-generated method stub + return null; + } + + public int getSuccessorCount() { + // TODO Auto-generated method stub + return 0; + } + + public int getLinearScanNumber() { + // TODO Auto-generated method stub + return 0; + } + + public void setLinearScanNumber(int linearScanNumber) { + // TODO Auto-generated method stub + + } + + public boolean isAligned() { + // TODO Auto-generated method stub + return false; + } + + public void setAlign(boolean align) { + // TODO Auto-generated method stub + + } + + public BciBlock getDominator() { + // TODO Auto-generated method stub + return null; + } } - public static class ExceptionDispatchBlock extends Block { + public static class ExceptionDispatchBlock extends BciBlock { private HashMap exceptionDispatch = new HashMap<>(); @@ -152,15 +226,15 @@ /** * The blocks found in this method, in reverse postorder. */ - public final List blocks; + public final List blocks; public final ResolvedJavaMethod method; public boolean hasJsrBytecodes; - public Block startBlock; + public BciBlock startBlock; private final BytecodeStream stream; private final ExceptionHandler[] exceptionHandlers; - private Block[] blockMap; - public Block[] loopHeaders; + private BciBlock[] blockMap; + public BciBlock[] loopHeaders; public LocalLiveness liveness; @@ -173,9 +247,9 @@ this.method = method; exceptionHandlers = method.getExceptionHandlers(); stream = new BytecodeStream(method.getCode()); - this.blockMap = new Block[method.getCodeSize()]; + this.blockMap = new BciBlock[method.getCodeSize()]; this.blocks = new ArrayList<>(); - this.loopHeaders = new Block[64]; + this.loopHeaders = new BciBlock[64]; } /** @@ -218,11 +292,11 @@ } private boolean verify() { - for (Block block : blocks) { + for (BciBlock block : blocks) { assert blocks.get(block.blockID) == block; for (int i = 0; i < block.successors.size(); i++) { - Block sux = block.successors.get(i); + BciBlock sux = block.successors.get(i); if (sux instanceof ExceptionDispatchBlock) { assert i == block.successors.size() - 1 : "Only one exception handler allowed, and it must be last in successors list"; } @@ -241,7 +315,7 @@ private void makeExceptionEntries() { // start basic blocks at all exception handler blocks and mark them as exception entries for (ExceptionHandler h : this.exceptionHandlers) { - Block xhandler = makeBlock(h.getHandlerBCI()); + BciBlock xhandler = makeBlock(h.getHandlerBCI()); xhandler.isExceptionEntry = true; } } @@ -250,13 +324,13 @@ // iterate over the bytecodes top to bottom. // mark the entrypoints of basic blocks and build lists of successors for // all bytecodes that end basic blocks (i.e. goto, ifs, switches, throw, jsr, returns, ret) - Block current = null; + BciBlock current = null; stream.setBCI(0); while (stream.currentBC() != Bytecodes.END) { int bci = stream.currentBCI(); if (current == null || blockMap[bci] != null) { - Block b = makeBlock(bci); + BciBlock b = makeBlock(bci); if (current != null) { addSuccessor(current.endBci, b); } @@ -327,7 +401,7 @@ if (target == 0) { throw new JsrNotSupportedBailout("jsr target bci 0 not allowed"); } - Block b1 = makeBlock(target); + BciBlock b1 = makeBlock(target); current.jsrSuccessor = b1; current.jsrReturnBci = stream.nextBCI(); current = null; @@ -382,10 +456,10 @@ } } - private Block makeBlock(int startBci) { - Block oldBlock = blockMap[startBci]; + private BciBlock makeBlock(int startBci) { + BciBlock oldBlock = blockMap[startBci]; if (oldBlock == null) { - Block newBlock = new Block(); + BciBlock newBlock = new BciBlock(); newBlock.startBci = startBci; blockMap[startBci] = newBlock; return newBlock; @@ -393,7 +467,7 @@ } else if (oldBlock.startBci != startBci) { // Backward branch into the middle of an already processed block. // Add the correct fall-through successor. - Block newBlock = new Block(); + BciBlock newBlock = new BciBlock(); newBlock.startBci = startBci; newBlock.endBci = oldBlock.endBci; newBlock.successors.addAll(oldBlock.successors); @@ -424,17 +498,17 @@ } } - private void addSuccessor(int predBci, Block sux) { - Block predecessor = blockMap[predBci]; + private void addSuccessor(int predBci, BciBlock sux) { + BciBlock predecessor = blockMap[predBci]; if (sux.isExceptionEntry) { throw new BailoutException("Exception handler can be reached by both normal and exceptional control flow"); } predecessor.successors.add(sux); } - private final ArrayList jsrVisited = new ArrayList<>(); + private final ArrayList jsrVisited = new ArrayList<>(); - private void createJsrAlternatives(Block block) { + private void createJsrAlternatives(BciBlock block) { jsrVisited.add(block); JsrScope scope = block.jsrScope; @@ -447,7 +521,7 @@ if (block.jsrSuccessor != null || !scope.isEmpty()) { for (int i = 0; i < block.successors.size(); i++) { - Block successor = block.successors.get(i); + BciBlock successor = block.successors.get(i); JsrScope nextScope = scope; if (successor == block.jsrSuccessor) { nextScope = scope.push(block.jsrReturnBci); @@ -459,7 +533,7 @@ throw new JsrNotSupportedBailout("unstructured control flow (" + successor.jsrScope + " " + nextScope + ")"); } if (!nextScope.isEmpty()) { - Block clone; + BciBlock clone; if (successor.jsrAlternatives != null && successor.jsrAlternatives.containsKey(nextScope)) { clone = successor.jsrAlternatives.get(nextScope); } else { @@ -480,7 +554,7 @@ } } } - for (Block successor : block.successors) { + for (BciBlock successor : block.successors) { if (!jsrVisited.contains(successor)) { createJsrAlternatives(successor); } @@ -526,7 +600,7 @@ private void fixLoopBits() { do { loopChanges = false; - for (Block b : blocks) { + for (BciBlock b : blocks) { b.visited = false; } @@ -563,13 +637,13 @@ String n = System.lineSeparator(); StringBuilder sb = new StringBuilder(Debug.currentScope()).append("BlockMap ").append(name).append(" :"); sb.append(n); - Iterable it; + Iterable it; if (blocks.isEmpty()) { it = new HashSet<>(Arrays.asList(blockMap)); } else { it = blocks; } - for (Block b : it) { + for (BciBlock b : it) { if (b == null) { continue; } @@ -581,7 +655,7 @@ sb.append(" ExceptionEntry"); } sb.append(n).append(" Sux : "); - for (Block s : b.successors) { + for (BciBlock s : b.successors) { sb.append("B").append(s.blockID).append(" (").append(s.startBci).append(" -> ").append(s.endBci).append(")"); if (s.isExceptionEntry) { sb.append("!"); @@ -625,7 +699,7 @@ * Mark the block as a loop header, using the next available loop number. Also checks for corner * cases that we don't want to compile. */ - private void makeLoopHeader(Block block) { + private void makeLoopHeader(BciBlock block) { if (!block.isLoopHeader) { block.isLoopHeader = true; @@ -655,11 +729,11 @@ } /** - * Depth-first traversal of the control flow graph. The flag {@linkplain Block#visited} is used - * to visit every block only once. The flag {@linkplain Block#active} is used to detect cycles + * Depth-first traversal of the control flow graph. The flag {@linkplain BciBlock#visited} is used + * to visit every block only once. The flag {@linkplain BciBlock#active} is used to detect cycles * (backward edges). */ - private long computeBlockOrder(Block block) { + private long computeBlockOrder(BciBlock block) { if (block.visited) { if (block.active) { // Reached block via backward branch. @@ -677,7 +751,7 @@ block.active = true; long loops = 0; - for (Block successor : block.successors) { + for (BciBlock successor : block.successors) { // Recursively process successors. loops |= computeBlockOrder(successor); } @@ -695,7 +769,7 @@ return loops; } - private long fixLoopBits(Block block) { + private long fixLoopBits(BciBlock block) { if (block.visited) { // Return cached loop information for this block. if (block.isLoopHeader) { @@ -707,11 +781,11 @@ block.visited = true; long loops = block.loops; - for (Block successor : block.successors) { + for (BciBlock successor : block.successors) { // Recursively process successors. loops |= fixLoopBits(successor); } - for (Block successor : block.successors) { + for (BciBlock successor : block.successors) { successor.exits = loops & ~successor.loops; } if (block.loops != loops) { @@ -734,7 +808,7 @@ public abstract class LocalLiveness { private void computeLiveness() { - for (Block block : blocks) { + for (BciBlock block : blocks) { computeLocalLiveness(block); } @@ -744,7 +818,7 @@ Debug.log("Iteration %d", iteration); changed = false; for (int i = blocks.size() - 1; i >= 0; i--) { - Block block = blocks.get(i); + BciBlock block = blocks.get(i); int blockID = block.blockID; // log statements in IFs because debugLiveX creates a new String if (Debug.isLogEnabled()) { @@ -755,7 +829,7 @@ boolean blockChanged = (iteration == 0); if (block.successors.size() > 0) { int oldCardinality = liveOutCardinality(blockID); - for (Block sux : block.successors) { + for (BciBlock sux : block.successors) { if (Debug.isLogEnabled()) { Debug.log(" Successor B%d: %s", sux.blockID, debugLiveIn(sux.blockID)); } @@ -780,12 +854,12 @@ /** * Returns whether the local is live at the beginning of the given block. */ - public abstract boolean localIsLiveIn(Block block, int local); + public abstract boolean localIsLiveIn(BciBlock block, int local); /** * Returns whether the local is live at the end of the given block. */ - public abstract boolean localIsLiveOut(Block block, int local); + public abstract boolean localIsLiveOut(BciBlock block, int local); /** * Returns a string representation of the liveIn values of the given block. @@ -832,7 +906,7 @@ */ protected abstract void storeOne(int blockID, int local); - private void computeLocalLiveness(Block block) { + private void computeLocalLiveness(BciBlock block) { if (block.startBci < 0 || block.endBci < 0) { return; } @@ -1043,13 +1117,13 @@ } @Override - public boolean localIsLiveIn(Block block, int local) { + public boolean localIsLiveIn(BciBlock block, int local) { int blockID = block.blockID; return blockID >= Integer.MAX_VALUE ? false : (localsLiveIn[blockID] & (1L << local)) != 0L; } @Override - public boolean localIsLiveOut(Block block, int local) { + public boolean localIsLiveOut(BciBlock block, int local) { int blockID = block.blockID; return blockID >= Integer.MAX_VALUE ? false : (localsLiveOut[blockID] & (1L << local)) != 0L; } @@ -1128,12 +1202,12 @@ } @Override - public boolean localIsLiveIn(Block block, int local) { + public boolean localIsLiveIn(BciBlock block, int local) { return block.blockID >= Integer.MAX_VALUE ? true : localsLiveIn[block.blockID].get(local); } @Override - public boolean localIsLiveOut(Block block, int local) { + public boolean localIsLiveOut(BciBlock block, int local) { return block.blockID >= Integer.MAX_VALUE ? true : localsLiveOut[block.blockID].get(local); } } diff -r 17a735726670 -r 2ed3233503b8 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 Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Mar 20 18:09:41 2014 +0000 @@ -40,7 +40,7 @@ import com.oracle.graal.bytecode.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; -import com.oracle.graal.java.BciBlockMapping.Block; +import com.oracle.graal.java.BciBlockMapping.BciBlock; import com.oracle.graal.java.BciBlockMapping.ExceptionDispatchBlock; import com.oracle.graal.java.BciBlockMapping.LocalLiveness; import com.oracle.graal.nodes.*; @@ -119,7 +119,7 @@ protected HIRFrameStateBuilder frameState; // the current execution state private BytecodeParseHelper parseHelper; - private Block currentBlock; + private BciBlock currentBlock; private ValueNode methodSynchronizedObject; private ExceptionDispatchBlock unwindBlock; @@ -160,7 +160,7 @@ } } - private Block[] loopHeaders; + private BciBlock[] loopHeaders; private LocalLiveness liveness; /** @@ -261,7 +261,7 @@ blockMap.startBlock.firstInstruction = lastInstr; } - for (Block block : blockMap.blocks) { + for (BciBlock block : blockMap.blocks) { processBlock(block); } processBlock(unwindBlock); @@ -287,7 +287,7 @@ indent.outdent(); } - private Block unwindBlock(int bci) { + private BciBlock unwindBlock(int bci) { if (unwindBlock == null) { unwindBlock = new ExceptionDispatchBlock(); unwindBlock.startBci = -1; @@ -426,7 +426,7 @@ assert bci == FrameState.BEFORE_BCI || bci == bci() : "invalid bci"; Debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, profilingInfo.getExceptionSeen(bci)); - Block dispatchBlock = currentBlock.exceptionDispatchBlock(); + BciBlock dispatchBlock = currentBlock.exceptionDispatchBlock(); /* * The exception dispatch block is always for the last bytecode of a block, so if we are * not at the endBci yet, there is no exception handler for this bci and we can unwind @@ -734,8 +734,8 @@ private void ifNode(ValueNode x, Condition cond, ValueNode y) { assert !x.isDeleted() && !y.isDeleted(); assert currentBlock.numNormalSuccessors() == 2; - Block trueBlock = currentBlock.successors.get(0); - Block falseBlock = currentBlock.successors.get(1); + BciBlock trueBlock = currentBlock.successors.get(0); + BciBlock falseBlock = currentBlock.successors.get(1); if (trueBlock == falseBlock) { appendGoto(createTarget(trueBlock, frameState)); return; @@ -1232,7 +1232,7 @@ InvokeWithExceptionNode invoke = createInvokeWithException(callTarget, resultType); - Block nextBlock = currentBlock.successors.get(0); + BciBlock nextBlock = currentBlock.successors.get(0); invoke.setNext(createTarget(nextBlock, frameState)); } } @@ -1251,7 +1251,7 @@ DispatchBeginNode exceptionEdge = handleException(null, bci()); InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionEdge, bci())); frameState.pushReturn(resultType, invoke); - Block nextBlock = currentBlock.successors.get(0); + BciBlock nextBlock = currentBlock.successors.get(0); invoke.setStateAfter(frameState.create(nextBlock.startBci)); return invoke; } @@ -1289,7 +1289,7 @@ } private void genJsr(int dest) { - Block successor = currentBlock.jsrSuccessor; + BciBlock successor = currentBlock.jsrSuccessor; assert successor.startBci == dest : successor.startBci + " != " + dest + " @" + bci(); JsrScope scope = currentBlock.jsrScope; if (!successor.jsrScope.pop().equals(scope)) { @@ -1303,7 +1303,7 @@ } private void genRet(int localIndex) { - Block successor = currentBlock.retSuccessor; + BciBlock successor = currentBlock.retSuccessor; ValueNode local = frameState.loadLocal(localIndex); JsrScope scope = currentBlock.jsrScope; int retAddress = scope.nextReturnAddress(); @@ -1368,7 +1368,7 @@ } } - ArrayList actualSuccessors = new ArrayList<>(); + ArrayList actualSuccessors = new ArrayList<>(); int[] keys = new int[nofCases]; int[] keySuccessors = new int[nofCases + 1]; int deoptSuccessorIndex = -1; @@ -1463,7 +1463,7 @@ } } - private Target checkLoopExit(FixedNode target, Block targetBlock, HIRFrameStateBuilder state) { + private Target checkLoopExit(FixedNode target, BciBlock targetBlock, HIRFrameStateBuilder state) { if (currentBlock != null) { long exits = currentBlock.loops & ~targetBlock.loops; if (exits != 0) { @@ -1471,7 +1471,7 @@ LoopExitNode lastLoopExit = null; int pos = 0; - ArrayList exitLoops = new ArrayList<>(Long.bitCount(exits)); + ArrayList exitLoops = new ArrayList<>(Long.bitCount(exits)); do { long lMask = 1L << pos; if ((exits & lMask) != 0) { @@ -1481,10 +1481,10 @@ pos++; } while (exits != 0); - Collections.sort(exitLoops, new Comparator() { + Collections.sort(exitLoops, new Comparator() { @Override - public int compare(Block o1, Block o2) { + public int compare(BciBlock o1, BciBlock o2) { return Long.bitCount(o2.loops) - Long.bitCount(o1.loops); } }); @@ -1494,7 +1494,7 @@ bci = ((ExceptionDispatchBlock) targetBlock).deoptBci; } HIRFrameStateBuilder newState = state.copy(); - for (Block loop : exitLoops) { + for (BciBlock loop : exitLoops) { LoopBeginNode loopBegin = (LoopBeginNode) loop.firstInstruction; LoopExitNode loopExit = currentGraph.add(new LoopExitNode(loopBegin)); if (lastLoopExit != null) { @@ -1516,7 +1516,7 @@ return new Target(target, state); } - private FixedNode createTarget(double probability, Block block, HIRFrameStateBuilder stateAfter) { + private FixedNode createTarget(double probability, BciBlock block, HIRFrameStateBuilder stateAfter) { assert probability >= 0 && probability <= 1.01 : probability; if (isNeverExecutedCode(probability)) { return currentGraph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); @@ -1530,7 +1530,7 @@ return probability == 0 && optimisticOpts.removeNeverExecutedCode() && entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI; } - private FixedNode createTarget(Block block, HIRFrameStateBuilder state) { + private FixedNode createTarget(BciBlock block, HIRFrameStateBuilder state) { assert block != null && state != null; assert !block.isExceptionEntry || state.stackSize() == 1; @@ -1610,7 +1610,7 @@ * Returns a block begin node with the specified state. If the specified probability is 0, * the block deoptimizes immediately. */ - private AbstractBeginNode createBlockTarget(double probability, Block block, HIRFrameStateBuilder stateAfter) { + private AbstractBeginNode createBlockTarget(double probability, BciBlock block, HIRFrameStateBuilder stateAfter) { FixedNode target = createTarget(probability, block, stateAfter); AbstractBeginNode begin = AbstractBeginNode.begin(target); @@ -1627,7 +1627,7 @@ } } - private void processBlock(Block block) { + private void processBlock(BciBlock block) { // Ignore blocks that have no predecessors by the time their bytecodes are parsed if (block == null || block.firstInstruction == null) { Debug.log("Ignoring block %s", block); @@ -1718,7 +1718,7 @@ ResolvedJavaType resolvedCatchType = (ResolvedJavaType) catchType; for (ResolvedJavaType skippedType : graphBuilderConfig.getSkippedExceptionTypes()) { if (skippedType.isAssignableFrom(resolvedCatchType)) { - Block nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1); + BciBlock nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1); ValueNode exception = frameState.stackAt(0); FixedNode trueSuccessor = currentGraph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); FixedNode nextDispatch = createTarget(nextBlock, frameState); @@ -1729,7 +1729,7 @@ } if (initialized) { - Block nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1); + BciBlock nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1); ValueNode exception = frameState.stackAt(0); CheckCastNode checkCast = currentGraph.add(new CheckCastNode((ResolvedJavaType) catchType, exception, null, false)); frameState.apop(); @@ -1755,7 +1755,7 @@ return n instanceof ControlSplitNode || n instanceof ControlSinkNode; } - private void iterateBytecodesForBlock(Block block) { + private void iterateBytecodesForBlock(BciBlock block) { if (block.isLoopHeader) { // Create the loop header block, which later will merge the backward branches of the // loop. diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java Thu Mar 20 18:09:41 2014 +0000 @@ -32,7 +32,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.Node.Verbosity; -import com.oracle.graal.java.BciBlockMapping.Block; +import com.oracle.graal.java.BciBlockMapping.BciBlock; import com.oracle.graal.java.BciBlockMapping.LocalLiveness; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; @@ -316,7 +316,7 @@ } } - public void clearNonLiveLocals(Block block, LocalLiveness liveness, boolean liveIn) { + public void clearNonLiveLocals(BciBlock block, LocalLiveness liveness, boolean liveIn) { if (liveness == null) { return; } diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Thu Mar 20 18:09:41 2014 +0000 @@ -30,7 +30,7 @@ * Represents a value that is yet to be bound to a machine location (such as a {@link RegisterValue} * or {@link StackSlot}) by a register allocator. */ -public final class Variable extends AllocatableValue implements KindInterface { +public final class Variable extends AllocatableValue { private static final long serialVersionUID = 4507578431686109809L; diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/KindInterface.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/KindInterface.java Thu Mar 20 13:50:21 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -package com.oracle.graal.nodes; - -import com.oracle.graal.api.meta.*; - -public interface KindInterface { - - public Kind getKind(); - -} diff -r 17a735726670 -r 2ed3233503b8 graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Thu Mar 20 13:50:21 2014 +0100 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Thu Mar 20 18:09:41 2014 +0000 @@ -73,7 +73,7 @@ public void printCFG(String label, BciBlockMapping blockMap) { begin("cfg"); out.print("name \"").print(label).println('"'); - for (BciBlockMapping.Block block : blockMap.blocks) { + for (BciBlockMapping.BciBlock block : blockMap.blocks) { begin("block"); printBlock(block); end("block"); @@ -81,7 +81,7 @@ end("cfg"); } - private void printBlock(BciBlockMapping.Block block) { + private void printBlock(BciBlockMapping.BciBlock block) { out.print("name \"B").print(block.startBci).println('"'); out.print("from_bci ").println(block.startBci); out.print("to_bci ").println(block.endBci); @@ -89,7 +89,7 @@ out.println("predecessors "); out.print("successors "); - for (BciBlockMapping.Block succ : block.successors) { + for (BciBlockMapping.BciBlock succ : block.successors) { if (!succ.isExceptionEntry) { out.print("\"B").print(succ.startBci).print("\" "); } @@ -97,7 +97,7 @@ out.println(); out.print("xhandlers"); - for (BciBlockMapping.Block succ : block.successors) { + for (BciBlockMapping.BciBlock succ : block.successors) { if (succ.isExceptionEntry) { out.print("\"B").print(succ.startBci).print("\" "); }