MemoryLayoutPREVIEWAddressLayoutPREVIEW, ValueLayout.OfBooleanPREVIEW, ValueLayout.OfBytePREVIEW, ValueLayout.OfCharPREVIEW, ValueLayout.OfDoublePREVIEW, ValueLayout.OfFloatPREVIEW, ValueLayout.OfIntPREVIEW, ValueLayout.OfLongPREVIEW, ValueLayout.OfShortPREVIEW
public sealed interface ValueLayout extends MemoryLayoutPREVIEW permits ValueLayout.OfBooleanPREVIEW, ValueLayout.OfBytePREVIEW, ValueLayout.OfCharPREVIEW, ValueLayout.OfShortPREVIEW, ValueLayout.OfIntPREVIEW, ValueLayout.OfFloatPREVIEW, ValueLayout.OfLongPREVIEW, ValueLayout.OfDoublePREVIEW, AddressLayoutPREVIEW
ValueLayout is a preview API of the Java platform. 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 accessingPREVIEW a region of memory using the value layout.
This class defines useful value layout constants for Java primitive types and addresses.
ByteBuffer. Moreover, the alignment constraint of JAVA_LONG and JAVA_DOUBLE is set to 8 bytes on 64-bit platforms, but only to 4 bytes on 32-bit platforms.| Modifier and Type | Interface | Description | 
|---|---|---|
| static interface  | ValueLayout.OfBooleanPREVIEW | Preview. A value layout whose carrier is  boolean.class. | 
| static interface  | ValueLayout.OfBytePREVIEW | Preview. A value layout whose carrier is  byte.class. | 
| static interface  | ValueLayout.OfCharPREVIEW | Preview. A value layout whose carrier is  char.class. | 
| static interface  | ValueLayout.OfDoublePREVIEW | Preview. A value layout whose carrier is  double.class. | 
| static interface  | ValueLayout.OfFloatPREVIEW | Preview. A value layout whose carrier is  float.class. | 
| static interface  | ValueLayout.OfIntPREVIEW | Preview. A value layout whose carrier is  int.class. | 
| static interface  | ValueLayout.OfLongPREVIEW | Preview. A value layout whose carrier is  long.class. | 
| static interface  | ValueLayout.OfShortPREVIEW | Preview. A value layout whose carrier is  short.class. | 
MemoryLayout.PathElementPREVIEW
| Modifier and Type | Field | Description | 
|---|---|---|
| static final AddressLayoutPREVIEW | ADDRESS | An address layout constant whose size is the same as that of a machine address ( size_t), byte alignment set tosizeof(size_t), byte order set toByteOrder.nativeOrder(). | 
| static final AddressLayoutPREVIEW | ADDRESS_UNALIGNED | An unaligned address layout constant whose size is the same as that of a machine address ( size_t), and byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfBooleanPREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfBytePREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfCharPREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfCharPREVIEW | JAVA_CHAR_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  charand byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfDoublePREVIEW | JAVA_DOUBLE | A value layout constant whose size is the same as that of a Java  double, (platform-dependent) byte alignment set toADDRESS.byteSize(), and byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfDoublePREVIEW | JAVA_DOUBLE_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  doubleand byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfFloatPREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfFloatPREVIEW | JAVA_FLOAT_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  floatand byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfIntPREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfIntPREVIEW | JAVA_INT_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  intand byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfLongPREVIEW | JAVA_LONG | A value layout constant whose size is the same as that of a Java  long, (platform-dependent) byte alignment set toADDRESS.byteSize(), and byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfLongPREVIEW | JAVA_LONG_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  longand byte order set toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfShortPREVIEW | 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 toByteOrder.nativeOrder(). | 
| static final ValueLayout.OfShortPREVIEW | JAVA_SHORT_UNALIGNED | An unaligned value layout constant whose size is the same as that of a Java  shortand byte order set toByteOrder.nativeOrder(). | 
| Modifier and Type | Method | Description | 
|---|---|---|
| VarHandle | arrayElementVarHandle | Creates a strided var handle that can be used to access a memory segment as multi-dimensional array. | 
| Class | carrier() | Returns the carrier associated with this value layout. | 
| ByteOrder | order() | Returns the value's byte order. | 
| ValueLayoutPREVIEW | withByteAlignment | Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes). | 
| ValueLayoutPREVIEW | withName | Returns a memory layout with the same characteristics as this layout, but with the given name. | 
| ValueLayoutPREVIEW | withOrder | Returns a value layout with the same characteristics as this layout, but with the given byte order. | 
| ValueLayoutPREVIEW | withoutName() | Returns a memory layout with the same characteristics as this layout, but with no name. | 
byteAlignment, byteOffset, byteOffsetHandle, byteSize, equals, hashCode, name, select, sliceHandle, toString, varHandle
static final AddressLayoutPREVIEW ADDRESS
size_t), byte alignment set to sizeof(size_t), byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfBytePREVIEW JAVA_BYTE
byte, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfBooleanPREVIEW JAVA_BOOLEAN
boolean, byte alignment set to 1, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfCharPREVIEW JAVA_CHAR
char, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfShortPREVIEW JAVA_SHORT
short, byte alignment set to 2, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfIntPREVIEW JAVA_INT
int, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfLongPREVIEW JAVA_LONG
long, (platform-dependent) byte alignment set to ADDRESS.byteSize(), and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfFloatPREVIEW JAVA_FLOAT
float, byte alignment set to 4, and byte order set to ByteOrder.nativeOrder().static final ValueLayout.OfDoublePREVIEW JAVA_DOUBLE
double, (platform-dependent) byte alignment set to ADDRESS.byteSize(), and byte order set to ByteOrder.nativeOrder().static final AddressLayoutPREVIEW ADDRESS_UNALIGNED
size_t), and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: ADDRESS.withByteAlignment(1);
static final ValueLayout.OfCharPREVIEW JAVA_CHAR_UNALIGNED
char and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_CHAR.withByteAlignment(1);
static final ValueLayout.OfShortPREVIEW JAVA_SHORT_UNALIGNED
short and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_SHORT.withByteAlignment(1);
static final ValueLayout.OfIntPREVIEW JAVA_INT_UNALIGNED
int and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_INT.withByteAlignment(1);
static final ValueLayout.OfLongPREVIEW JAVA_LONG_UNALIGNED
long and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_LONG.withByteAlignment(1);
static final ValueLayout.OfFloatPREVIEW JAVA_FLOAT_UNALIGNED
float and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_FLOAT.withByteAlignment(1);
static final ValueLayout.OfDoublePREVIEW JAVA_DOUBLE_UNALIGNED
double and byte order set to ByteOrder.nativeOrder(). Equivalent to the following code: JAVA_DOUBLE.withByteAlignment(1);
ByteOrder order()
ValueLayoutPREVIEW withOrder(ByteOrder order)
order - the desired byte order.ValueLayoutPREVIEW withoutName()
withoutName in interface MemoryLayoutPREVIEW
VarHandle arrayElementVarHandle(int... shape)
shape.length nested sequence layouts. The element layout of the innermost sequence layout in the notional sequence layout is this value layout. The resulting var handle is obtained as if calling the MemoryLayout.varHandle(PathElement...)PREVIEW method on the notional layout, with a layout path containing exactly shape.length + 1 open sequence layout path elementsPREVIEW. For instance, the following method call:
VarHandle arrayHandle = ValueLayout.JAVA_INT.arrayElementVarHandle(10, 20);
 SequenceLayout notionalLayout = MemoryLayout.sequenceLayout(
                                         MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(20, ValueLayout.JAVA_INT)));
 VarHandle arrayHandle = notionalLayout.varHandle(PathElement.sequenceElement(),
                                                  PathElement.sequenceElement(),
                                                  PathElement.sequenceElement());
arrayHandle will feature 3 coordinates of type long; each coordinate is interpreted as an index into the corresponding sequence layout. If we refer to the var handle coordinates, from left to right, as x, y and z respectively, the final offset accessed by the var handle can be computed with the following formula: Additionally, the values ofoffset = (10 * 20 * 4 * x) + (20 * 4 * y) + (4 * z)
x, y and z are constrained as follows: 0 <= x < notionalLayout.elementCount() 0 <= y < 10 0 <= z < 20 Consider the following access expressions:
int value1 = (int) arrayHandle.get(10, 2, 4); // ok, accessed offset = 8176
int value2 = (int) arrayHandle.get(0, 0, 30); // out of bounds value for z
x, y and z conform to the bounds specified above. In the second case, access fails with IndexOutOfBoundsException, as the value for z is outside its specified bounds.shape - the size of each nested array dimension.shape.length + 1 long coordinates.IllegalArgumentException - if shape[i] < 0, for at least one index i.UnsupportedOperationException - if byteAlignment() > byteSize().Class<?> carrier()
ValueLayoutPREVIEW withName(String name)
withName in interface MemoryLayoutPREVIEW
name - the layout name.ValueLayoutPREVIEW withByteAlignment(long byteAlignment)
withByteAlignment in interface MemoryLayoutPREVIEW
byteAlignment - the layout alignment constraint, expressed in bytes.IllegalArgumentException - if byteAlignment is not a power of two.
    © 1993, 2023, 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/21/docs/api/java.base/java/lang/foreign/ValueLayout.html
  
ValueLayoutwhen preview features are enabled.