Class FindInconsistentSync2

  • All Implemented Interfaces:
    Detector, Priorities

    public class FindInconsistentSync2
    extends java.lang.Object
    implements Detector
    Find instance fields which are sometimes accessed (read or written) with the receiver lock held and sometimes without. These are candidates to be data races.
    • Field Detail

      • DEBUG

        private static final boolean DEBUG
      • 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.

      • singleThreadedServlet

        private static ClassDescriptor singleThreadedServlet
    • Constructor Detail

      • FindInconsistentSync2

        public FindInconsistentSync2​(BugReporter bugReporter)
    • Method Detail

      • isServletField

        public static boolean isServletField​(XField field)
      • 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)
      • isGetterMethod

        public static boolean isGetterMethod​(ClassContext classContext,
                                             org.apache.bcel.classfile.Method method)
        Determine whether or not 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
      • findNotUnlockedMethods

        private static 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.
      • findLockedMethods

        private static 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. We assume that nonpublic methods will only be called from within the class, which is not really a valid assumption.