Package org.apache.uima.cas.impl
Class CommonAuxHeap
- java.lang.Object
-
- org.apache.uima.cas.impl.CommonAuxHeap
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
DEBUG_LOG_SHRINK
protected static int
DEFAULT_HEAP_BASE_SIZE
protected static int
DEFAULT_HEAP_MULT_LIMIT
protected static int
FIRST_CELL_REF
protected static int
GROWTH_FACTOR
protected int
heapBaseSize
protected int
heapMultLimit
protected int
heapPos
protected static int
MIN_HEAP_BASE_SIZE
protected static int
NULL
private int[]
shrinkableCount
-
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()
-
-
-
Field Detail
-
DEBUG_LOG_SHRINK
private static final boolean DEBUG_LOG_SHRINK
- See Also:
- Constant Field Values
-
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
-
MIN_HEAP_BASE_SIZE
protected static final int MIN_HEAP_BASE_SIZE
- See Also:
- Constant Field Values
-
GROWTH_FACTOR
protected static final int GROWTH_FACTOR
- See Also:
- Constant Field Values
-
NULL
protected static final int NULL
- See Also:
- Constant Field Values
-
FIRST_CELL_REF
protected static final int FIRST_CELL_REF
- See Also:
- Constant Field Values
-
heapBaseSize
protected final int heapBaseSize
-
heapMultLimit
protected final int heapMultLimit
-
heapPos
protected int heapPos
-
shrinkableCount
private final int[] shrinkableCount
-
-
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 capacitysize_used
- the maximum number of used entries, <= current capacitygrowth_factor
- is 2multiplication_limit
- the point where we start adding this limit, vs using the growth factorshrinkableCount
- 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()
-
-