# HG changeset patch # User Lukas Stadler # Date 1366723941 -7200 # Node ID 931bd99780a700516269ac60618433c23da9fa59 # Parent c4561d60fd9aa8afeced637d539780d7a2618e8f# Parent dd596345f28a6745c795a8a6774e5715115cb7fc Merge diff -r c4561d60fd9a -r 931bd99780a7 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierAdditionTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierAdditionTest.java Tue Apr 23 15:21:20 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierAdditionTest.java Tue Apr 23 15:32:21 2013 +0200 @@ -49,8 +49,7 @@ main.b = temp2; } - public static void test2Snippet() { - boolean test = true; + public static void test2Snippet(boolean test) { Container main = new Container(); Container temp1 = new Container(); Container temp2 = new Container(); @@ -58,11 +57,9 @@ if (test) { main.a = temp1; main.b = temp2; - test = false; } else { main.a = temp2; main.b = temp1; - test = true; } } } @@ -109,7 +106,7 @@ for (WriteNode write : graph.getNodes(WriteNode.class)) { if (write.getWriteBarrierType() != WriteBarrierType.NONE) { Assert.assertTrue(write.successors().count() == 1); - Assert.assertTrue(write.successors().first() instanceof SerialWriteBarrier); + Assert.assertTrue(write.next() instanceof SerialWriteBarrier); } } } diff -r c4561d60fd9a -r 931bd99780a7 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 Tue Apr 23 15:21:20 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Tue Apr 23 15:32:21 2013 +0200 @@ -43,11 +43,11 @@ import com.oracle.graal.hotspot.stubs.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.ParametersOp; +import com.oracle.graal.lir.StandardOp.PlaceholderOp; import com.oracle.graal.lir.amd64.*; import com.oracle.graal.lir.amd64.AMD64Move.CompareAndSwapOp; import com.oracle.graal.lir.amd64.AMD64Move.MoveFromRegOp; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind; /** @@ -71,15 +71,43 @@ StackSlot deoptimizationRescueSlot; /** - * The position at which the instruction for saving RBP should be inserted. + * Utility for emitting the instruction to save RBP. */ - Block saveRbpBlock; - int saveRbpIndex; + class SaveRbp { + + final PlaceholderOp placeholder; + + /** + * The slot reserved for saving RBP. + */ + final StackSlot reservedSlot; + + public SaveRbp(PlaceholderOp placeholder) { + this.placeholder = placeholder; + this.reservedSlot = frameMap.allocateSpillSlot(Kind.Long); + assert reservedSlot.getRawOffset() == -16 : reservedSlot.getRawOffset(); + } - /** - * The slot reserved for saving RBP. - */ - StackSlot rbpSlot; + /** + * Replaces this operation with the appropriate move for saving rbp. + * + * @param useStack specifies if rbp must be saved to the stack + */ + public AllocatableValue finalize(boolean useStack) { + AllocatableValue dst; + if (useStack) { + dst = reservedSlot; + } else { + frameMap.freeSpillSlot(reservedSlot); + dst = newVariable(Kind.Long); + } + + placeholder.replace(lir, new MoveFromRegOp(dst, rbp.asValue(Kind.Long))); + return dst; + } + } + + private SaveRbp saveRbp; /** * List of epilogue operations that need to restore RBP. @@ -119,11 +147,9 @@ ParametersOp paramsOp = new ParametersOp(params); append(paramsOp); - saveRbpBlock = currentBlock; - saveRbpIndex = lir.lir(saveRbpBlock).size(); - append(paramsOp); // placeholder - rbpSlot = frameMap.allocateSpillSlot(Kind.Long); - assert rbpSlot.getRawOffset() == -16 : rbpSlot.getRawOffset(); + + saveRbp = new SaveRbp(new PlaceholderOp(currentBlock, lir.lir(currentBlock).size())); + append(saveRbp.placeholder); for (LocalNode local : graph.getNodes(LocalNode.class)) { Value param = params[local.index()]; @@ -238,23 +264,14 @@ @Override public void beforeRegisterAllocation() { - assert rbpSlot != null; - RegisterValue rbpParam = rbp.asValue(Kind.Long); - AllocatableValue savedRbp; - LIRInstruction saveRbp; - if (lir.hasDebugInfo()) { - savedRbp = rbpSlot; + boolean hasDebugInfo = lir.hasDebugInfo(); + AllocatableValue savedRbp = saveRbp.finalize(hasDebugInfo); + if (hasDebugInfo) { deoptimizationRescueSlot = frameMap.allocateSpillSlot(Kind.Long); - } else { - frameMap.freeSpillSlot(rbpSlot); - savedRbp = newVariable(Kind.Long); } for (AMD64HotSpotEpilogueOp op : epilogueOps) { op.savedRbp = savedRbp; } - - saveRbp = new MoveFromRegOp(savedRbp, rbpParam); - lir.lir(saveRbpBlock).set(saveRbpIndex, saveRbp); } } diff -r c4561d60fd9a -r 931bd99780a7 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Tue Apr 23 15:21:20 2013 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Tue Apr 23 15:32:21 2013 +0200 @@ -24,7 +24,10 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; +import com.oracle.graal.graph.*; import com.oracle.graal.lir.asm.*; +import com.oracle.graal.nodes.cfg.*; + import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; /** @@ -135,4 +138,34 @@ // No code to emit. } } + + /** + * Placeholder for a LIR instruction that will be subsequently replaced. + */ + public static class PlaceholderOp extends LIRInstruction { + + /** + * The block in which this instruction is located. + */ + final Block block; + + /** + * The block index of this instruction. + */ + final int index; + + public PlaceholderOp(Block block, int index) { + this.block = block; + this.index = index; + } + + public void replace(LIR lir, LIRInstruction replacement) { + lir.lir(block).set(index, replacement); + } + + @Override + public void emitCode(TargetMethodAssembler tasm) { + throw new GraalInternalError(this + " should have been replaced"); + } + } }