use of org.graalvm.compiler.java.BciBlockMapping.BciBlock in project graal by oracle.
the class BytecodeParser method checkLoopExit.
private Target checkLoopExit(FixedNode target, BciBlock targetBlock, FrameStateBuilder state) {
if (currentBlock != null) {
long exits = currentBlock.loops & ~targetBlock.loops;
if (exits != 0) {
LoopExitNode firstLoopExit = null;
LoopExitNode lastLoopExit = null;
int pos = 0;
ArrayList<BciBlock> exitLoops = new ArrayList<>(Long.bitCount(exits));
do {
long lMask = 1L << pos;
if ((exits & lMask) != 0) {
exitLoops.add(blockMap.getLoopHeader(pos));
exits &= ~lMask;
}
pos++;
} while (exits != 0);
Collections.sort(exitLoops, new Comparator<BciBlock>() {
@Override
public int compare(BciBlock o1, BciBlock o2) {
return Long.bitCount(o2.loops) - Long.bitCount(o1.loops);
}
});
int bci = targetBlock.startBci;
if (targetBlock instanceof ExceptionDispatchBlock) {
bci = ((ExceptionDispatchBlock) targetBlock).deoptBci;
}
FrameStateBuilder newState = state.copy();
for (BciBlock loop : exitLoops) {
LoopBeginNode loopBegin = (LoopBeginNode) getFirstInstruction(loop);
LoopExitNode loopExit = graph.add(new LoopExitNode(loopBegin));
if (lastLoopExit != null) {
lastLoopExit.setNext(loopExit);
}
if (firstLoopExit == null) {
firstLoopExit = loopExit;
}
lastLoopExit = loopExit;
debug.log("Target %s Exits %s, scanning framestates...", targetBlock, loop);
newState.clearNonLiveLocals(targetBlock, liveness, true);
newState.insertLoopProxies(loopExit, getEntryState(loop));
loopExit.setStateAfter(newState.create(bci, loopExit));
}
lastLoopExit.setNext(target);
return new Target(firstLoopExit, newState);
}
}
return new Target(target, state);
}
use of org.graalvm.compiler.java.BciBlockMapping.BciBlock in project graal by oracle.
the class BytecodeParser method genIf.
protected void genIf(ValueNode x, Condition cond, ValueNode y) {
assert x.getStackKind() == y.getStackKind();
assert currentBlock.getSuccessorCount() == 2;
BciBlock trueBlock = currentBlock.getSuccessor(0);
BciBlock falseBlock = currentBlock.getSuccessor(1);
if (trueBlock == falseBlock) {
// The target block is the same independent of the condition.
appendGoto(trueBlock);
return;
}
ValueNode a = x;
ValueNode b = y;
BciBlock trueSuccessor = trueBlock;
BciBlock falseSuccessor = falseBlock;
CanonicalizedCondition canonicalizedCondition = cond.canonicalize();
// Check whether the condition needs to mirror the operands.
if (canonicalizedCondition.mustMirror()) {
a = y;
b = x;
}
if (canonicalizedCondition.mustNegate()) {
trueSuccessor = falseBlock;
falseSuccessor = trueBlock;
}
// Create the logic node for the condition.
LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b);
double probability = -1;
if (condition instanceof IntegerEqualsNode) {
probability = extractInjectedProbability((IntegerEqualsNode) condition);
// the probability coming from here is about the actual condition
}
if (probability == -1) {
probability = getProfileProbability(canonicalizedCondition.mustNegate());
}
probability = clampProbability(probability);
genIf(condition, trueSuccessor, falseSuccessor, probability);
}
use of org.graalvm.compiler.java.BciBlockMapping.BciBlock in project graal by oracle.
the class LocalLiveness method computeLiveness.
void computeLiveness(DebugContext debug, BytecodeStream stream) {
for (BciBlock block : blocks) {
computeLocalLiveness(stream, block);
}
boolean changed;
int iteration = 0;
do {
assert traceIteration(debug, iteration);
changed = false;
for (int i = blocks.length - 1; i >= 0; i--) {
BciBlock block = blocks[i];
int blockID = block.getId();
assert traceStart(debug, block, blockID);
boolean blockChanged = (iteration == 0);
if (block.getSuccessorCount() > 0) {
int oldCardinality = liveOutCardinality(blockID);
for (BciBlock sux : block.getSuccessors()) {
assert traceSuccessor(debug, sux);
propagateLiveness(blockID, sux.getId());
}
blockChanged |= (oldCardinality != liveOutCardinality(blockID));
}
if (blockChanged) {
updateLiveness(blockID);
assert traceEnd(debug, block, blockID);
}
changed |= blockChanged;
}
iteration++;
} while (changed);
}
use of org.graalvm.compiler.java.BciBlockMapping.BciBlock in project graal by oracle.
the class SmallLocalLiveness method storeOne.
@Override
protected void storeOne(int blockID, int local) {
long bit = 1L << local;
if ((localsLiveGen[blockID] & bit) == 0L) {
localsLiveKill[blockID] |= bit;
}
BciBlock block = blocks[blockID];
long tmp = block.loops;
int pos = 0;
while (tmp != 0) {
if ((tmp & 1L) == 1L) {
this.localsChangedInLoop[pos] |= bit;
}
tmp >>>= 1;
++pos;
}
}
use of org.graalvm.compiler.java.BciBlockMapping.BciBlock in project graal by oracle.
the class GraalOSRTestBase method getBackedgeBCI.
/**
* Returns the target BCI of the first bytecode backedge. This is where HotSpot triggers
* on-stack-replacement in case the backedge counter overflows.
*/
private static int getBackedgeBCI(DebugContext debug, ResolvedJavaMethod method) {
Bytecode code = new ResolvedJavaMethodBytecode(method);
BytecodeStream stream = new BytecodeStream(code.getCode());
OptionValues options = debug.getOptions();
BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, options, debug);
for (BciBlock block : bciBlockMapping.getBlocks()) {
if (block.startBci != -1) {
int bci = block.startBci;
for (BciBlock succ : block.getSuccessors()) {
if (succ.startBci != -1) {
int succBci = succ.startBci;
if (succBci < bci) {
// back edge
return succBci;
}
}
}
}
}
TTY.println("Cannot find loop back edge with bytecode loops at:%s", Arrays.toString(bciBlockMapping.getLoopHeaders()));
TTY.println(new BytecodeDisassembler().disassemble(code));
return -1;
}
Aggregations