Package edu.umd.cs.findbugs.ba

Examples of edu.umd.cs.findbugs.ba.BasicBlock


        }
    }

    @Override
    public void meetInto(TypeFrame fact, Edge edge, TypeFrame result) throws DataflowAnalysisException {
        BasicBlock basicBlock = edge.getTarget();

        if (fact.isValid()) {
            TypeFrame tmpFact = null;

            // Handling an exception?
            if (basicBlock.isExceptionHandler()) {
                tmpFact = modifyFrame(fact, null);

                // Special case: when merging predecessor facts for entry to
                // an exception handler, we clear the stack and push a
                // single entry for the exception object. That way, the locals
                // can still be merged.
                CodeExceptionGen exceptionGen = basicBlock.getExceptionGen();
                tmpFact.clearStack();

                // Determine the type of exception(s) caught.
                Type catchType = null;
View Full Code Here


            result.addAll(thrownExceptionSet);
            thrownExceptionSet.clear();
            return result;
        }

        BasicBlock handlerBlock = edge.getTarget();
        CodeExceptionGen handler = handlerBlock.getExceptionGen();
        ObjectType catchType = handler.getCatchType();

        if (Hierarchy.isUniversalExceptionHandler(catchType)) {
            result.addAll(thrownExceptionSet);
            thrownExceptionSet.clear();
View Full Code Here

     */
    private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException {
        BitSet deadBlocks = new BitSet();
        ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
        for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) {
            BasicBlock block = i.next();
            ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block);
            if (vnaFrame.isTop()) {
                deadBlocks.set(block.getLabel());
            }
        }

        return deadBlocks;
    }
View Full Code Here

        Edge infeasibleEdge = redundantBranch.infeasibleEdge;
        if (infeasibleEdge != null) {
            if (DEBUG) {
                System.out.println("Check if " + redundantBranch + " creates dead code");
            }
            BasicBlock target = infeasibleEdge.getTarget();

            if (DEBUG) {
                System.out.println("Target block is  "
                        + (target.isExceptionThrower() ? " exception thrower" : " not exception thrower"));
            }
            // If the block is empty, it probably doesn't matter that it was
            // killed.
            // FIXME: really, we should crawl the immediately reachable blocks
            // starting at the target block to see if any of them are dead and
            // nonempty.
            boolean empty = !target.isExceptionThrower()
                    && (target.isEmpty() || isGoto(target.getFirstInstruction().getInstruction()));
            if (!empty) {
                try {
                    if (classContext.getCFG(method).getNumIncomingEdges(target) > 1) {
                        if (DEBUG) {
                            System.out.println("Target of infeasible edge has multiple incoming edges");
                        }
                        empty = true;
                    }
                } catch (CFGBuilderException e) {
                    assert true; // ignore it
                }
            }
            if (DEBUG) {
                System.out.println("Target block is  " + (empty ? "empty" : "not empty"));
            }

            if (!empty) {
                if (isThrower(target)) {
                    infeasibleEdgeSimplyThrowsException = true;
                }

            }
            if (!empty && !previouslyDeadBlocks.get(target.getLabel())) {
                if (DEBUG) {
                    System.out.println("target was alive previously");
                }
                // Block was not dead before the null pointer analysis.
                // See if it is dead now by inspecting the null value frame.
View Full Code Here

     */
    public PatternMatcher execute() throws DataflowAnalysisException {
        workList.addLast(cfg.getEntry());

        while (!workList.isEmpty()) {
            BasicBlock basicBlock = workList.removeLast();
            visitedBlockMap.put(basicBlock, basicBlock);

            // Scan instructions of basic block for possible matches
            BasicBlock.InstructionIterator i = basicBlock.instructionIterator();
            while (i.hasNext()) {
                attemptMatch(basicBlock, i.duplicate());
                i.next();
            }

            // Add successors of the basic block (which haven't been visited
            // already)
            Iterator<BasicBlock> succIterator = cfg.successorIterator(basicBlock);
            while (succIterator.hasNext()) {
                BasicBlock succ = succIterator.next();
                if (visitedBlockMap.get(succ) == null) {
                    workList.addLast(succ);
                }
            }
        }
View Full Code Here

                    Edge edge = i.next();
                    if (dfs.getDFSEdgeType(edge) == BACK_EDGE) {
                        continue;
                    }

                    BasicBlock destBlock = edge.getTarget();
                    int destId = destBlock.getLabel();

                    // CFGs can have duplicate edges
                    if (visitedSuccessorSet.get(destId)) {
                        continue;
                    }
View Full Code Here

            State dup = this.duplicate();

            if (currentMatch != null) {
                // Find the referenced instruction.
                PatternElementMatch dominator = currentMatch.getFirstLabeledMatch(patternElement.getDominatedBy());
                BasicBlock domBlock = dominator.getBasicBlock();
                InstructionHandle domInstruction = dominator.getMatchedInstructionInstructionHandle();
                // Find all basic blocks dominated by the dominator block.
                for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
                    BasicBlock block = i.next();
                    boolean includeInstructions = block != domBlock;

                    BitSet dominators = domAnalysis.getResultFact(block);
                    if (block == domBlock || dominators.get(domBlock.getLabel())) {
                        // This block is dominated by the dominator block.
                        // Each instruction in the block which matches the
                        // current pattern
                        // element is a new state continuing the match.
                        for (Iterator<InstructionHandle> j = block.instructionIterator(); j.hasNext();) {
                            InstructionHandle next = j.next();
                            if (includeInstructions) {
                                MatchResult matchResult = dup.matchLocation(new Location(next, block));
                                if (matchResult != null) {
                                    stateList.add(dup);
View Full Code Here

                    tmpFact = modifyFrame(fact, tmpFact);
                    tmpFact.toExceptionValues();
                }
            }

            final BasicBlock destBlock = edge.getTarget();

            if (destBlock.isExceptionHandler()) {
                // Exception handler - clear stack and push a non-null value
                // to represent the exception.
                tmpFact = modifyFrame(fact, tmpFact);
                tmpFact.clearStack();

                // Downgrade NULL and NSP to DNR if the handler is for
                // CloneNotSupportedException or InterruptedException
                if (true) {
                    CodeExceptionGen handler = destBlock.getExceptionGen();
                    ObjectType catchType = handler.getCatchType();
                    if (catchType != null) {
                        String catchClass = catchType.getClassName();
                        if (catchClass.equals("java.lang.CloneNotSupportedException")
                                || catchClass.equals("java.lang.InterruptedException")) {
                            for (int i = 0; i < tmpFact.getNumSlots(); ++i) {
                                IsNullValue value = tmpFact.getValue(i);
                                if (value.isDefinitelyNull() || value.isNullOnSomePath()) {
                                    tmpFact.setValue(i, IsNullValue.nullOnComplexPathValue());
                                }
                            }
                        }
                    }
                }

                // Mark all values as having occurred on an exception path
                tmpFact.toExceptionValues();

                // Push the exception value
                tmpFact.pushValue(IsNullValue.nonNullValue());
            } else {
                final int edgeType = edge.getType();
                final BasicBlock sourceBlock = edge.getSource();
                final BasicBlock targetBlock = edge.getTarget();
                final ValueNumberFrame targetVnaFrame = vnaDataflow.getStartFact(destBlock);
                final ValueNumberFrame sourceVnaFrame = vnaDataflow.getResultFact(sourceBlock);

                assert targetVnaFrame != null;

                // Determine if the edge conveys any information about the
                // null/non-null status of operands in the incoming frame.
                if (edgeType == IFCMP_EDGE || edgeType == FALL_THROUGH_EDGE) {
                    IsNullValueFrame resultFact = getResultFact(sourceBlock);
                    IsNullConditionDecision decision = resultFact.getDecision();
                    if (decision != null) {
                        if (!decision.isEdgeFeasible(edgeType)) {
                            // The incoming edge is infeasible; just use TOP
                            // as the start fact for this block.
                            tmpFact = createFact();
                            tmpFact.setTop();
                        } else {
                            ValueNumber valueTested = decision.getValue();
                            if (valueTested != null) {
                                // A value has been determined for this edge.
                                // Use the value to update the is-null
                                // information in
                                // the start fact for this block.

                                if (DEBUG) {
                                    System.out.println("Updating edge information for " + valueTested);
                                }
                                final Location atIf = new Location(sourceBlock.getLastInstruction(), sourceBlock);
                                final ValueNumberFrame prevVnaFrame = vnaDataflow.getFactAtLocation(atIf);

                                IsNullValue decisionValue = decision.getDecision(edgeType);
                                if (decisionValue != null) {

                                    if (DEBUG) {
                                        System.out.println("Set decision information");
                                        System.out.println("  " + valueTested + " becomes " + decisionValue);
                                        System.out.println("  at " + targetBlock.getFirstInstruction().getPosition());
                                        System.out.println("  prev available loads: " + prevVnaFrame.availableLoadMapAsString());
                                        System.out.println("  target available loads: "
                                                + targetVnaFrame.availableLoadMapAsString());
                                    }
                                    tmpFact = replaceValues(fact, tmpFact, valueTested, prevVnaFrame, targetVnaFrame,
                                            decisionValue);
                                    if (decisionValue.isDefinitelyNull()) {
                                        // Make a note of the value that has
                                        // become null
                                        // due to the if comparison.
                                        addLocationWhereValueBecomesNull(new LocationWhereValueBecomesNull(atIf, valueTested));
                                        ValueNumber knownNonnull = getKnownNonnullDueToPointerDisequality(valueTested, atIf
                                                .getHandle().getPosition());
                                        if (knownNonnull != null) {
                                            tmpFact = replaceValues(fact, tmpFact, knownNonnull, prevVnaFrame, targetVnaFrame,
                                                    IsNullValue.checkedNonNullValue());
                                        }
                                    }
                                }
                            }
                        }
                    }
                } // if (edgeType == IFCMP_EDGE || edgeType ==
                // FALL_THROUGH_EDGE)

                // If this is a fall-through edge from a null check,
                // then we know the value checked is not null.
                if (sourceBlock.isNullCheck() && edgeType == FALL_THROUGH_EDGE) {
                    ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(destBlock);
                    if (vnaFrame == null) {
                        throw new IllegalStateException("no vna frame at block entry?");
                    }

                    Instruction firstInDest = edge.getTarget().getFirstInstruction().getInstruction();

                    IsNullValue instance = fact.getInstance(firstInDest, methodGen.getConstantPool());

                    if (instance.isDefinitelyNull()) {
                        // If we know the variable is null, this edge is
                        // infeasible
                        tmpFact = createFact();
                        tmpFact.setTop();
                    } else if (!instance.isDefinitelyNotNull()) {
                        // If we're not sure that the instance is definitely
                        // non-null,
                        // update the is-null information for the dereferenced
                        // value.
                        InstructionHandle kaBoomLocation = targetBlock.getFirstInstruction();
                        ValueNumber replaceMe = vnaFrame.getInstance(firstInDest, methodGen.getConstantPool());
                        IsNullValue noKaboomNonNullValue = IsNullValue.noKaboomNonNullValue(new Location(kaBoomLocation,
                                targetBlock));
                        if (DEBUG) {
                            System.out.println("Start vna fact: " + vnaFrame);
View Full Code Here

        return frame;

    }

    public IsNullValueFrame getFactAtMidEdge(Edge edge) throws DataflowAnalysisException {
        BasicBlock block = isForwards() ? edge.getSource() : edge.getTarget();

        IsNullValueFrame predFact = createFact();
        copy(getResultFact(block), predFact);

        edgeTransfer(edge, predFact);
View Full Code Here

            }

            NullnessAnnotation methodAnnotation = getMethodNullnessAnnotation(classContext, method);

            while (bbIter.hasNext()) {
                BasicBlock basicBlock = bbIter.next();

                if (basicBlock.isNullCheck()) {
                    InstructionHandle exceptionThrowerHandle = basicBlock.getExceptionThrower();
                    Instruction exceptionThrower = exceptionThrowerHandle.getInstruction();
                    ValueNumberFrame vnaFrame = vna.getStartFact(basicBlock);
                    if (!vnaFrame.isValid()) {
                        continue;
                    }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.BasicBlock

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.