Top Description Inners Fields Constructors Methods
io.netty.util.internal.shaded.org.jctools.maps

public Class NonBlockingHashMapLong<TypeV>

extends AbstractMap<Long, TypeV>
implements ConcurrentMap<Long, TypeV>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.concurrent.ConcurrentMap, java.util.Map
Type Parameters
<TypeV>
the type of mapped values
Imports
io.netty.util.internal.shaded.org.jctools.util.RangeUtil, java.io.IOException, .Serializable, java.util.*, java.util.concurrent.ConcurrentMap, java.util.concurrent.atomic.AtomicLongFieldUpdater, .AtomicReferenceFieldUpdater

A lock-free alternate implementation of java.util.concurrent.ConcurrentHashMap with primitive long keys, better scaling properties and generally lower costs. The use of long keys allows for faster compares and lower memory costs. The Map provides identical correctness properties as ConcurrentHashMap. All operations are non-blocking and multi-thread safe, including all update operations. NonBlockingHashMapLong scales substatially better than java.util.concurrent.ConcurrentHashMap for high update rates, even with a large concurrency factor. Scaling is linear up to 768 CPUs on a 768-CPU Azul box, even with 100% updates or 100% reads or any fraction in-between. Linear scaling up to all cpus has been observed on a 32-way Sun US2 box, 32-way Sun Niagra box, 8-way Intel box and a 4-way Power box.

The main benefit of this class over using plain io.netty.util.internal.shaded.org.jctools.maps.NonBlockingHashMap with Long keys is that it avoids the auto-boxing and unboxing costs. Since auto-boxing is automatic, it is easy to accidentally cause auto-boxing and negate the space and speed benefits.

This class obeys the same functional specification as java.util.Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, operations do not entail locking and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.

Operations (including put) generally do not block, so may overlap with other update operations (including other puts and removes). Retrievals reflect the results of the most recently completed update operations holding upon their onset. For aggregate operations such as putAll, concurrent retrievals may reflect insertion or removal of only some entries. Similarly, Iterators and Enumerations return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration. They do not throw ConcurrentModificationException. However, iterators are designed to be used by only one thread at a time.

Very full tables, or tables with high reprobe rates may trigger an internal resize operation to move into a larger table. Resizing is not terribly expensive, but it is not free either; during resize operations table throughput may drop somewhat. All threads that visit the table during a resize will 'help' the resizing but will still be allowed to complete their operation before the resize is finished (i.e., a simple 'get' operation on a million-entry table undergoing resizing will not need to block until the entire million entries are copied).

This class and its views and iterators implement all of the optional methods of the Map and Iterator interfaces.

Like Hashtable but unlike HashMap, this class does not allow null to be used as a value.

Author
Cliff Click
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public class
NonBlockingHashMapLong.IteratorLong

A class which implements the Iterator and Enumeration interfaces, generified to the Long class and supporting a non-auto-boxing nextLong function.

private class
private static class
private class
private class

Field Summary

Modifier and TypeField and Description
private transient NonBlockingHashMapLong.CHM
private static final long
private transient long
private static final int
private static final int
private static final int
private final boolean
private static final int
private transient Object
private static final long
private static final Object
private static final int
private static final int
private static final long
private static final Object
private static final int
private static final long
private static final NonBlockingHashMapLong.Prime
private static final Object

Constructor Summary

AccessConstructor and Description
public
NonBlockingHashMapLong()

Create a new NonBlockingHashMapLong with default minimum size (currently set to 8 K/V pairs or roughly 84 bytes on a standard 32-bit JVM).

public
NonBlockingHashMapLong(final int initial_sz)

Create a new NonBlockingHashMapLong with initial room for the given number of elements, thus avoiding internal resizing operations to reach an appropriate size.

public
NonBlockingHashMapLong(final boolean opt_for_space)

Create a new NonBlockingHashMapLong, setting the space-for-speed tradeoff.

public
NonBlockingHashMapLong(final int initial_sz, final boolean opt_for_space)

Create a new NonBlockingHashMapLong, setting both the initial size and the space-for-speed tradeoff.

Method Summary

Modifier and TypeMethod and Description
private final boolean
CAS(final long offset, final Object old, final Object nnn)

public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map.
public boolean

Returns:

true if this map maps one or more keys to the specified value
contains
(Object
a value to search for
val
)

Legacy method testing if some key maps into the specified value in this table.

public boolean

Returns:

true if the key is in the table
containsKey
(long key)

Tests if the key in the table.

public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Auto-boxing version of containsKey(long).
public boolean

Returns:

true if this Map maps one or more keys to the specified value
containsValue
(Object
value whose presence in this map is to be tested
val
)

Overrides java.util.AbstractMap.containsValue.

Implements java.util.Map.containsValue.

Returns true if this Map maps one or more keys to the specified value

Note

This method requires a full internal traversal of the hash table and is much slower than containsKey.

public Enumeration<TypeV>

Returns:

an enumeration of the values in this table
elements
()

Returns an enumeration of the values in this table.

public Set<Map.Entry<Long, TypeV>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public final TypeV
get(long key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public TypeV
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Auto-boxing version of get(long).
private void
private void
initialize(final int initial_sz)

public Enumeration<Long>

Returns:

an enumeration of the auto-boxed keys in this table
keys
()

Returns an enumeration of the auto-boxed keys in this table

Warning

this version will auto-box all returned keys.

public Set<Long>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map; with care the keys may be iterated over without auto-boxing.
public long[]
keySetLong()

Keys as a long array.

private void
private static void
print2_impl(final int i, final long K, final Object V)

public TypeV

Returns:

the previous value associated with key, or null if there was no mapping for key
put
(long
key with which the specified value is to be associated
key
,
TypeV
value to be associated with the specified key
val
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Maps the specified key to the specified value in the table.
public TypeV
put(Long
key with which the specified value is to be associated
key
,
TypeV
value to be associated with the specified key
val
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Auto-boxing version of put.
public TypeV

Returns:

the previous value associated with the specified key, or null if there was no mapping for the key
putIfAbsent
(long
key with which the specified value is to be associated
key
,
TypeV
value to be associated with the specified key
val
)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

Atomically, do a put if-and-only-if the key is not mapped.
public TypeV
putIfAbsent(Long
key with which the specified value is to be associated
key
,
TypeV
value to be associated with the specified key
val
)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

Auto-boxing version of putIfAbsent.
private TypeV
putIfMatch(long key, Object newVal, Object oldVal)

private static long
rawIndex(final Object[] ary, final int idx)

private static long
rawIndex(final long[] ary, final int idx)

private void
public TypeV

Returns:

the previous value associated with key, or null if there was no mapping for key
remove
(long key)

Removes the key (and its corresponding value) from this map.

public boolean
remove(long key, Object val)

Atomically do a remove(long) if-and-only-if the key is mapped to a value which is equals to the given value.

public TypeV
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Auto-boxing version of remove(long).
public boolean
remove(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
Val
)

Overrides default java.util.Map.remove.

Implements java.util.concurrent.ConcurrentMap.remove.

Auto-boxing version of remove(long, Object).
public TypeV
replace(long
key with which the specified value is associated
key
,
TypeV
value to be associated with the specified key
val
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Atomically do a put(key,val) if-and-only-if the key is mapped to some value already.
public boolean
replace(long
key with which the specified value is associated
key
,
TypeV
value expected to be associated with the specified key
oldValue
,
TypeV
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Atomically do a put(key,newValue) if-and-only-if the key is mapped a value which is equals to oldValue.
public TypeV
replace(Long
key with which the specified value is associated
key
,
TypeV
value to be associated with the specified key
Val
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Auto-boxing version of replace.
public boolean
replace(Long
key with which the specified value is associated
key
,
TypeV
value expected to be associated with the specified key
oldValue
,
TypeV
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Auto-boxing version of replace.
private static int
reprobe_limit(int len)

public int

Returns:

the number of key-value mappings in this map
size
()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
public Collection<TypeV>
values()

Overrides java.util.AbstractMap.values.

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.
private void
Inherited from java.util.AbstractMap:
cloneequalshashCodeisEmptyputAlltoString