Package edu.umd.cs.findbugs.ba.vna

Examples of edu.umd.cs.findbugs.ba.vna.ValueNumberFrame


        startTransfer();
        super.transfer(basicBlock, end, start, result);
        endTransfer(basicBlock, end, result);

        if (end == null) {
            ValueNumberFrame vnaFrameAfter = vnaDataflow.getFactAfterLocation(Location.getLastLocation(basicBlock));
            // purge stale information
            if (!vnaFrameAfter.isTop()) {
                result.cleanStaleKnowledge(vnaFrameAfter);
            }
        }

    }
View Full Code Here


            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;
        }
        for (int i = start; i < fact.getNumSlots(); ++i) {
            ValueNumber value = vnaFrameAfter.getValue(i);
            IsNullValue isNullValue = fact.getValue(i);

            for (int j = 0; j < start; ++j) {
                ValueNumber otherValue = vnaFrameAfter.getValue(j);
                if (value.equals(otherValue)) {
                    // Same value is in both slots.
                    // Update the is-null information to match
                    // the new information.
                    fact.setValue(j, isNullValue);
                }
            }
        }

        if (visitor.getSlotContainingNewNullValue() >= 0) {
            ValueNumber newNullValue = vnaFrameAfter.getValue(visitor.getSlotContainingNewNullValue());
            addLocationWhereValueBecomesNull(new LocationWhereValueBecomesNull(location, newNullValue// ,
                    // handle
                    ));
        }
View Full Code Here

                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);
                            System.out.println("inva fact: " + fact);
View Full Code Here

                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:
        case Constants.IFNONNULL: {
            IsNullValue tos = lastFrame.getTopValue();
            boolean ifnull = (lastInSourceOpcode == Constants.IFNULL);
            ValueNumber prevTopValue = prevVnaFrame.getTopValue();

            return handleIfNull(tos, prevTopValue, ifnull);
        }
        case Constants.IF_ACMPEQ:
        case Constants.IF_ACMPNE: {
            IsNullValue tos = lastFrame.getStackValue(0);
            IsNullValue nextToTos = lastFrame.getStackValue(1);

            boolean tosNull = tos.isDefinitelyNull();
            boolean nextToTosNull = nextToTos.isDefinitelyNull();

            boolean cmpeq = (lastInSourceOpcode == Constants.IF_ACMPEQ);

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

            if (tosNull && nextToTosNull) {
                // Redundant comparison: both values are null, only one branch
                // is feasible
                value = null; // no value will be replaced - just want to
                // indicate that one of the branches is infeasible
                if (cmpeq) {
                    ifcmpDecision = IsNullValue.pathSensitiveNullValue();
                } else {
                    // cmpne
                    fallThroughDecision = IsNullValue.pathSensitiveNullValue();
                }
            } else if (tosNull || nextToTosNull) {
                if (tosNull) {
                    return handleIfNull(nextToTos, prevVnaFrame.getStackValue(1), cmpeq);
                }

                assert nextToTosNull;
                return handleIfNull(tos, prevVnaFrame.getStackValue(0), cmpeq);

            } else if (tos.isDefinitelyNotNull() && !nextToTos.isDefinitelyNotNull()) {
                // learn that nextToTos is definitely non null on one branch
                value = prevVnaFrame.getStackValue(1);
                if (cmpeq) {
                    ifcmpDecision = tos;
                    fallThroughDecision = nextToTos;
                } else {
                    fallThroughDecision = tos;
                    ifcmpDecision = nextToTos;
                }
            } else if (!tos.isDefinitelyNotNull() && nextToTos.isDefinitelyNotNull()) {
                // learn that tos is definitely non null on one branch
                value = prevVnaFrame.getStackValue(0);
                if (cmpeq) {
                    ifcmpDecision = nextToTos;
                    fallThroughDecision = tos;
                } else {
                    fallThroughDecision = nextToTos;
View Full Code Here

                    .getUnconditionalDerefParamDatabase();
            Iterator<BasicBlock> bbIter = cfg.blockIterator();
            ConstantPoolGen cpg = classContext.getConstantPoolGen();
            ValueNumber valueNumberForThis = null;
            if (!method.isStatic()) {
                ValueNumberFrame frameAtEntry = vna.getStartFact(cfg.getEntry());
                valueNumberForThis = frameAtEntry.getValue(0);
            }

            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;
                    }
                    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;
                    XMethod m = XFactory.createXMethod(inv, cpg);
                    SignatureParser sigParser = new SignatureParser(m.getSignature());
                    int numParams = sigParser.getNumParameters();

                    // Check nonnull annotations

                    for (int j = 0; j < numParams; j++) {
                        if (db.parameterMustBeNonNull(m, j)) {
                            int slot = sigParser.getSlotsFromTopOfStackForParameter(j);
                            ValueNumber valueNumber = valueNumberFrame.getStackValue(slot);
                            if (valueNumberForThis != valueNumber) {
                                derefs.add(location, valueNumber,
                                        PointerUsageRequiringNonNullValue.getPassedAsNonNullParameter(m, j));
                            }
                        }
                    }

                    // Check actual targets
                    try {
                        Set<JavaClassAndMethod> targetMethodSet = Hierarchy.resolveMethodCallTargets(inv, typeFrame, cpg);
                        BitSet unconditionallyDereferencedNullArgSet = null;
                        for (JavaClassAndMethod targetMethod : targetMethodSet) {

                            ParameterProperty property = unconditionalDerefParamDatabase.getProperty(targetMethod
                                    .toMethodDescriptor());
                            if (property == null) {
                                unconditionallyDereferencedNullArgSet = null;
                                break;
                            }
                            BitSet foo = property.getAsBitSet();
                            if (unconditionallyDereferencedNullArgSet == null) {
                                unconditionallyDereferencedNullArgSet = foo;
                            } else {
                                unconditionallyDereferencedNullArgSet.intersects(foo);
                            }
                            if (unconditionallyDereferencedNullArgSet.isEmpty()) {
                                break;
                            }
                        }

                        if (unconditionallyDereferencedNullArgSet != null && !unconditionallyDereferencedNullArgSet.isEmpty()
                                && valueNumberFrame.isValid()) {
                            for (int j = unconditionallyDereferencedNullArgSet.nextSetBit(0); j >= 0; j = unconditionallyDereferencedNullArgSet
                                    .nextSetBit(j + 1)) {
                                int slot = sigParser.getSlotsFromTopOfStackForParameter(j);
                                ValueNumber valueNumber = valueNumberFrame.getStackValue(slot);
                                if (valueNumberForThis != valueNumber) {
                                    derefs.add(location, valueNumber,
                                            PointerUsageRequiringNonNullValue.getPassedAsNonNullParameter(m, j));
                                }
                            }
                        }

                    } catch (ClassNotFoundException e) {
                        AnalysisContext.reportMissingClass(e);
                    }

                } else if (ins instanceof IFNONNULL && UnconditionalValueDerefAnalysis.isNullCheck(handle, cpg)) {
                    ValueNumber valueNumber = valueNumberFrame.getTopValue();
                    derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerNullChecked());
                } else if (ins instanceof ARETURN && methodAnnotation == NullnessAnnotation.NONNULL) {
                    ValueNumber valueNumber = valueNumberFrame.getTopValue();
                    if (valueNumberForThis != valueNumber) {
                        derefs.add(location, valueNumber,
                                PointerUsageRequiringNonNullValue.getReturnFromNonNullMethod(thisMethod));
                    }

                } else if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) {
                    FieldInstruction inf = (FieldInstruction) ins;
                    XField field = XFactory.createXField(inf, cpg);
                    NullnessAnnotation annotation = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase()
                            .getResolvedAnnotation(field, false);
                    if (annotation == NullnessAnnotation.NONNULL) {
                        ValueNumber valueNumber = valueNumberFrame.getTopValue();
                        if (valueNumberForThis != valueNumber) {
                            derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getStoredIntoNonNullField(field));
                        }
                    }
View Full Code Here

                    continue;
                }

                // The value number frame could be invalid if the basic
                // block became unreachable due to edge pruning (dead code).
                ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);
                if (!frame.isValid()) {
                    continue;
                }

                // Get lock set and instance value
                ValueNumber thisValue = !method.isStatic() ? vnaDataflow.getAnalysis().getThisValue() : null;
                LockSet lockSet = lockChecker.getFactAtLocation(location);
                InstructionHandle handle = location.getHandle();
                ValueNumber instance = frame.getInstance(handle.getInstruction(), cpg);
                if (DEBUG) {
                    System.out.println("Lock set: " + lockSet);
                    System.out.println("value number: " + instance.getNumber());
                    System.out.println("Lock count: " + lockSet.getLockCount(instance.getNumber()));
                }
View Full Code Here

            LockChecker lockChecker = classContext.getLockChecker(method);
            LockSet lockSet = lockChecker.getFactAtLocation(location);

            // Get value number frame for site
            ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
            ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);

            // NOTE: if the CFG on which the value number analysis was performed
            // was pruned, there may be unreachable instructions. Therefore,
            // we can't assume the frame is valid.
            if (!frame.isValid()) {
                continue;
            }

            // Find the ValueNumber of the receiver object
            int numConsumed = ins.consumeStack(cpg);
            MethodGen methodGen = classContext.getMethodGen(method);
            assert methodGen != null;
            if (numConsumed == Constants.UNPREDICTABLE) {
                throw new DataflowAnalysisException("Unpredictable stack consumption", methodGen, handle);
            }
            // if (DEBUG) System.out.println("Getting receiver for frame: " +
            // frame);
            ValueNumber instance = frame.getStackValue(numConsumed - 1);

            // Is the instance locked?
            int lockCount = lockSet.getLockCount(instance.getNumber());
            if (lockCount > 0) {
                // This is a locked call site
View Full Code Here

    }

    private Set<ValueNumber> getParameterValueNumbers(ClassContext classContext, Method method, CFG cfg)
            throws DataflowAnalysisException, CFGBuilderException {
        ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
        ValueNumberFrame vnaFrameAtEntry = vnaDataflow.getStartFact(cfg.getEntry());
        Set<ValueNumber> paramValueNumberSet = new HashSet<ValueNumber>();
        int firstParam = method.isStatic() ? 0 : 1;
        for (int i = firstParam; i < vnaFrameAtEntry.getNumLocals(); ++i) {
            paramValueNumberSet.add(vnaFrameAtEntry.getValue(i));
        }
        return paramValueNumberSet;
    }
View Full Code Here

            String refName = refSig2.substring(1, refSig2.length() - 1).replace('/', '.');

            if (vnaDataflow == null) {
                vnaDataflow = classContext.getValueNumberDataflow(method);
            }
            ValueNumberFrame vFrame = vnaDataflow.getFactAtLocation(location);
            if (paramValueNumberSet == null) {
                paramValueNumberSet = getParameterValueNumbers(classContext, method, cfg);
            }
            ValueNumber valueNumber = vFrame.getTopValue();
            BugAnnotation valueSource = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vFrame,
                    "VALUE_OF");
            // XXX call below causes 86% of all OpcodeStackDetector.EarlyExitException (getPC() == targetPC) thrown (13000 on java* JDK7 classes)
            BugAnnotation source = BugInstance.getSourceForTopStackValue(classContext, method, location);
            boolean isParameter = paramValueNumberSet.contains(valueNumber) && source instanceof LocalVariableAnnotation;
View Full Code Here

            return;
        }

        // Propagate flow values and source information across phi nodes.

        ValueNumberFrame targetVnaFrame = vnaDataflow.getStartFact(edge.getTarget());
        ValueNumberFrame sourceVnaFrame = vnaDataflow.getResultFact(edge.getSource());

        if (!targetVnaFrame.isValid() || !sourceVnaFrame.isValid()) {
            return;
        }

        // The source and target frames can have different numbers of slots
        // if the target is an exception handler.
        // So, merge the minimum number of slots in either frame.
        int numSlotsToMerge = Math.min(sourceVnaFrame.getNumSlots(), targetVnaFrame.getNumSlots());

        for (int i = 0; i < numSlotsToMerge; i++) {
            ValueNumber targetVN = targetVnaFrame.getValue(i);
            ValueNumber sourceVN = sourceVnaFrame.getValue(i);

            if (!targetVN.equals(sourceVN) && targetVN.hasFlag(ValueNumber.PHI_NODE)) {
                // targetVN is a phi result
                if (DEBUG_VERBOSE) {
                    System.out.println("Phi node: " + fact.valueNumberToString(sourceVN) + " -> "
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.vna.ValueNumberFrame

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.