public interface MemoryAddress
MemorySegment. Memory addresses are typically obtained using the
MemorySegment.baseAddress()method; such addresses can then be adjusted as required, using
A memory address is typically used as the first argument in a memory access var handle call, to perform some operation on the underlying memory backing a given memory segment. Since a memory address is always associated with a memory segment, such access operations are always subject to spatial and temporal checks as enforced by the address' owning memory region.
All implementations of this interface must be value-based;
use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on
MemoryAddress may have unpredictable results and should be avoided. The
equals method should
be used for comparisons.
Non-platform classes should not implement MemoryAddress directly.
- API Note:
- In the future, if the Java language permits,
MemoryAddressmay become a
sealedinterface, which would prohibit subclassing except by explicitly permitted types.
- Implementation Requirements:
- Implementations of this interface are immutable and thread-safe.
Modifier and Type Method Description
addOffset(long offset)Creates a new memory address with given offset (in bytes), which might be negative, from current one.
copy(MemoryAddress src, MemoryAddress dst, long bytes)Perform bulk copy from source address to target address.
equals(Object that)Compares the specified object with this address for equality.
hashCode()Returns the hash code value for this address.
offset()The offset of this memory address into the underlying segment.
segment()The memory segment this address belongs to.
MemoryAddress addOffset(long offset)Creates a new memory address with given offset (in bytes), which might be negative, from current one.
offset- specified offset (in bytes), relative to this address, which should be used to create the new address.
- a new memory address with given offset from current one.
long offset()The offset of this memory address into the underlying segment.
- the offset
MemorySegment segment()The memory segment this address belongs to.
- The memory segment this address belongs to.
boolean equals(Object that)Compares the specified object with this address for equality. Returns
trueif and only if the specified object is also an address, and it refers to the same memory location as this address.
- API Note:
- two addresses might be considered equal despite their associated segments differ. This
can happen, for instance, if the segment associated with one address is a slice
MemorySegment.asSlice(long, long)) of the segment associated with the other address. Moreover, two addresses might be considered equals despite differences in the temporal bounds associated with their corresponding segments (this is possible, for example, as a result of calls to
that- the object to be compared for equality with this address.
trueif the specified object is equal to this address.
- See Also:
int hashCode()Returns the hash code value for this address.
Perform bulk copy from source address to target address. More specifically, the bytes at addresses
src.addOffset(bytes - 1)are copied into addresses
dst.addOffset(bytes - 1). If the source and address ranges overlap, then the copying is performed as if the bytes at addresses
src.addOffset(bytes - 1)were first copied into a temporary segment with size
bytes, and then the contents of the temporary segment were copied into the bytes at addresses
dst.addOffset(bytes - 1).
src- the source address.
dst- the target address.
bytes- the number of bytes to be copied.
bytes < 0, or if it is greater than the size of the segments associated with either
IllegalStateException- if either the source address or the target address belong to memory segments which have been already closed, or if access occurs from a thread other than the thread owning either segment.
dstis associated with a read-only segment (see