Class CommonAuxHeap

  • Direct Known Subclasses:
    ByteHeap, LongHeap, ShortHeap

    abstract class CommonAuxHeap
    extends java.lang.Object
    Encapsulate 8, 16, and 64 bit storage for the CAS.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommonAuxHeap()  
      CommonAuxHeap​(int heapBaseSize, int heapMultLimit)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int computeNewArraySize​(int size, int needed_size, int growth_factor, int multiplication_limit)  
      (package private) static int computeShrunkArraySize​(int capacity, int size_used, int growth_factor, int multiplication_limit, int min_size, int[] shrinkableCount)
      This routine is used to compute the capacity an internal expandable array should be reallocated to, upon reset.
      (package private) abstract int getCapacity()  
      (package private) int getSize()  
      (package private) abstract void growHeapIfNeeded()  
      (package private) abstract void initMemory()  
      (package private) abstract void initMemory​(int size)  
      (package private) int reserve​(int numCells)  
      (package private) void reset()  
      (package private) void reset​(boolean doFullReset)
      Logic for shrinking: Based on a short history of the capacity needed to hold the larger of the previous 2 sizes (Note: can be overridden by calling reset() multiple times in a row) Never shrink below initialSize Shrink in exact reverse sequence of growth - using the subtraction method and then (for small enough sizes) the dividing method Shrink by one jump if that is large enough to hold the larger of the prev 2 sizes
      (package private) abstract void resetToZeros()  
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_HEAP_BASE_SIZE

        protected static final int DEFAULT_HEAP_BASE_SIZE
        See Also:
        Constant Field Values
      • DEFAULT_HEAP_MULT_LIMIT

        protected static final int DEFAULT_HEAP_MULT_LIMIT
        See Also:
        Constant Field Values
      • heapBaseSize

        protected final int heapBaseSize
      • heapMultLimit

        protected final int heapMultLimit
      • heapPos

        protected int heapPos
      • shrinkableCount

        private final int[] shrinkableCount
    • Constructor Detail

      • CommonAuxHeap

        CommonAuxHeap()
      • CommonAuxHeap

        CommonAuxHeap​(int heapBaseSize,
                      int heapMultLimit)
    • Method Detail

      • initMemory

        abstract void initMemory()
      • initMemory

        abstract void initMemory​(int size)
      • resetToZeros

        abstract void resetToZeros()
      • growHeapIfNeeded

        abstract void growHeapIfNeeded()
      • reset

        void reset()
      • reset

        void reset​(boolean doFullReset)
        Logic for shrinking: Based on a short history of the capacity needed to hold the larger of the previous 2 sizes (Note: can be overridden by calling reset() multiple times in a row) Never shrink below initialSize Shrink in exact reverse sequence of growth - using the subtraction method and then (for small enough sizes) the dividing method Shrink by one jump if that is large enough to hold the larger of the prev 2 sizes
        Parameters:
        doFullReset - true means reallocate from scratch
      • reserve

        int reserve​(int numCells)
      • computeNewArraySize

        int computeNewArraySize​(int size,
                                int needed_size,
                                int growth_factor,
                                int multiplication_limit)
      • computeShrunkArraySize

        static int computeShrunkArraySize​(int capacity,
                                          int size_used,
                                          int growth_factor,
                                          int multiplication_limit,
                                          int min_size,
                                          int[] shrinkableCount)
        This routine is used to compute the capacity an internal expandable array should be reallocated to, upon reset. It returns at most a 1 increment shrink, based on the doubling up to multiplication limit, then addition thereafter. It maintains a shrinkableCount - the number of consecutive times this could be shrunk. This is reset to 0 if current size requires current capacity, that is, no shrinkage is possible for current size. Otherwise, the count is incremented. If the shrinkableCount is incremented to exceed 20, the capacity is allowed to drop by 1 allocation unit. This guarantees the shrinkages are delayed until 20 shrinkable sizes are found (with no intervening non-shrinkable ones). When a shrinkage happens, the count is reset to 16; this delays subsequent shrinkages to happen only every (20 - 16) 4 resets.
        Parameters:
        capacity - the current capacity
        size_used - the maximum number of used entries, <= current capacity
        growth_factor - is 2
        multiplication_limit - the point where we start adding this limit, vs using the growth factor
        shrinkableCount - a pass-by-reference int reflecting the number of times it was shrinkable
        Returns:
        the capacity shrink down by one step, if that will still hold the size_used number of entries, minimum limited to min_size.
      • getSize

        int getSize()
      • getCapacity

        abstract int getCapacity()