Package org.jctools.maps
Class ConcurrentAutoTable
- java.lang.Object
-
- org.jctools.maps.ConcurrentAutoTable
-
- All Implemented Interfaces:
java.io.Serializable
public class ConcurrentAutoTable extends java.lang.Object implements java.io.SerializableAn auto-resizing table oflongs, supporting low-contention CAS operations. Updates are done with CAS's to no particular table element. The intent is to support highly scalable counters, r/w locks, and other structures where the updates are associative, loss-free (no-brainer), and otherwise happen at such a high volume that the cache contention for CAS'ing a single word is unacceptable.- Since:
- 1.5
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classConcurrentAutoTable.CAT
-
Field Summary
Fields Modifier and Type Field Description private ConcurrentAutoTable.CAT_catprivate static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentAutoTable,ConcurrentAutoTable.CAT>_catUpdater
-
Constructor Summary
Constructors Constructor Description ConcurrentAutoTable()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long x)Add the given value to current counter value.private longadd_if(long x)private booleanCAS_cat(ConcurrentAutoTable.CAT oldcat, ConcurrentAutoTable.CAT newcat)voiddecrement()add(long)with -1longestimate_get()A cheaperget().longget()Current value of the counter.private static inthash()voidincrement()add(long)with +1intinternal_size()Return the internal counter striping factor.intintValue()Same asget(), included for completeness.longlongValue()Same asget(), included for completeness.voidprint()A more verbose print thantoString(), showing internal structure.voidset(long x)Atomically set the sum of the striped counters to specified value.java.lang.StringtoString()Return the counter'slongvalue converted to a string.
-
-
-
Field Detail
-
_cat
private volatile ConcurrentAutoTable.CAT _cat
-
_catUpdater
private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentAutoTable,ConcurrentAutoTable.CAT> _catUpdater
-
-
Method Detail
-
add
public void add(long x)
Add the given value to current counter value. Concurrent updates will not be lost, but addAndGet or getAndAdd are not implemented because the total counter value (i.e.,get()) is not atomically updated. Updates are striped across an array of counters to avoid cache contention and has been tested with performance scaling linearly up to 768 CPUs.
-
decrement
public void decrement()
add(long)with -1
-
increment
public void increment()
add(long)with +1
-
set
public void set(long x)
Atomically set the sum of the striped counters to specified value. Rather more expensive than a simple store, in order to remain atomic.
-
get
public long get()
Current value of the counter. Since other threads are updating furiously the value is only approximate, but it includes all counts made by the current thread. Requires a pass over the internally striped counters.
-
intValue
public int intValue()
Same asget(), included for completeness.
-
longValue
public long longValue()
Same asget(), included for completeness.
-
estimate_get
public long estimate_get()
A cheaperget(). Updated only once/millisecond, but as fast as a simple load instruction when not updating.
-
toString
public java.lang.String toString()
Return the counter'slongvalue converted to a string.- Overrides:
toStringin classjava.lang.Object
-
print
public void print()
A more verbose print thantoString(), showing internal structure. Useful for debugging.
-
internal_size
public int internal_size()
Return the internal counter striping factor. Useful for diagnosing performance problems.
-
add_if
private long add_if(long x)
-
CAS_cat
private boolean CAS_cat(ConcurrentAutoTable.CAT oldcat, ConcurrentAutoTable.CAT newcat)
-
hash
private static int hash()
-
-