MemoryLayoutAddressLayout, ValueLayout.OfBoolean, ValueLayout.OfByte, ValueLayout.OfChar, ValueLayout.OfDouble, ValueLayout.OfFloat, ValueLayout.OfInt, ValueLayout.OfLong, ValueLayout.OfShortpublic sealed interface ValueLayout extends MemoryLayout permits ValueLayout.OfBoolean, ValueLayout.OfByte, ValueLayout.OfChar, ValueLayout.OfShort, ValueLayout.OfInt, ValueLayout.OfFloat, ValueLayout.OfLong, ValueLayout.OfDouble, AddressLayout
Each value layout has a size, an alignment (both expressed in bytes), a byte order, and a carrier, that is, the Java type that should be used when accessing a region of memory using the value layout.
This class defines useful value layout constants for Java primitive types and addresses.
ByteBuffer.| 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. |
MemoryLayout.PathElement
| 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(). |
| 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. |
ValueLayout |
withByteAlignment |
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes). |
ValueLayout |
withName |
Returns a memory layout with the same characteristics as this layout, but with the given name. |
ValueLayout |
withOrder |
Returns a value layout with the same characteristics as this layout, but with the given byte order. |
ValueLayout |
withoutName() |
Returns a memory layout with the same characteristics as this layout, but with no name. |
arrayElementVarHandle, byteAlignment, byteOffset, byteOffsetHandle, byteSize, equals, hashCode, name, scale, scaleHandle, select, sliceHandle, toString, varHandle
static final AddressLayout ADDRESS
size_t), byte alignment set to sizeof(size_t), byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfByte JAVA_BYTE
byte, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfBoolean JAVA_BOOLEAN
boolean, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfChar JAVA_CHAR
char, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfShort JAVA_SHORT
short, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfInt JAVA_INT
int, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfLong JAVA_LONG
long, byte alignment set to 8, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfFloat JAVA_FLOAT
float, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfDouble JAVA_DOUBLE
double, byte alignment set to 8, and byte order set to ByteOrder.nativeOrder().static final AddressLayout ADDRESS_UNALIGNED
size_t), and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: ADDRESS.withByteAlignment(1);
static final ValueLayout.OfChar JAVA_CHAR_UNALIGNED
char and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_CHAR.withByteAlignment(1);
static final ValueLayout.OfShort JAVA_SHORT_UNALIGNED
short and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_SHORT.withByteAlignment(1);
static final ValueLayout.OfInt JAVA_INT_UNALIGNED
int and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_INT.withByteAlignment(1);
static final ValueLayout.OfLong JAVA_LONG_UNALIGNED
long and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_LONG.withByteAlignment(1);
static final ValueLayout.OfFloat JAVA_FLOAT_UNALIGNED
float and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_FLOAT.withByteAlignment(1);
static final ValueLayout.OfDouble JAVA_DOUBLE_UNALIGNED
double and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_DOUBLE.withByteAlignment(1);
ByteOrder order()
ValueLayout withOrder(ByteOrder order)
order - the desired byte orderValueLayout withoutName()
withoutName in interface MemoryLayout
Class<?> carrier()
ValueLayout withName(String name)
withName in interface MemoryLayout
name - the layout nameValueLayout withByteAlignment(long byteAlignment)
withByteAlignment in interface MemoryLayout
byteAlignment - the layout alignment constraint, expressed in bytesIllegalArgumentException - if byteAlignment is not a power of twoVarHandle varHandle()
The returned var handle's var type is the carrier type of this value layout, and the list of coordinate types is (MemorySegment, long), where the memory segment coordinate corresponds to the memory segment to be accessed, and the long coordinate corresponds to the byte offset into the accessed memory segment at which the access occurs.
The returned var handle checks that accesses are aligned according to this value layout's alignment constraint.
MemoryLayout#varHandle(PathElement...) with an empty path element array, as it avoids the creation of the var args array., The returned var handle features certain access mode restrictions common to all memory access var handles derived from memory layouts.
© 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.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/foreign/ValueLayout.html