--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java 2017-03-20 17:39:48.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java 2017-03-20 17:39:48.000000000 -0700 @@ -22,23 +22,21 @@ */ package org.graalvm.compiler.lir.alloc.lsra; -import static org.graalvm.compiler.core.common.GraalOptions.DetailedAsserts; -import static org.graalvm.compiler.lir.LIRValueUtil.asVariable; -import static org.graalvm.compiler.lir.LIRValueUtil.isVariable; -import static org.graalvm.compiler.lir.debug.LIRGenerationDebugContext.getSourceForOperandFromDebugContext; import static jdk.vm.ci.code.ValueUtil.asRegister; import static jdk.vm.ci.code.ValueUtil.asStackSlot; import static jdk.vm.ci.code.ValueUtil.isRegister; import static jdk.vm.ci.code.ValueUtil.isStackSlot; +import static org.graalvm.compiler.core.common.GraalOptions.DetailedAsserts; +import static org.graalvm.compiler.lir.LIRValueUtil.asVariable; +import static org.graalvm.compiler.lir.LIRValueUtil.isVariable; +import static org.graalvm.compiler.lir.debug.LIRGenerationDebugContext.getSourceForOperandFromDebugContext; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.BitSet; -import java.util.Deque; import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; -import org.graalvm.compiler.common.PermanentBailoutException; +import org.graalvm.compiler.core.common.PermanentBailoutException; import org.graalvm.compiler.core.common.LIRKind; import org.graalvm.compiler.core.common.alloc.ComputeBlockOrder; import org.graalvm.compiler.core.common.cfg.AbstractBlockBase; @@ -59,6 +57,8 @@ import org.graalvm.compiler.lir.alloc.lsra.LinearScan.BlockData; import org.graalvm.compiler.lir.gen.LIRGenerationResult; import org.graalvm.compiler.lir.phases.AllocationPhase; +import org.graalvm.util.EconomicSet; +import org.graalvm.util.Equivalence; import jdk.vm.ci.code.Register; import jdk.vm.ci.code.RegisterArray; @@ -87,7 +87,7 @@ allocator.printLir("Before register allocation", true); computeLocalLiveSets(); computeGlobalLiveSets(); - buildIntervals(); + buildIntervals(DetailedAsserts.getValue(allocator.getOptions())); } /** @@ -127,7 +127,7 @@ for (AbstractBlockBase block : allocator.sortedBlocks()) { allocator.initBlockData(block); - List instructions = allocator.getLIR().getLIRforBlock(block); + ArrayList instructions = allocator.getLIR().getLIRforBlock(block); int numInst = instructions.size(); for (int j = 0; j < numInst; j++) { @@ -165,7 +165,7 @@ final BitSet liveGen = new BitSet(liveSize); final BitSet liveKill = new BitSet(liveSize); - List instructions = allocator.getLIR().getLIRforBlock(block); + ArrayList instructions = allocator.getLIR().getLIRforBlock(block); int numInst = instructions.size(); ValueConsumer useConsumer = (operand, mode, flags) -> { @@ -182,7 +182,7 @@ } } - if (DetailedAsserts.getValue()) { + if (allocator.detailedAsserts) { verifyInput(block, liveKill, operand); } }; @@ -209,7 +209,7 @@ } } - if (DetailedAsserts.getValue()) { + if (allocator.detailedAsserts) { /* * Fixed intervals are never live at block boundaries, so they need not be * processed in live sets. Process them only in debug mode so that this can @@ -355,7 +355,7 @@ if (changeOccurred && iterationCount > 50) { /* - * Very unlikely should never happen: If it happens we cannot guarantee it + * Very unlikely, should never happen: If it happens we cannot guarantee it * won't happen again. */ throw new PermanentBailoutException("too many iterations in computeGlobalLiveSets"); @@ -363,14 +363,14 @@ } } while (changeOccurred); - if (DetailedAsserts.getValue()) { + if (DetailedAsserts.getValue(allocator.getOptions())) { verifyLiveness(); } // check that the liveIn set of the first block is empty AbstractBlockBase startBlock = allocator.getLIR().getControlFlowGraph().getStartBlock(); if (allocator.getBlockData(startBlock).liveIn.cardinality() != 0) { - if (DetailedAsserts.getValue()) { + if (DetailedAsserts.getValue(allocator.getOptions())) { reportFailure(numBlocks); } // bailout if this occurs in product mode. @@ -408,8 +408,8 @@ } try (Indent indent2 = Debug.logAndIndent("---- Detailed information for var %d; operand=%s; node=%s ----", operandNum, operand, valueForOperandFromDebugContext)) { - Deque> definedIn = new ArrayDeque<>(); - HashSet> usedIn = new HashSet<>(); + ArrayDeque> definedIn = new ArrayDeque<>(); + EconomicSet> usedIn = EconomicSet.create(Equivalence.IDENTITY); for (AbstractBlockBase block : allocator.sortedBlocks()) { if (allocator.getBlockData(block).liveGen.get(operandNum)) { usedIn.add(block); @@ -478,7 +478,7 @@ } } - protected void addUse(AllocatableValue operand, int from, int to, RegisterPriority registerPriority, ValueKind kind) { + protected void addUse(AllocatableValue operand, int from, int to, RegisterPriority registerPriority, ValueKind kind, boolean detailedAsserts) { if (!allocator.isProcessed(operand)) { return; } @@ -491,14 +491,14 @@ interval.addRange(from, to); // Register use position at even instruction id. - interval.addUsePos(to & ~1, registerPriority); + interval.addUsePos(to & ~1, registerPriority, detailedAsserts); if (Debug.isLogEnabled()) { Debug.log("add use: %s, from %d to %d (%s)", interval, from, to, registerPriority.name()); } } - protected void addTemp(AllocatableValue operand, int tempPos, RegisterPriority registerPriority, ValueKind kind) { + protected void addTemp(AllocatableValue operand, int tempPos, RegisterPriority registerPriority, ValueKind kind, boolean detailedAsserts) { if (!allocator.isProcessed(operand)) { return; } @@ -509,7 +509,7 @@ } interval.addRange(tempPos, tempPos + 1); - interval.addUsePos(tempPos, registerPriority); + interval.addUsePos(tempPos, registerPriority, detailedAsserts); interval.addMaterializationValue(null); if (Debug.isLogEnabled()) { @@ -517,7 +517,7 @@ } } - protected void addDef(AllocatableValue operand, LIRInstruction op, RegisterPriority registerPriority, ValueKind kind) { + protected void addDef(AllocatableValue operand, LIRInstruction op, RegisterPriority registerPriority, ValueKind kind, boolean detailedAsserts) { if (!allocator.isProcessed(operand)) { return; } @@ -535,14 +535,14 @@ * beginning of the current block until a def is encountered). */ r.from = defPos; - interval.addUsePos(defPos, registerPriority); + interval.addUsePos(defPos, registerPriority, detailedAsserts); } else { /* * Dead value - make vacuous interval also add register priority for dead intervals */ interval.addRange(defPos, defPos + 1); - interval.addUsePos(defPos, registerPriority); + interval.addUsePos(defPos, registerPriority, detailedAsserts); if (Debug.isLogEnabled()) { Debug.log("Warning: def of operand %s at %d occurs without use", operand, defPos); } @@ -569,7 +569,7 @@ ValueMoveOp move = (ValueMoveOp) op; if (optimizeMethodArgument(move.getInput())) { StackSlot slot = asStackSlot(move.getInput()); - if (DetailedAsserts.getValue()) { + if (DetailedAsserts.getValue(allocator.getOptions())) { assert op.id() > 0 : "invalid id"; assert allocator.blockForId(op.id()).getPredecessorCount() == 0 : "move from stack must be in first block"; assert isVariable(move.getResult()) : "result of move must be a variable"; @@ -683,19 +683,19 @@ } @SuppressWarnings("try") - protected void buildIntervals() { + protected void buildIntervals(boolean detailedAsserts) { try (Indent indent = Debug.logAndIndent("build intervals")) { InstructionValueConsumer outputConsumer = (op, operand, mode, flags) -> { if (LinearScan.isVariableOrRegister(operand)) { - addDef((AllocatableValue) operand, op, registerPriorityOfOutputOperand(op), operand.getValueKind()); + addDef((AllocatableValue) operand, op, registerPriorityOfOutputOperand(op), operand.getValueKind(), detailedAsserts); addRegisterHint(op, operand, mode, flags, true); } }; InstructionValueConsumer tempConsumer = (op, operand, mode, flags) -> { if (LinearScan.isVariableOrRegister(operand)) { - addTemp((AllocatableValue) operand, op.id(), RegisterPriority.MustHaveRegister, operand.getValueKind()); + addTemp((AllocatableValue) operand, op.id(), RegisterPriority.MustHaveRegister, operand.getValueKind(), detailedAsserts); addRegisterHint(op, operand, mode, flags, false); } }; @@ -705,7 +705,7 @@ RegisterPriority p = registerPriorityOfInputOperand(flags); int opId = op.id(); int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId))); - addUse((AllocatableValue) operand, blockFrom, opId + 1, p, operand.getValueKind()); + addUse((AllocatableValue) operand, blockFrom, opId + 1, p, operand.getValueKind(), detailedAsserts); addRegisterHint(op, operand, mode, flags, false); } }; @@ -715,7 +715,7 @@ int opId = op.id(); int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId))); RegisterPriority p = registerPriorityOfInputOperand(flags); - addUse((AllocatableValue) operand, blockFrom, opId, p, operand.getValueKind()); + addUse((AllocatableValue) operand, blockFrom, opId, p, operand.getValueKind(), detailedAsserts); addRegisterHint(op, operand, mode, flags, false); } }; @@ -724,7 +724,7 @@ if (LinearScan.isVariableOrRegister(operand)) { int opId = op.id(); int blockFrom = allocator.getFirstLirInstructionId((allocator.blockForId(opId))); - addUse((AllocatableValue) operand, blockFrom, opId + 1, RegisterPriority.None, operand.getValueKind()); + addUse((AllocatableValue) operand, blockFrom, opId + 1, RegisterPriority.None, operand.getValueKind(), detailedAsserts); } }; @@ -737,7 +737,7 @@ AbstractBlockBase block = allocator.blockAt(i); try (Indent indent2 = Debug.logAndIndent("handle block %d", block.getId())) { - List instructions = allocator.getLIR().getLIRforBlock(block); + ArrayList instructions = allocator.getLIR().getLIRforBlock(block); final int blockFrom = allocator.getFirstLirInstructionId(block); int blockTo = allocator.getLastLirInstructionId(block); @@ -753,7 +753,7 @@ Debug.log("live in %d: %s", operandNum, operand); } - addUse(operand, blockFrom, blockTo + 2, RegisterPriority.None, LIRKind.Illegal); + addUse(operand, blockFrom, blockTo + 2, RegisterPriority.None, LIRKind.Illegal, detailedAsserts); /* * Add special use positions for loop-end blocks when the interval is used @@ -761,7 +761,7 @@ * non-natural loop, so it might have an invalid loop index. */ if (block.isLoopEnd() && block.getLoop() != null && isIntervalInLoop(operandNum, block.getLoop().getIndex())) { - allocator.intervalFor(operandNum).addUsePos(blockTo + 1, RegisterPriority.LiveAtLoopEnd); + allocator.intervalFor(operandNum).addUsePos(blockTo + 1, RegisterPriority.LiveAtLoopEnd, detailedAsserts); } } @@ -780,7 +780,7 @@ if (op.destroysCallerSavedRegisters()) { for (Register r : callerSaveRegs) { if (allocator.attributes(r).isAllocatable()) { - addTemp(r.asValue(), opId, RegisterPriority.None, LIRKind.Illegal); + addTemp(r.asValue(), opId, RegisterPriority.None, LIRKind.Illegal, detailedAsserts); } } if (Debug.isLogEnabled()) {