public interface AtomicBuffer extends MutableDirectBuffer
| Modifier and Type | Field and Description |
|---|---|
static int |
ALIGNMENT
Buffer alignment in bytes to ensure atomic word accesses.
|
static boolean |
STRICT_ALIGNMENT_CHECKS
Should alignment checks for atomic operations be done or not.
|
static String |
STRICT_ALIGNMENT_CHECKS_PROP_NAME
Name of the system property that specify if the alignment checks for atomic operations are strict.
|
DISABLE_ARRAY_CONTENT_PRINTOUT_PROP_NAME, DISABLE_BOUNDS_CHECKS_PROP_NAME, SHOULD_BOUNDS_CHECK, STR_HEADER_LEN| Modifier and Type | Method and Description |
|---|---|
int |
addIntOrdered(int index,
int increment)
Add a value to a given index with ordered store semantics.
|
long |
addLongOrdered(int index,
long increment)
Add a value to a given index with ordered store semantics.
|
boolean |
compareAndSetInt(int index,
int expectedValue,
int updateValue)
Atomic compare and set of an int given an expected value.
|
boolean |
compareAndSetLong(int index,
long expectedValue,
long updateValue)
Atomic compare and set of a long given an expected value.
|
int |
getAndAddInt(int index,
int delta)
Atomically add a delta to a value at a location returning the previous contents.
|
long |
getAndAddLong(int index,
long delta)
Atomically add a delta to a value at a location returning the previous contents.
|
int |
getAndSetInt(int index,
int value)
Atomically exchange a value at a location returning the previous contents.
|
long |
getAndSetLong(int index,
long value)
Atomically exchange a value at a location returning the previous contents.
|
byte |
getByteVolatile(int index)
Get the value at a given index with volatile semantics.
|
char |
getCharVolatile(int index)
Get the value at a given index with volatile semantics.
|
int |
getIntVolatile(int index)
Get the value at a given index with volatile semantics.
|
long |
getLongVolatile(int index)
Get the value at a given index with volatile semantics.
|
short |
getShortVolatile(int index)
Get the value at a given index with volatile semantics.
|
void |
putByteVolatile(int index,
byte value)
Put a value to a given index with volatile semantics.
|
void |
putCharVolatile(int index,
char value)
Put a value to a given index with volatile semantics.
|
void |
putIntOrdered(int index,
int value)
Put a value to a given index with ordered semantics.
|
void |
putIntVolatile(int index,
int value)
Put a value to a given index with volatile semantics.
|
void |
putLongOrdered(int index,
long value)
Put a value to a given index with ordered store semantics.
|
void |
putLongVolatile(int index,
long value)
Put a value to a given index with volatile semantics.
|
void |
putShortVolatile(int index,
short value)
Put a value to a given index with volatile semantics.
|
void |
verifyAlignment()
Verify that the underlying buffer is correctly aligned to prevent word tearing, other ordering issues and
the JVM crashes.
|
isExpandable, putByte, putBytes, putBytes, putBytes, putBytes, putBytes, putChar, putChar, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putIntAscii, putLong, putLong, putLongAscii, putNaturalIntAscii, putNaturalIntAsciiFromEnd, putNaturalLongAscii, putNaturalPaddedIntAscii, putShort, putShort, putStringAscii, putStringAscii, putStringAscii, putStringAscii, putStringUtf8, putStringUtf8, putStringUtf8, putStringUtf8, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthUtf8, setMemoryaddressOffset, boundsCheck, byteArray, byteBuffer, capacity, checkLimit, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, getChar, getChar, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringUtf8, getStringUtf8, getStringUtf8, getStringWithoutLengthAscii, getStringWithoutLengthAscii, getStringWithoutLengthUtf8, parseIntAscii, parseLongAscii, parseNaturalIntAscii, parseNaturalLongAscii, wrap, wrap, wrap, wrap, wrap, wrap, wrap, wrapAdjustmentcompareTostatic final int ALIGNMENT
static final String STRICT_ALIGNMENT_CHECKS_PROP_NAME
verifyAlignment() method will throw an exception if the underlying buffer is a
byte[].static final boolean STRICT_ALIGNMENT_CHECKS
STRICT_ALIGNMENT_CHECKS_PROP_NAME system property.true.STRICT_ALIGNMENT_CHECKS_PROP_NAMEvoid verifyAlignment()
putIntOrdered(int, int),
putIntVolatile(int, int), addIntOrdered(int, int), getIntVolatile(int),
getAndAddInt(int, int) or getAndSetInt(int, int), must have the index aligned by four bytes
(e.g. 0, 4, 8, 12, 60 etc.).
Users are encouraged to call this method after constructing the AtomicBuffer instance in order to ensure
that the underlying buffer supports atomic access to long values.
Agrona provides an agent (org.agrona.agent.BufferAlignmentAgent) that checks the alignment of indexes
for all operations at runtime. The agent throws an exception if the unaligned access is detected.
Note: on some platforms unaligned atomic access can lead to the JVM crashes, e.g.:
# Java VM: OpenJDK 64-Bit Server VM (25.352-b08 mixed mode bsd-aarch64 compressed oops)
#
# siginfo: si_signo: 10 (SIGBUS), si_code: 1 (BUS_ADRALN)
IllegalStateException - if the starting offset into the buffer is not properly aligned.ALIGNMENTlong getLongVolatile(int index)
index - in bytes from which to get.void putLongVolatile(int index,
long value)
index - in bytes for where to put.value - for at a given index.void putLongOrdered(int index,
long value)
index - in bytes for where to put.value - for at a given index.long addLongOrdered(int index,
long increment)
index - in bytes for where to put.increment - by which the value at the index will be adjusted.boolean compareAndSetLong(int index,
long expectedValue,
long updateValue)
index - in bytes for where to put.expectedValue - at to be compared.updateValue - to be exchanged.long getAndSetLong(int index,
long value)
index - in bytes for where to put.value - for at a given index.long getAndAddLong(int index,
long delta)
index - in bytes for where to put.delta - to be added to the value at the index.int getIntVolatile(int index)
index - in bytes from which to get.void putIntVolatile(int index,
int value)
index - in bytes for where to put.value - for at a given index.void putIntOrdered(int index,
int value)
index - in bytes for where to put.value - for at a given index.int addIntOrdered(int index,
int increment)
index - in bytes for where to put.increment - by which the value at the index will be adjusted.boolean compareAndSetInt(int index,
int expectedValue,
int updateValue)
index - in bytes for where to put.expectedValue - at to be compared.updateValue - to be exchanged.int getAndSetInt(int index,
int value)
index - in bytes for where to put.value - for at a given index.int getAndAddInt(int index,
int delta)
index - in bytes for where to put.delta - to be added to the value at the index.short getShortVolatile(int index)
index - in bytes from which to get.void putShortVolatile(int index,
short value)
index - in bytes for where to put.value - for at a given index.char getCharVolatile(int index)
index - in bytes from which to get.void putCharVolatile(int index,
char value)
index - in bytes for where to put.value - for at a given index.byte getByteVolatile(int index)
index - in bytes from which to get.void putByteVolatile(int index,
byte value)
index - in bytes for where to put.value - for at a given index.Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.