Class LockSet


  • public final class LockSet
    extends java.lang.Object
    Lock counts for values (as produced by ValueNumberAnalysis). A LockSet tells us the lock counts for all values in a method, insofar as we can accurately determine them.
    See Also:
    ValueNumberAnalysis
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] array
      Lock counts are stored in an array.
      static int BOTTOM
      An invalid lock count resulting from the meet of two different (inconsistent) lock counts.
      private static int DEFAULT_CAPACITY  
      private int defaultLockCount
      The lock count value to return for nonexistent lock entries.
      private static int INVALID  
      static int TOP
      An uninitialized lock value.
    • Constructor Summary

      Constructors 
      Constructor Description
      LockSet()
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addEntry​(int negatedIndex, int valueNumber, int lockCount)  
      void clear()
      Clear all entries out of this LockSet.
      boolean containsReturnValue​(ValueNumberFactory factory)
      Determine whether or not this lock set contains any locked values which are method return values.
      void copyFrom​(LockSet other)
      Make this LockSet the same as the given one.
      private int findIndex​(int valueNumber)  
      int getLockCount​(int valueNumber)
      Get the lock count for given lock object.
      java.util.Collection<ValueNumber> getLockedValueNumbers​(ValueNumberFrame frame)  
      int getNumLockedObjects()
      Get the number of distinct lock values with positive lock counts.
      private boolean identicalSubset​(LockSet other)  
      void intersectWith​(LockSet other)
      Destructively intersect this lock set with another.
      boolean isEmpty()
      Return whether or not this lock set is empty, meaning that no locks have a positive lock count.
      boolean isTop()  
      void meetWith​(LockSet other)
      Meet this LockSet with another LockSet, storing the result in this object.
      private static int mergeValues​(int a, int b)  
      boolean sameAs​(LockSet other)
      Return whether or not this LockSet is the same as the one given.
      void setDefaultLockCount​(int defaultLockCount)
      Set the default lock count to return for nonexistent lock entries.
      void setLockCount​(int valueNumber, int lockCount)
      Set the lock count for a lock object.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • BOTTOM

        public static final int BOTTOM
        An invalid lock count resulting from the meet of two different (inconsistent) lock counts.
        See Also:
        Constant Field Values
      • array

        private int[] array
        Lock counts are stored in an array. Even indices i are value numbers of lock objects. Odd indices i+1 are lock counts. This representation is fairly compact in memory.
      • defaultLockCount

        private int defaultLockCount
        The lock count value to return for nonexistent lock entries.
    • Constructor Detail

      • LockSet

        public LockSet()
        Constructor. Creates an empty lock set which returns TOP for nonexistent lock entries.
    • Method Detail

      • getLockCount

        public int getLockCount​(int valueNumber)
        Get the lock count for given lock object.
        Parameters:
        valueNumber - value number of the lock object
        Returns:
        the lock count for the lock object
      • isTop

        public boolean isTop()
      • setLockCount

        public void setLockCount​(int valueNumber,
                                 int lockCount)
        Set the lock count for a lock object.
        Parameters:
        valueNumber - value number of the lock object
        lockCount - the lock count for the lock
      • setDefaultLockCount

        public void setDefaultLockCount​(int defaultLockCount)
        Set the default lock count to return for nonexistent lock entries.
        Parameters:
        defaultLockCount - the default lock count value
      • getNumLockedObjects

        public int getNumLockedObjects()
        Get the number of distinct lock values with positive lock counts.
      • copyFrom

        public void copyFrom​(LockSet other)
        Make this LockSet the same as the given one.
        Parameters:
        other - the LockSet to copy
      • clear

        public void clear()
        Clear all entries out of this LockSet.
      • meetWith

        public void meetWith​(LockSet other)
        Meet this LockSet with another LockSet, storing the result in this object.
        Parameters:
        other - the other LockSet
      • sameAs

        public boolean sameAs​(LockSet other)
        Return whether or not this LockSet is the same as the one given.
        Parameters:
        other - the other LockSet
      • containsReturnValue

        public boolean containsReturnValue​(ValueNumberFactory factory)
        Determine whether or not this lock set contains any locked values which are method return values.
        Parameters:
        factory - the ValueNumberFactory that produced the lock values
      • intersectWith

        public void intersectWith​(LockSet other)
        Destructively intersect this lock set with another. Note that this is not a dataflow merge: we are interested in finding out which locks are held in both sets, not in the exact lock counts.
        Parameters:
        other - the other LockSet
      • isEmpty

        public boolean isEmpty()
        Return whether or not this lock set is empty, meaning that no locks have a positive lock count.
        Returns:
        true if no locks are held, false if at least one lock is held
      • identicalSubset

        private boolean identicalSubset​(LockSet other)
      • mergeValues

        private static int mergeValues​(int a,
                                       int b)
      • findIndex

        private int findIndex​(int valueNumber)
      • addEntry

        private void addEntry​(int negatedIndex,
                              int valueNumber,
                              int lockCount)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getLockedValueNumbers

        public java.util.Collection<ValueNumber> getLockedValueNumbers​(ValueNumberFrame frame)
        Parameters:
        frame -
        Returns:
        a set of the locked value numbers