Search in sources :

Example 1 with ExceptionDispatchBlock

use of org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock 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 ExceptionDispatchBlock

use of org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock in project graal by oracle.

the class BytecodeParser method setMergeStateAfter.

private void setMergeStateAfter(BciBlock block, FixedWithNextNode firstInstruction) {
    AbstractMergeNode abstractMergeNode = (AbstractMergeNode) firstInstruction;
    if (abstractMergeNode.stateAfter() == null) {
        int bci = block.startBci;
        if (block instanceof ExceptionDispatchBlock) {
            bci = ((ExceptionDispatchBlock) block).deoptBci;
        }
        abstractMergeNode.setStateAfter(createFrameState(bci, abstractMergeNode));
    }
}
Also used : ExceptionDispatchBlock(org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)

Example 3 with ExceptionDispatchBlock

use of org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock in project graal by oracle.

the class BytecodeParser method processBlock.

@SuppressWarnings("try")
protected void processBlock(BciBlock block) {
    // Ignore blocks that have no predecessors by the time their bytecodes are parsed
    FixedWithNextNode firstInstruction = getFirstInstruction(block);
    if (firstInstruction == null) {
        debug.log("Ignoring block %s", block);
        return;
    }
    try (Indent indent = debug.logAndIndent("Parsing block %s  firstInstruction: %s  loopHeader: %b", block, firstInstruction, block.isLoopHeader)) {
        lastInstr = firstInstruction;
        frameState = getEntryState(block);
        setCurrentFrameState(frameState);
        currentBlock = block;
        if (block != blockMap.getUnwindBlock() && !(block instanceof ExceptionDispatchBlock)) {
            frameState.setRethrowException(false);
        }
        if (firstInstruction instanceof AbstractMergeNode) {
            setMergeStateAfter(block, firstInstruction);
        }
        if (block == blockMap.getUnwindBlock()) {
            handleUnwindBlock((ExceptionDispatchBlock) block);
        } else if (block instanceof ExceptionDispatchBlock) {
            createExceptionDispatch((ExceptionDispatchBlock) block);
        } else {
            iterateBytecodesForBlock(block);
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Indent(org.graalvm.compiler.debug.Indent) ExceptionDispatchBlock(org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode)

Aggregations

ExceptionDispatchBlock (org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock)3 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)2 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)2 ArrayList (java.util.ArrayList)1 Indent (org.graalvm.compiler.debug.Indent)1 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)1