Package edu.umd.cs.findbugs.ba

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


    private boolean isLocked() {
        try {
            if (currentMethod != null && currentLockDataFlow != null && currentCFG != null) {
                Collection<Location> tLocations = currentCFG.getLocationsContainingInstructionWithOffset(getPC());
                for (Location tLoc : tLocations) {
                    LockSet lockSet = currentLockDataFlow.getFactAtLocation(tLoc);
                    if (lockSet.getNumLockedObjects() > 0) {
                        // within a synchronized block
                        return true;
                    }
                }
            }
View Full Code Here


        // object
        //
        // We ignore matches where a lock is held consistently,
        // or if the extent does not appear to create a new object.
        LockDataflow lockDataflow = classContext.getLockDataflow(method);
        LockSet lockSet = null;
        boolean sawNEW = false, sawINVOKE = false;
        for (BasicBlock block : cfg.getBlocks(extent)) {
            for (Iterator<InstructionHandle> j = block.instructionIterator(); j.hasNext();) {
                InstructionHandle handle = j.next();
                if (handle.equals(store.getMatchedInstructionInstructionHandle())) {
                    break;
                }
                Location location = new Location(handle, block);

                // Keep track of whether we saw any instructions
                // that might actually have created a new object.
                Instruction ins = handle.getInstruction();
                if (DEBUG) {
                    System.out.println(location);
                }
                if (ins instanceof AllocationInstruction) {
                    sawNEW = true;
                } else if (ins instanceof InvokeInstruction) {
                    if (ins instanceof INVOKESTATIC
                            && ((INVOKESTATIC) ins).getMethodName(classContext.getConstantPoolGen()).startsWith("new")) {
                        sawNEW = true;
                    }
                    sawINVOKE = true;
                }

                // Compute lock set intersection for all matched
                // instructions.
                LockSet insLockSet = lockDataflow.getFactAtLocation(location);
                if (lockSet == null) {
                    lockSet = new LockSet();
                    lockSet.copyFrom(insLockSet);
                } else {
                    lockSet.intersectWith(insLockSet);
                }
            }
View Full Code Here

                continue;
            }

            // System.out.println("Found sleep at " + location.getHandle());

            LockSet lockSet = lockDataflow.getFactAtLocation(location);
            if (lockSet.getNumLockedObjects() > 0) {
                bugAccumulator.accumulateBug(
                        new BugInstance(this, "SWL_SLEEP_WITH_LOCK_HELD", NORMAL_PRIORITY).addClassAndMethod(
                                classContext.getJavaClass(), method), classContext, method, location);
            }
        }
View Full Code Here

                }
                if (frame.getStackDepth() - numConsumed < 0) {
                    throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
                }
                ValueNumber ref = frame.getValue(frame.getNumSlots() - numConsumed);
                LockSet lockSet = dataflow.getFactAtLocation(location);
                int lockCount = lockSet.getLockCount(ref.getNumber());

                if (lockCount == 0) {
                    Collection<ValueNumber> lockedValueNumbers = lockSet.getLockedValueNumbers(frame);
                    boolean foundMatch = false;
                    for (ValueNumber v : lockedValueNumbers) {
                        if (frame.veryFuzzyMatch(ref, v)) {
                            foundMatch = true;
                            break;
View Full Code Here

                    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()));
                }

                // Is the instance locked?
                // We consider the access to be locked if either
                // - the object is explicitly locked, or
                // - the field is accessed through the "this" reference,
                // and the method is in the locked method set, or
                // - any value returned by a called method is locked;
                // the (conservative) assumption is that the return lock object
                // is correct for synchronizing the access
                boolean isExplicitlyLocked = lockSet.getLockCount(instance.getNumber()) > 0;
                boolean isAccessedThroughThis = thisValue != null && thisValue.equals(instance);
                boolean isLocked = isExplicitlyLocked
                        || ((isConstructor(method.getName()) || lockedMethodSet.contains(method)) && isAccessedThroughThis)
                        || lockSet.containsReturnValue(vnaDataflow.getAnalysis().getFactory());

                // Adjust the field so its class name is the same
                // as the type of reference it is accessed through.
                // This helps fix false positives produced when a
                // threadsafe class is extended by a subclass that
View Full Code Here

                continue;
            }

            // Get lock set for site
            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
                obviouslyLockedSites.add(callSite);
            }
        }
View Full Code Here

TOP

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

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.