Package com.strobel.assembler.ir

Examples of com.strobel.assembler.ir.ExceptionHandler


            }
            else {
                handlerLastInstruction = new Instruction(handlerEnd, OpCode.NOP);
            }

            final ExceptionHandler handler;

            if (catchType == null) {
                handler = ExceptionHandler.createFinally(
                    new ExceptionBlock(firstInstruction, lastInstruction),
                    new ExceptionBlock(handlerFirstInstruction, handlerLastInstruction)
View Full Code Here


        throw new IllegalStateException("Could not find node for exception handler!");
    }

    private ControlFlowNode findInnermostFinallyHandlerNode(final int offset) {
        final ExceptionHandler handler = findInnermostFinallyHandler(offset);

        if (handler == null) {
            return _exceptionalExit;
        }
View Full Code Here

    private static List<ExceptionHandler> coalesceExceptionHandlers(final List<ExceptionHandler> handlers) {
        final ArrayList<ExceptionHandler> copy = new ArrayList<>(handlers);

        for (int i = 0; i < copy.size(); i++) {
            final ExceptionHandler handler = copy.get(i);

            if (!handler.isCatch()) {
                continue;
            }

            final ExceptionBlock tryBlock = handler.getTryBlock();
            final ExceptionBlock handlerBlock = handler.getHandlerBlock();

            for (int j = i + 1; j < copy.size(); j++) {
                final ExceptionHandler other = copy.get(j);

                if (!other.isCatch()) {
                    continue;
                }

                final ExceptionBlock otherTry = other.getTryBlock();
                final ExceptionBlock otherHandler = other.getHandlerBlock();

                if (otherTry.getFirstInstruction().getOffset() == tryBlock.getFirstInstruction().getOffset() &&
                    otherTry.getLastInstruction().getOffset() == tryBlock.getLastInstruction().getOffset() &&
                    otherHandler.getFirstInstruction().getOffset() == handlerBlock.getFirstInstruction().getOffset() &&
                    otherHandler.getLastInstruction().getOffset() == handlerBlock.getLastInstruction().getOffset()) {

                    copy.set(
                        i,
                        ExceptionHandler.createCatch(
                            tryBlock,
                            handlerBlock,
                            MetadataHelper.findCommonSuperType(handler.getCatchType(), other.getCatchType())
                        )
                    );

                    copy.remove(j--);
                }
View Full Code Here

        final List<Instruction> instructions = _instructions;

        for (int i = 0, n = instructions.size(); i < n; i++) {
            final Instruction blockStart = instructions.get(i);
            final ExceptionHandler blockStartExceptionHandler = findInnermostExceptionHandler(blockStart.getOffset());

            //
            // See how big we can make that block...
            //
            for (; i + 1 < n; i++) {
                final Instruction instruction = instructions.get(i);
                final OpCode opCode = instruction.getOpCode();

                if (opCode.isUnconditionalBranch() /*|| opCode.canThrow()*/ || _hasIncomingJumps[i + 1]) {
                    break;
                }

                final Instruction next = instruction.getNext();

                if (next != null) {
                    //
                    // Ensure that blocks never contain instructions from different try blocks.
                    //
                    final ExceptionHandler innermostExceptionHandler = findInnermostExceptionHandler(next.getOffset());

                    if (innermostExceptionHandler != blockStartExceptionHandler) {
                        break;
                    }
                }
View Full Code Here

                        }
                    }
                }
            }

            final ExceptionHandler exceptionHandler = node.getExceptionHandler();

            if (exceptionHandler != null) {
                if (exceptionHandler.isFinally() || any(node.getInstructions(), CAN_THROW)) {
                    final ControlFlowNode endFinallyNode = node.getEndFinallyNode();

                    if (endFinallyNode != null) {
                        createEdge(
                            endFinallyNode,
                            findParentExceptionHandlerNode(node),
                            JumpType.JumpToExceptionHandler
                        );
                    }
                    else {
                        final ControlFlowNode parentHandler = findParentExceptionHandlerNode(node);

                        if (parentHandler.getNodeType() != ControlFlowNodeType.ExceptionalExit) {
                            createEdge(node, parentHandler, JumpType.JumpToExceptionHandler);
                        }

                        if (parentHandler.getNodeType() != ControlFlowNodeType.ExceptionalExit) {
                            for (final ExceptionHandler handler : _exceptionHandlers) {
                                if (Comparer.equals(handler.getTryBlock(), parentHandler.getExceptionHandler().getTryBlock())) {
                                    final ControlFlowNode handlerNode = firstOrDefault(
                                        _nodes,
                                        new Predicate<ControlFlowNode>() {
                                            @Override
                                            public boolean test(final ControlFlowNode node) {
                                                return node.getExceptionHandler() == handler;
                                            }
                                        }
                                    );

                                    if (handlerNode != node && handlerNode != parentHandler) {
                                        createEdge(node, handlerNode, JumpType.JumpToExceptionHandler);
                                    }
                                }
                            }
                        }
                    }
                }

                createEdge(
                    node,
                    exceptionHandler.getHandlerBlock().getFirstInstruction(),
                    JumpType.Normal
                );
            }
        }
    }
View Full Code Here

        final int offset = node.getExceptionHandler().getHandlerBlock().getFirstInstruction().getOffset();

        for (int i = node.getBlockIndex() + 1, n = _nodes.size(); i < n; i++) {
            final ControlFlowNode currentNode = _nodes.get(i);
            final ExceptionHandler handler = currentNode.getExceptionHandler();

            if (handler != null &&
                handler.getTryBlock().getFirstInstruction().getOffset() <= offset &&
                offset < handler.getTryBlock().getLastInstruction().getEndOffset()) {

                return currentNode;
            }
        }
View Full Code Here

        return _exceptionalExit;
    }

    private ControlFlowNode findInnermostExceptionHandlerNode(final int offset) {
        final ExceptionHandler handler = findInnermostExceptionHandler(offset);

        if (handler == null) {
            return _exceptionalExit;
        }
View Full Code Here

        final List<Instruction> instructions = _instructions;

        for (int i = 0, n = instructions.size(); i < n; i++) {
            final Instruction blockStart = instructions.get(i);
            final ExceptionHandler blockStartExceptionHandler = findInnermostExceptionHandler(blockStart.getOffset());

            //
            // See how big we can make that block...
            //
            for (; i + 1 < n; i++) {
                final Instruction instruction = instructions.get(i);
                final OpCode opCode = instruction.getOpCode();

                if (opCode.isBranch() /*|| opCode.canThrow()*/ || _hasIncomingJumps[i + 1]) {
                    break;
                }

                final Instruction next = instruction.getNext();

                if (next != null) {
                    //
                    // Ensure that blocks never contain instructions from different try blocks.
                    //
                    final ExceptionHandler innermostExceptionHandler = findInnermostExceptionHandler(next.getOffset());

                    if (innermostExceptionHandler != blockStartExceptionHandler) {
                        break;
                    }
                }
View Full Code Here

                        }
                    }
                }
            }

            final ExceptionHandler exceptionHandler = node.getExceptionHandler();

            if (exceptionHandler != null) {
                if (exceptionHandler.isFinally()) {
                    final ControlFlowNode handlerBlock = findInnermostFinallyHandlerNode(
                        exceptionHandler.getHandlerBlock().getLastInstruction().getOffset()
                    );

                    if (handlerBlock.getNodeType() == ControlFlowNodeType.FinallyHandler && handlerBlock != node) {
                        createEdge(
                            node,
                            handlerBlock,
                            JumpType.JumpToExceptionHandler
                        );
                    }
                }
                else {
                    final ControlFlowNode adjacentFinally = findInnermostFinallyHandlerNode(
                        exceptionHandler.getTryBlock().getLastInstruction().getOffset()
                    );

                    createEdge(
                        node,
                        adjacentFinally != null ? adjacentFinally : findParentExceptionHandlerNode(node),
                        JumpType.JumpToExceptionHandler
                    );
                }

                createEdge(
                    node,
                    exceptionHandler.getHandlerBlock().getFirstInstruction(),
                    JumpType.Normal
                );
            }
        }
    }
View Full Code Here

    private void createBranchControlFlow(final ControlFlowNode node, final Instruction jump, final Instruction target) {
        final ControlFlowNode handlerNode = findInnermostHandlerBlock(jump.getOffset());
        final ControlFlowNode outerFinally = findInnermostHandlerBlock(jump.getOffset(), true);
        final ControlFlowNode targetHandlerNode = findInnermostHandlerBlock(target.getOffset());
        final ExceptionHandler handler = handlerNode.getExceptionHandler();

        if (jump.getOpCode().isJumpToSubroutine() ||
            targetHandlerNode == handlerNode ||
            (handler != null &&
             (handler.getTryBlock().contains(jump) ? handler.getTryBlock().contains(target)
                                                   : handler.getHandlerBlock().contains(target)))) {
            //
            // A jump within a handler is normal control flow.
            //
            createEdge(node, target, JumpType.Normal);
            return;
        }

        if (handlerNode.getNodeType() == ControlFlowNodeType.CatchHandler) {
            //
            // First look for an immediately adjacent finally handler.
            //
            ControlFlowNode finallyHandlerNode = findInnermostFinallyHandlerNode(handler.getTryBlock().getLastInstruction().getOffset());

            final ExceptionHandler finallyHandler = finallyHandlerNode.getExceptionHandler();
            final ExceptionHandler outerFinallyHandler = outerFinally.getExceptionHandler();

            if (finallyHandlerNode.getNodeType() != ControlFlowNodeType.FinallyHandler ||
                (outerFinally.getNodeType() == ControlFlowNodeType.FinallyHandler &&
                 finallyHandler.getTryBlock().contains(outerFinallyHandler.getHandlerBlock()))) {

                //
                // We don't have an adjacent finally handler, or our containing finally handler is
                // protected by the adjacent finally handler's try block.  Use the containing finally.
                //
View Full Code Here

TOP

Related Classes of com.strobel.assembler.ir.ExceptionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.