edu.umd.cs.findbugs.detect
Class FindInconsistentSync2

java.lang.Object
  extended by edu.umd.cs.findbugs.detect.FindInconsistentSync2
All Implemented Interfaces:
Detector

public class FindInconsistentSync2
extends java.lang.Object
implements Detector


Nested Class Summary
private static class FindInconsistentSync2.FieldStats
          The access statistics for a field.
 
Field Summary
private static boolean ADJUST_SUBCLASS_ACCESSES
           
private  BugReporter bugReporter
           
private static boolean DEBUG
           
private static boolean EVAL
           
private static int LOCKED
           
private static int MIN_SYNC_PERCENT
          Minimum percent of unbiased field accesses that must be synchronized in order to report a field as inconsistently synchronized.
private static int READ
           
private static int READ_LOCKED
           
private static int READ_UNLOCKED
           
private  java.util.Map<XField,FindInconsistentSync2.FieldStats> statMap
           
private static boolean SYNC_ACCESS
           
private static int UNLOCKED
           
private static double UNSYNC_FACTOR
          Factor which the biased number of unsynchronized accesses is multiplied by.
private static int WRITE
           
private static double WRITE_BIAS
          Bias that writes are given with respect to reads.
private static int WRITE_LOCKED
           
private static int WRITE_UNLOCKED
           
 
Fields inherited from interface edu.umd.cs.findbugs.Detector
EXP_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
 
Constructor Summary
FindInconsistentSync2(BugReporter bugReporter)
           
 
Method Summary
private  void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method, java.util.Set<org.apache.bcel.classfile.Method> lockedMethodSet)
           
private  java.util.Set<org.apache.bcel.classfile.Method> findLockedMethods(ClassContext classContext, SelfCalls selfCalls, java.util.Set<CallSite> obviouslyLockedSites)
          Find methods that appear to always be called from a locked context.
private  java.util.Set<org.apache.bcel.classfile.Method> findNotUnlockedMethods(ClassContext classContext, SelfCalls selfCalls, java.util.Set<CallSite> obviouslyLockedSites)
          Find methods that appear to never be called from an unlocked context We assume that nonpublic methods will only be called from within the class, which is not really a valid assumption.
private  java.util.Set<CallSite> findObviouslyLockedCallSites(ClassContext classContext, SelfCalls selfCalls)
          Find all self-call sites that are obviously locked.
private  java.util.Set<org.apache.bcel.classfile.Method> findPublicReachableMethods(ClassContext classContext, SelfCalls selfCalls)
          Find methods that do not appear to be reachable from public methods.
private  FindInconsistentSync2.FieldStats getStats(XField field)
          Get the access statistics for given field.
private static boolean isConstructor(java.lang.String methodName)
           
static boolean isGetterMethod(ClassContext classContext, org.apache.bcel.classfile.Method method)
          Determine whether or not the the given method is a getter method.
 void report()
          This method is called after all classes to be visited.
 void setAnalysisContext(AnalysisContext analysisContext)
          Set the AnalysisContext that will be used.
 void visitClassContext(ClassContext classContext)
          Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

SYNC_ACCESS

private static final boolean SYNC_ACCESS
See Also:
Constant Field Values

ADJUST_SUBCLASS_ACCESSES

private static final boolean ADJUST_SUBCLASS_ACCESSES

EVAL

private static final boolean EVAL

MIN_SYNC_PERCENT

private static final int MIN_SYNC_PERCENT
Minimum percent of unbiased field accesses that must be synchronized in order to report a field as inconsistently synchronized. This is meant to distinguish incidental synchronization from intentional synchronization.


WRITE_BIAS

private static final double WRITE_BIAS
Bias that writes are given with respect to reads. The idea is that this should be above 1.0, because unsynchronized writes are more dangerous than unsynchronized reads.


UNSYNC_FACTOR

private static final double UNSYNC_FACTOR
Factor which the biased number of unsynchronized accesses is multiplied by. I.e., for factor f, if nUnsync is the biased number of unsynchronized accesses, and nSync is the biased number of synchronized accesses, and
      f(nUnsync) > nSync
 
then we report a bug. Default value is 2.0, which means that we report a bug if more than 1/3 of accesses are unsynchronized.

Note that MIN_SYNC_PERCENT also influences whether we report a bug: it specifies the minimum unbiased percentage of synchronized accesses.


UNLOCKED

private static final int UNLOCKED
See Also:
Constant Field Values

LOCKED

private static final int LOCKED
See Also:
Constant Field Values

READ

private static final int READ
See Also:
Constant Field Values

WRITE

private static final int WRITE
See Also:
Constant Field Values

READ_UNLOCKED

private static final int READ_UNLOCKED
See Also:
Constant Field Values

WRITE_UNLOCKED

private static final int WRITE_UNLOCKED
See Also:
Constant Field Values

READ_LOCKED

private static final int READ_LOCKED
See Also:
Constant Field Values

WRITE_LOCKED

private static final int WRITE_LOCKED
See Also:
Constant Field Values

bugReporter

private BugReporter bugReporter

statMap

private java.util.Map<XField,FindInconsistentSync2.FieldStats> statMap
Constructor Detail

FindInconsistentSync2

public FindInconsistentSync2(BugReporter bugReporter)
Method Detail

setAnalysisContext

public void setAnalysisContext(AnalysisContext analysisContext)
Description copied from interface: Detector
Set the AnalysisContext that will be used. This is called before visitClassContext() is called on any class to be analyzed.

Specified by:
setAnalysisContext in interface Detector
Parameters:
analysisContext - the AnalysisContext

visitClassContext

public void visitClassContext(ClassContext classContext)
Description copied from interface: Detector
Visit the ClassContext for a class which should be analyzed for instances of bug patterns.

Specified by:
visitClassContext in interface Detector
Parameters:
classContext - the ClassContext

report

public void report()
Description copied from interface: Detector
This method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results.

Specified by:
report in interface Detector

isConstructor

private static boolean isConstructor(java.lang.String methodName)

analyzeMethod

private void analyzeMethod(ClassContext classContext,
                           org.apache.bcel.classfile.Method method,
                           java.util.Set<org.apache.bcel.classfile.Method> lockedMethodSet)
                    throws CFGBuilderException,
                           DataflowAnalysisException
Throws:
CFGBuilderException
DataflowAnalysisException

isGetterMethod

public static boolean isGetterMethod(ClassContext classContext,
                                     org.apache.bcel.classfile.Method method)
Determine whether or not the the given method is a getter method. I.e., if it just returns the value of an instance field.

Parameters:
classContext - the ClassContext for the class containing the method
method - the method

getStats

private FindInconsistentSync2.FieldStats getStats(XField field)
Get the access statistics for given field.


findNotUnlockedMethods

private java.util.Set<org.apache.bcel.classfile.Method> findNotUnlockedMethods(ClassContext classContext,
                                                                               SelfCalls selfCalls,
                                                                               java.util.Set<CallSite> obviouslyLockedSites)
                                                                        throws CFGBuilderException,
                                                                               DataflowAnalysisException
Find methods that appear to never be called from an unlocked context We assume that nonpublic methods will only be called from within the class, which is not really a valid assumption.

Throws:
CFGBuilderException
DataflowAnalysisException

findLockedMethods

private java.util.Set<org.apache.bcel.classfile.Method> findLockedMethods(ClassContext classContext,
                                                                          SelfCalls selfCalls,
                                                                          java.util.Set<CallSite> obviouslyLockedSites)
                                                                   throws CFGBuilderException,
                                                                          DataflowAnalysisException
Find methods that appear to always be called from a locked context. We assume that nonpublic methods will only be called from within the class, which is not really a valid assumption.

Throws:
CFGBuilderException
DataflowAnalysisException

findPublicReachableMethods

private java.util.Set<org.apache.bcel.classfile.Method> findPublicReachableMethods(ClassContext classContext,
                                                                                   SelfCalls selfCalls)
                                                                            throws CFGBuilderException,
                                                                                   DataflowAnalysisException
Find methods that do not appear to be reachable from public methods. Such methods will not be analyzed.

Throws:
CFGBuilderException
DataflowAnalysisException

findObviouslyLockedCallSites

private java.util.Set<CallSite> findObviouslyLockedCallSites(ClassContext classContext,
                                                             SelfCalls selfCalls)
                                                      throws CFGBuilderException,
                                                             DataflowAnalysisException
Find all self-call sites that are obviously locked.

Throws:
CFGBuilderException
DataflowAnalysisException