Package org.apache.uima.jcas.impl
Class JCasHashMapSubMap
- java.lang.Object
-
- org.apache.uima.jcas.impl.JCasHashMapSubMap
-
-
Field Summary
Fields Modifier and Type Field Description private int
concurrencyLevelBits
(package private) int
continues
(package private) int[]
histogram
private float
loadFactor
(package private) int
maxProbe
(package private) int
maxProbeAfterContinue
private static int
PROBE_ADDR_INDEX
private static int
PROBE_DELTA_INDEX
(package private) static java.lang.ThreadLocal<int[]>
probeInfoGet
(package private) static java.lang.ThreadLocal<int[]>
probeInfoPutInner
private boolean
secondTimeShrinkable
(package private) int
size
private int
sizeWhichTriggersExpansion
private int
subMapInitialCapacity
private java.lang.Object
synclock
This lock is sometimes held by put, putIfAbsent, get, clear - not held if putIfAbsent or get find existing (non-reserve) item -- assumes no "remove" operation(package private) TOP[]
table
private static boolean
TUNE
-
Constructor Summary
Constructors Constructor Description JCasHashMapSubMap(float loadFactor, int subMapInitialCapacity, int concurrencyLevelBits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
clear()
private TOP
find(TOP[] localTable, int key, int hash, int[] probeInfo)
find a real item or a reserve item, matching the key Can be called under lock or not.(package private) TOP
get(int key, int hash)
Gets a value.private void
increaseTableCapacity()
private void
incrementSize()
private static boolean
isReserve(TOP m)
IteratorNvc<TOP>
iterator()
private JCasHashMapSubMap
newTable(int capacity)
private TOP[]
newTableKeepSize(int capacity)
(package private) TOP
put(int key, TOP value, int hash)
Puts a new value into the table, replacing an existing one if there is an entry already, or adding a new entry Starts by acquiring the lock.(package private) TOP
putIfAbsent(int key, int hash, java.util.function.IntFunction<TOP> creatorFromKey)
If an entry isn't already present for this key, calls a Supplier to create a value and puts it into the table.private void
putInner(int key, TOP value, int hash, int[] probeInfo)
Only used to fill in newly expanded table always called with lock heldprivate TOP
re_find(TOP[] localTable, int key, int hash, int[] probeInfo)
private static void
resetProbeInfo(int[] probeInfo)
private static void
setProbeInfo(int[] probeInfo, int probeAddr, int probeDelta)
private void
updateHistogram(int nbrProbes, boolean isContinue)
-
-
-
Field Detail
-
TUNE
private static final boolean TUNE
- See Also:
- Constant Field Values
-
PROBE_ADDR_INDEX
private static final int PROBE_ADDR_INDEX
- See Also:
- Constant Field Values
-
PROBE_DELTA_INDEX
private static final int PROBE_DELTA_INDEX
- See Also:
- Constant Field Values
-
probeInfoGet
static final java.lang.ThreadLocal<int[]> probeInfoGet
-
probeInfoPutInner
static final java.lang.ThreadLocal<int[]> probeInfoPutInner
-
histogram
int[] histogram
-
maxProbe
int maxProbe
-
maxProbeAfterContinue
int maxProbeAfterContinue
-
continues
int continues
-
synclock
private final java.lang.Object synclock
This lock is sometimes held by put, putIfAbsent, get, clear - not held if putIfAbsent or get find existing (non-reserve) item -- assumes no "remove" operation
-
sizeWhichTriggersExpansion
private int sizeWhichTriggersExpansion
-
size
int size
-
table
volatile TOP[] table
-
secondTimeShrinkable
private boolean secondTimeShrinkable
-
loadFactor
private final float loadFactor
-
subMapInitialCapacity
private final int subMapInitialCapacity
-
concurrencyLevelBits
private final int concurrencyLevelBits
-
-
Method Detail
-
newTable
private JCasHashMapSubMap newTable(int capacity)
-
newTableKeepSize
private TOP[] newTableKeepSize(int capacity)
-
incrementSize
private void incrementSize()
-
clear
void clear()
-
find
private TOP find(TOP[] localTable, int key, int hash, int[] probeInfo)
find a real item or a reserve item, matching the key Can be called under lock or not. Using a ref to the current value of table, searches that int array. If, during the search, the table is resized, it continues using the ** before the resize ** int array referenced by localTable The answer will only be OK if the key is found for a real value. Results that yield null or Reserved slots must be re-searched, under a lock (caller needs to do this).- Parameters:
key
- -hash
- -probeInfo
- - used to get/receive multiple int values; 0: (in/out) startProbe or -1; -1 starts at the hash & bitMask 1: (in/out) probeDelta (starts at 1)- Returns:
- the probeAddr in original table (which might have been resized)
-
updateHistogram
private void updateHistogram(int nbrProbes, boolean isContinue)
-
putIfAbsent
TOP putIfAbsent(int key, int hash, java.util.function.IntFunction<TOP> creatorFromKey)
If an entry isn't already present for this key, calls a Supplier to create a value and puts it into the table. otherwise, doesn't call the Supplier and returns the already present value. If the key isn't present, gets a lock, and (partially, as necessary) redoes the find. - assert key still not present. - add a "reserve" for the slot where it will go -- reserve is a pseudo FS with a matching key, but with null _casView - release the lock -- eval the creator to create the item (may cause table to be updated) - require the lock - if resized, redo the find() till find the reserved item, and replace it with value. - if not resized, replace the prev reserved spot. Threading: not synchronized for main path where finding the element (if already in table). Since elements are never updated, there is no race if an element is found, except for table being resized. And it doesn't matter if the table is resized (if the element is found).- Parameters:
key
- - the id to use as the keyhash
- - the hash that was already computed from the keycreatorFromKey
- - the function to call to create the item.- Returns:
- - the found fs in the table with the same key, or the newly created item.
-
put
final TOP put(int key, TOP value, int hash)
Puts a new value into the table, replacing an existing one if there is an entry already, or adding a new entry Starts by acquiring the lock.- Parameters:
key
- - the id to use as the keyhash
- - the hash that was already computed from the keycreator
- - the new value- Returns:
- - the previous fs in the table with the same key, or null
-
get
final TOP get(int key, int hash)
Gets a value. Threading: not synchronized for main path where get is finding an element. Since elements are never updated, there is no race if an element is found. And it doesn't matter if the table is resized (if the element is found). If it is not found, need to get the lock in order to get memory synch, and start over if resized, or continue from reserved or null spot if not- Parameters:
key
- - the addr in the heaphash
- - the hash that was already computed from the key- Returns:
- - the found fs, or null
-
putInner
private void putInner(int key, TOP value, int hash, int[] probeInfo)
Only used to fill in newly expanded table always called with lock held- Parameters:
key
- -value
- -hash
- -
-
increaseTableCapacity
private void increaseTableCapacity()
-
isReserve
private static boolean isReserve(TOP m)
-
resetProbeInfo
private static void resetProbeInfo(int[] probeInfo)
-
setProbeInfo
private static void setProbeInfo(int[] probeInfo, int probeAddr, int probeDelta)
-
iterator
public IteratorNvc<TOP> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<TOP>
-
-