Top Description Inners Fields Constructors Methods
org.jruby.util.collections

pack-priv Class ConcurrentAutoTable

Located in compilation unit of org.jruby.util.collections.NonBlockingHashMapLong.

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.jruby.util.collections.Counter

An auto-resizing table of longs, 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.

This API is overkill for simple counters (e.g. no need for the 'mask') and is untested as an API for making a scalable r/w lock and so is likely to change!

Author
Cliff Click
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private volatile ConcurrentAutoTable.CAT
private static final VarHandle

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
add(long x)

Add the given value to current counter value.

private long
add_if_mask(long x, long mask)

private boolean
public void
decrement()

add with -1

public long
estimate_get()

A cheaper get.

public long
get()

Current value of the counter.

private static final int
hash()

public void
increment()

add with +1

public int
internal_size()

Return the internal counter striping factor.

public int
intValue()

Same as get, included for completeness.

public long
longValue()

Same as get, included for completeness.

public void
set(long x)

Atomically set the sum of the striped counters to specified value.

public String
toString()

Overrides java.lang.Object.toString.

Return the counter's long value converted to a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_catback to summary
private volatile ConcurrentAutoTable.CAT _cat
catHandleback to summary
private static final VarHandle catHandle

Constructor Detail

ConcurrentAutoTableback to summary
pack-priv ConcurrentAutoTable()

Method Detail

addback to summary
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.

add_if_maskback to summary
private long add_if_mask(long x, long mask)
CAS_catback to summary
private boolean CAS_cat(ConcurrentAutoTable.CAT oldcat, ConcurrentAutoTable.CAT newcat)
decrementback to summary
public void decrement()

add with -1

estimate_getback to summary
public long estimate_get()

A cheaper get. Updated only once/millisecond, but as fast as a simple load instruction when not updating.

getback to summary
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.

hashback to summary
private static final int hash()
incrementback to summary
public void increment()

add with +1

internal_sizeback to summary
public int internal_size()

Return the internal counter striping factor. Useful for diagnosing performance problems.

intValueback to summary
public int intValue()

Same as get, included for completeness.

longValueback to summary
public long longValue()

Same as get, included for completeness.

setback to summary
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.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the counter's long value converted to a string.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

org.jruby.util.collections back to summary

private Class ConcurrentAutoTable.CAT

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private volatile long
private volatile long
private final ConcurrentAutoTable.CAT
pack-priv volatile long
private volatile long
private long[]
private static final int
private static final VarHandle

Constructor Summary

AccessConstructor and Description
pack-priv
CAT(ConcurrentAutoTable.CAT next, int sz, long init)

Method Summary

Modifier and TypeMethod and Description
public long
add_if_mask(long x, long mask, int hash, ConcurrentAutoTable master)

public void
all_and(long mask)

public void
all_or(long mask)

public void
all_set(long val)

private static final boolean
CAS(long[] A, int idx, long old, long nnn)

private static final boolean
CASnoUnsafe(long[] A, int idx, long old, long nnn)

public long
estimate_sum(long mask)

public long
sum(long mask)

pack-priv String
toString(long mask)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_fuzzy_sum_cacheback to summary
private volatile long _fuzzy_sum_cache
_fuzzy_timeback to summary
private volatile long _fuzzy_time
_nextback to summary
private final ConcurrentAutoTable.CAT _next
_resizersback to summary
pack-priv volatile long _resizers
_sum_cacheback to summary
private volatile long _sum_cache
_tback to summary
private long[] _t
MAX_SPINback to summary
private static final int MAX_SPIN
resizerHandleback to summary
private static final VarHandle resizerHandle

Constructor Detail

CATback to summary
pack-priv CAT(ConcurrentAutoTable.CAT next, int sz, long init)

Method Detail

add_if_maskback to summary
public long add_if_mask(long x, long mask, int hash, ConcurrentAutoTable master)
all_andback to summary
public void all_and(long mask)
all_orback to summary
public void all_or(long mask)
all_setback to summary
public void all_set(long val)
CASback to summary
private static final boolean CAS(long[] A, int idx, long old, long nnn)
CASnoUnsafeback to summary
private static final boolean CASnoUnsafe(long[] A, int idx, long old, long nnn)
estimate_sumback to summary
public long estimate_sum(long mask)
sumback to summary
public long sum(long mask)
toStringback to summary
pack-priv String toString(long mask)