Search in sources :

Example 1 with BciBlock

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);
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) ExceptionDispatchBlock(org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock) ArrayList(java.util.ArrayList) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)

Example 2 with BciBlock

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);
}
Also used : CanonicalizedCondition(org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 3 with BciBlock

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);
}
Also used : BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 4 with BciBlock

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;
    }
}
Also used : BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 5 with BciBlock

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;
}
Also used : BytecodeDisassembler(org.graalvm.compiler.bytecode.BytecodeDisassembler) OptionValues(org.graalvm.compiler.options.OptionValues) BciBlockMapping(org.graalvm.compiler.java.BciBlockMapping) BytecodeStream(org.graalvm.compiler.bytecode.BytecodeStream) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Aggregations

BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)15 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)8 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)4 LogicNode (org.graalvm.compiler.nodes.LogicNode)4 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 ProfilingPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)3 ArrayList (java.util.ArrayList)2 JavaType (jdk.vm.ci.meta.JavaType)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)1 Bytecode (org.graalvm.compiler.bytecode.Bytecode)1 BytecodeDisassembler (org.graalvm.compiler.bytecode.BytecodeDisassembler)1 BytecodeStream (org.graalvm.compiler.bytecode.BytecodeStream)1 ResolvedJavaMethodBytecode (org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode)1