Package edu.umd.cs.findbugs.ba

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


            if (!moreInstructionsInBasicBlock()) {
                throw new IllegalStateException("At end of BB!");
            }

            // Move to location of next instruction to be matched
            Location location = new Location(instructionIterator.next(), basicBlock);
            return matchLocation(location);
        }
View Full Code Here


                        // 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);
                                    dup = this.duplicate();
                                }
                            } else if (next.equals(domInstruction)) {
View Full Code Here

    public static @CheckForNull
    PointerEqualityCheck getForPointerEqualityCheck(CFG cfg, ValueNumberDataflow vna) {
        PointerEqualityCheckState state = PointerEqualityCheckState.INIT;
        int target = Integer.MAX_VALUE;
        Location test = null;

        for (Location loc : cfg.orderedLocations()) {
            Instruction ins = loc.getHandle().getInstruction();
            switch (state) {
            case INIT:
View Full Code Here

            instanceOfFrame = createFact();
            instanceOfFrame.copyFrom(fact);
        }

        // Model the instruction
        visitor.setFrameAndLocation(fact, new Location(handle, basicBlock));
        Instruction ins = handle.getInstruction();
        visitor.analyzeInstruction(ins);

        if (!fact.isValid()) {
            return;
        }

        // Special case:
        // The instruction may have produced previously seen values
        // about which new is-null information is known.
        // If any other instances of the produced values exist,
        // update their is-null information.
        // Also, make a note of any newly-produced null values.

        int numProduced = ins.produceStack(methodGen.getConstantPool());
        if (numProduced == Constants.UNPREDICTABLE) {
            throw new DataflowAnalysisException("Unpredictable stack production", methodGen, handle);
        }

        int start = fact.getNumSlots() - numProduced;
        Location location = new Location(handle, basicBlock);
        ValueNumberFrame vnaFrameAfter = vnaDataflow.getFactAfterLocation(location);
        if (!vnaFrameAfter.isValid()) {
            assert false : "Invalid VNA after location " + location + " in " +  SignatureConverter.convertMethodSignature(methodGen);
        return;
        }
View Full Code Here

                                // 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);
                            System.out.println("inva fact: " + fact);
                            System.out.println("\nGenerated NoKaboom value for location " + kaBoomLocation);
View Full Code Here

            if (instanceOfFrame == null) {
                return null;
            }
            IsNullValue tos = instanceOfFrame.getTopValue();
            boolean isNotInstanceOf = (lastInSourceOpcode != Constants.IFNE);
            Location atInstanceOf = new Location(prev, basicBlock);
            ValueNumberFrame instanceOfVnaFrame = vnaDataflow.getFactAtLocation(atInstanceOf);

            // Initially, assume neither branch is feasible.
            IsNullValue ifcmpDecision = null;
            IsNullValue fallThroughDecision = null;

            if (tos.isDefinitelyNull()) {
                // Predetermined comparison - one branch is infeasible
                if (isNotInstanceOf) {
                    ifcmpDecision = tos;
                } else {
                    // ifnonnull
                    fallThroughDecision = tos;
                }
            } else if (tos.isDefinitelyNotNull()) {
                return null;
            } else {
                // As far as we know, both branches feasible
                ifcmpDecision = isNotInstanceOf ? tos : IsNullValue.pathSensitiveNonNullValue();
                fallThroughDecision = isNotInstanceOf ? IsNullValue.pathSensitiveNonNullValue() : tos;
            }
            if (DEBUG) {
                System.out.println("Checking..." + tos + " -> " + ifcmpDecision + " or " + fallThroughDecision);
            }
            return new IsNullConditionDecision(instanceOfVnaFrame.getTopValue(), ifcmpDecision, fallThroughDecision);
        }

        if (!nullComparisonInstructionSet.get(lastInSourceOpcode)) {
            return null; // doesn't end in null comparison
        }

        Location atIf = new Location(lastInSourceHandle, basicBlock);
        ValueNumberFrame prevVnaFrame = vnaDataflow.getFactAtLocation(atIf);

        switch (lastInSourceOpcode) {

        case Constants.IFNULL:
View Full Code Here

        if (lineMentionedMultipleTimes.cardinality() > 0) {
            linesWithLoadsOfNotDefinitelyNullValues = new BitSet();
            LineNumberTable lineNumbers = method.getLineNumberTable();
            for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
                Location location = i.next();

                InstructionHandle handle = location.getHandle();
                Instruction ins = handle.getInstruction();
                if (!(ins instanceof ALOAD)) {
                    continue;
                }

                IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
                if (!frame.isValid()) {
                    // This basic block is probably dead
                    continue;
                }
                // System.out.println(handle.getPosition() + "\t" +
                // ins.getName() + "\t" + frame);

                ALOAD load = (ALOAD) ins;

                int index = load.getIndex();
                IsNullValue v = frame.getValue(index);
                if (!v.isDefinitelyNull()) {
                    int sourceLine = lineNumbers.getSourceLine(handle.getPosition());
                    if (sourceLine > 0) {
                        linesWithLoadsOfNotDefinitelyNullValues.set(sourceLine);
                    }
                }
            }
        }

        IdentityHashMap<InstructionHandle, Object> sometimesGood = new IdentityHashMap<InstructionHandle, Object>();

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();
            if (!(ins instanceof ALOAD)) {
                continue;
            }
            IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }
            // System.out.println(handle.getPosition() + "\t" + ins.getName() +
            // "\t" + frame);

            ALOAD load = (ALOAD) ins;

            int index = load.getIndex();
            IsNullValue v = frame.getValue(index);
            if (!v.isDefinitelyNull()) {
                sometimesGood.put(handle, null);
            }
        }

        // System.out.println(nullValueDataflow);
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();
            if (!(ins instanceof ALOAD)) {
                continue;
            }

            if (sometimesGood.containsKey(handle)) {
                continue;
            }
            IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }
            // System.out.println(handle.getPosition() + "\t" + ins.getName() +
            // "\t" + frame);

            ALOAD load = (ALOAD) ins;

            int index = load.getIndex();
            IsNullValue v = frame.getValue(index);
            if (v.isDefinitelyNull()) {
                InstructionHandle nextHandle = handle.getNext();
                Instruction next = nextHandle.getInstruction();
                int position = location
                        .getHandle().getPosition();
                int catchSizeANY = Util.getSizeOfSurroundingTryBlock(method, "", position);
                if (catchSizeANY < Integer.MAX_VALUE && isNullTestedClose( classContext, load, nextHandle, next)) {
                    continue;
                }
View Full Code Here

                    if (!vnaFrame.isValid()) {
                        continue;
                    }
                    ValueNumber valueNumber = vnaFrame.getInstance(exceptionThrower, cpg);

                    Location location = new Location(exceptionThrowerHandle, basicBlock);
                    if (valueNumberForThis != valueNumber) {
                        derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerDereference());
                    }

                }
            }

            for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
                Location location = i.next();
                InstructionHandle handle = location.getHandle();
                Instruction ins = handle.getInstruction();
                ValueNumberFrame valueNumberFrame = vna.getFactAtLocation(location);
                TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                if (ins instanceof InvokeInstruction) {
                    InvokeInstruction inv = (InvokeInstruction) ins;
View Full Code Here

            System.out.println("checking for nullcheck on edge " + edge);
        }
        Type type = null;
        if ((opcode == Constants.IFNULL && edge.getType() == EdgeTypes.IFCMP_EDGE)
                || (opcode == Constants.IFNONNULL && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) {
            Location location = new Location(last, sourceBlock);
            TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
            if (typeFrame.isValid()) {
                type = typeFrame.getTopValue();
                if (DEBUG_NULL_CHECK) {
                    System.out.println("ifnull comparison of " + type + " to null at " + last);
View Full Code Here

        if ((opcode == Constants.IF_ACMPEQ && edge.getType() == EdgeTypes.IFCMP_EDGE)
                || (opcode == Constants.IF_ACMPNE && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) {
            //
            // Check nullness and type of the top two stack values.
            //
            Location location = new Location(last, sourceBlock);
            IsNullValueFrame invFrame = invDataflow.getFactAtLocation(location);
            TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
            if (invFrame.isValid() && typeFrame.isValid()) {
                //
                // See if exactly one of the top two stack values is definitely
View Full Code Here

TOP

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

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.