Interface AddressLayout
- All Superinterfaces:
MemoryLayout, ValueLayout
public sealed interface AddressLayout extends ValueLayout
MemorySegment.class. The size and alignment of an address layout are platform-dependent (e.g. on a 64-bit platform, the size and alignment of an address layout are set to 8 bytes). An address layout may optionally feature a target layout. An address layout with target layout T can be used to model the address of a region of memory whose layout is T. For instance, an address layout with target layout ValueLayout.JAVA_INT can be used to model the address of a region of memory that is 4 bytes long. Specifying a target layout can be useful in the following situations:
- When accessing a memory segment that has been obtained by reading an address from another memory segment, e.g. using
MemorySegment.getAtIndex(AddressLayout, long); - When creating a downcall method handle, using
Linker.downcallHandle(FunctionDescriptor, Option...)RESTRICTED; - When creating an upcall stub, using
Linker.upcallStub(MethodHandle, FunctionDescriptor, Arena, Option...)RESTRICTED.
- Implementation Requirements:
- Implementations of this interface are immutable, thread-safe and value-based.
- Since:
- 22
- See Also:
Nested Class Summary
Nested classes/interfaces declared in interface MemoryLayout
MemoryLayout.PathElement | Modifier and Type | Interface | Description |
|---|---|---|
static interface |
MemoryLayout.PathElement |
An element in a layout path. |
Nested classes/interfaces declared in interface ValueLayout
ValueLayout.OfBoolean, ValueLayout.OfByte, ValueLayout.OfChar, ValueLayout.OfDouble, ValueLayout.OfFloat, ValueLayout.OfInt, ValueLayout.OfLong, ValueLayout.OfShort | Modifier and Type | Interface | Description |
|---|---|---|
static interface |
ValueLayout.OfBoolean |
A value layout whose carrier is boolean.class. |
static interface |
ValueLayout.OfByte |
A value layout whose carrier is byte.class. |
static interface |
ValueLayout.OfChar |
A value layout whose carrier is char.class. |
static interface |
ValueLayout.OfDouble |
A value layout whose carrier is double.class. |
static interface |
ValueLayout.OfFloat |
A value layout whose carrier is float.class. |
static interface |
ValueLayout.OfInt |
A value layout whose carrier is int.class. |
static interface |
ValueLayout.OfLong |
A value layout whose carrier is long.class. |
static interface |
ValueLayout.OfShort |
A value layout whose carrier is short.class. |
Field Summary
Fields declared in interface ValueLayout
ADDRESS, ADDRESS_UNALIGNED, JAVA_BOOLEAN, JAVA_BYTE, JAVA_CHAR, JAVA_CHAR_UNALIGNED, JAVA_DOUBLE, JAVA_DOUBLE_UNALIGNED, JAVA_FLOAT, JAVA_FLOAT_UNALIGNED, JAVA_INT, JAVA_INT_UNALIGNED, JAVA_LONG, JAVA_LONG_UNALIGNED, JAVA_SHORT, JAVA_SHORT_UNALIGNED | Modifier and Type | Field | Description |
|---|---|---|
static final AddressLayout |
ADDRESS |
An address layout constant whose size is the same as that of a machine address ( size_t), byte alignment set to sizeof(size_t), byte order set to ByteOrder.nativeOrder(). |
static final AddressLayout |
ADDRESS_UNALIGNED |
An unaligned address layout constant whose size is the same as that of a machine address ( size_t), and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfBoolean |
JAVA_BOOLEAN |
A value layout constant whose size is the same as that of a Java boolean, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfByte |
JAVA_BYTE |
A value layout constant whose size is the same as that of a Java byte, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfChar |
JAVA_CHAR |
A value layout constant whose size is the same as that of a Java char, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfChar |
JAVA_CHAR_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java char and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfDouble |
JAVA_DOUBLE |
A value layout constant whose size is the same as that of a Java double, byte alignment set to 8, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfDouble |
JAVA_DOUBLE_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java double and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfFloat |
JAVA_FLOAT |
A value layout constant whose size is the same as that of a Java float, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfFloat |
JAVA_FLOAT_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java float and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfInt |
JAVA_INT |
A value layout constant whose size is the same as that of a Java int, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfInt |
JAVA_INT_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java int and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfLong |
JAVA_LONG |
A value layout constant whose size is the same as that of a Java long, byte alignment set to 8, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfLong |
JAVA_LONG_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java long and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfShort |
JAVA_SHORT |
A value layout constant whose size is the same as that of a Java short, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder(). |
static final ValueLayout.OfShort |
JAVA_SHORT_UNALIGNED |
An unaligned value layout constant whose size is the same as that of a Java short and byte order set to ByteOrder.nativeOrder(). |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Optional |
targetLayout() |
Returns the target layout associated with this address layout (if any). |
AddressLayout |
withByteAlignment |
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes). |
AddressLayout |
withName |
Returns a memory layout with the same characteristics as this layout, but with the given name. |
AddressLayout |
withOrder |
Returns a value layout with the same characteristics as this layout, but with the given byte order. |
AddressLayout |
withoutName() |
Returns a memory layout with the same characteristics as this layout, but with no name. |
AddressLayout |
withoutTargetLayout() |
Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but with no target layout. |
AddressLayout |
withTargetLayout |
Restricted. Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but associated with the specified target layout. |
Methods declared in interface MemoryLayout
arrayElementVarHandle, byteAlignment, byteOffset, byteOffsetHandle, byteSize, equals, hashCode, name, scale, scaleHandle, select, sliceHandle, toString, varHandle | Modifier and Type | Method | Description |
|---|---|---|
VarHandle |
arrayElementVarHandle |
Creates a var handle that accesses adjacent elements in a memory segment at offsets selected by the given layout path, where the accessed elements have this layout, and where the initial layout in the path is this layout. |
long |
byteAlignment() |
Returns the alignment constraint associated with this layout, expressed in bytes. |
long |
byteOffset |
Computes the offset, in bytes, of the layout selected by the given layout path, where the initial layout in the path is this layout. |
MethodHandle |
byteOffsetHandle |
Creates a method handle that computes the offset, in bytes, of the layout selected by the given layout path, where the initial layout in the path is this layout. |
long |
byteSize() |
Returns the layout size, in bytes. |
boolean |
equals |
Compares the specified object with this layout for equality. |
int |
hashCode() |
Returns the hash code value for this layout. |
Optional |
name() |
Returns the name (if any) associated with this layout. |
long |
scale |
Returns offset + (byteSize() * index). |
MethodHandle |
scaleHandle() |
Returns a method handle that can be used to invoke MemoryLayout.scale(long, long) on this layout. |
MemoryLayout |
select |
Returns the layout selected from the provided path, where the initial layout in the path is this layout. |
MethodHandle |
sliceHandle |
Creates a method handle which, given a memory segment, returns a slice corresponding to the layout selected by the given layout path, where the initial layout in the path is this layout. |
String |
toString() |
Returns the string representation of this layout. |
VarHandle |
varHandle |
Creates a var handle that accesses a memory segment at the offset selected by the given layout path, where the initial layout in the path is this layout. |
Methods declared in interface ValueLayout
carrier, order, varHandle | Modifier and Type | Method | Description |
|---|---|---|
Class |
carrier() |
Returns the carrier associated with this value layout. |
ByteOrder |
order() |
Returns the value's byte order. |
VarHandle |
varHandle() |
Returns a var handle which can be used to access values described by this value layout, in a given memory segment. |
Method Details
withName
AddressLayout withName(String name)
- Specified by:
-
withNamein interfaceMemoryLayout - Specified by:
-
withNamein interfaceValueLayout - Parameters:
-
name- the layout name - Returns:
- a memory layout with the same characteristics as this layout, but with the given name
- See Also:
withoutName
AddressLayout withoutName()
- Specified by:
-
withoutNamein interfaceMemoryLayout - Specified by:
-
withoutNamein interfaceValueLayout - Returns:
- a memory layout with the same characteristics as this layout, but with no name
- See Also:
withByteAlignment
AddressLayout withByteAlignment(long byteAlignment)
- Specified by:
-
withByteAlignmentin interfaceMemoryLayout - Specified by:
-
withByteAlignmentin interfaceValueLayout - Parameters:
-
byteAlignment- the layout alignment constraint, expressed in bytes - Returns:
- a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes)
withOrder
AddressLayout withOrder(ByteOrder order)
- Specified by:
-
withOrderin interfaceValueLayout - Parameters:
-
order- the desired byte order - Returns:
- a value layout with the same characteristics as this layout, but with the given byte order
withTargetLayout
AddressLayout withTargetLayout(MemoryLayout layout)
withTargetLayout is a restricted method of the Java platform. - API Note:
- This method can also be used to create an address layout which, when used, creates native memory segments with maximal size (e.g. Long.MAX_VALUE). This can be done by using a target sequence layout with unspecified size, as follows:
AddressLayout addressLayout = ... AddressLayout unboundedLayout = addressLayout.withTargetLayout( MemoryLayout.sequenceLayout(Long.MAX_VALUE, ValueLayout.JAVA_BYTE)); - Parameters:
-
layout- the target layout - Returns:
- an address layout with same characteristics as this layout, but with the provided target layout
- Throws:
-
IllegalCallerException- if the caller is in a module that does not have native access enabled - See Also:
withoutTargetLayout
AddressLayout withoutTargetLayout()
- API Note:
- This can be useful to compare two address layouts that have different target layouts, but are otherwise equal.
- Returns:
- an address layout with same characteristics as this layout, but with no target layout
- See Also:
targetLayout
Optional<MemoryLayout> targetLayout()
- Returns:
- the target layout associated with this address layout (if any)
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
withTargetLayoutwhen access to restricted methods is enabled.