APIdia Launch Partner
Top Description Inners Fields Methods
java.lang.foreign

public sealed Interface ValueLayout

extends MemoryLayout
permits OfBoolean, OfByte, OfChar, OfShort, OfInt, OfFloat, OfLong, OfDouble, AddressLayout
Known Direct Subinterfaces
java.lang.foreign.ValueLayout.OfBoolean, java.lang.foreign.ValueLayout.OfByte, java.lang.foreign.ValueLayout.OfChar, java.lang.foreign.ValueLayout.OfShort, java.lang.foreign.ValueLayout.OfInt, java.lang.foreign.ValueLayout.OfFloat, java.lang.foreign.ValueLayout.OfLong, java.lang.foreign.ValueLayout.OfDouble, java.lang.foreign.AddressLayout
Imports
jdk.internal.foreign.layout.ValueLayouts, java.lang.invoke.VarHandle, java.nio.ByteOrder

A layout that models values of basic data types. Examples of values modeled by a value layout are integral values (either signed or unsigned), floating-point values and address values.

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.

API Note

Some characteristics of the Java layout constants are platform-dependent. For instance, the byte order of these constants is set to the native byte order, thus making it easy to work with other APIs, such as arrays and java.nio.ByteBuffer.

Implementation Specification

implementing classes and subclasses are immutable, thread-safe and value-based.

Since
22

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ValueLayout.OfBoolean

A value layout whose carrier is boolean.class.

public static interface
ValueLayout.OfByte

A value layout whose carrier is byte.class.

public static interface
ValueLayout.OfChar

A value layout whose carrier is char.class.

public static interface
ValueLayout.OfDouble

A value layout whose carrier is double.class.

public static interface
ValueLayout.OfFloat

A value layout whose carrier is float.class.

public static interface
ValueLayout.OfInt

A value layout whose carrier is int.class.

public static interface
ValueLayout.OfLong

A value layout whose carrier is long.class.

public static interface
ValueLayout.OfShort

A value layout whose carrier is short.class.

Field Summary

Modifier and TypeField and Description
public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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().

public 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 TypeMethod and Description
public Class<?>

Returns:

the carrier associated with this value layout
carrier
()

Returns the carrier associated with this value layout.

public ByteOrder

Returns:

the value's byte order
order
()

Returns the value's byte order.

public VarHandle

Returns:

a var handle which can be used to access values described by this value layout, in a given memory segment
varHandle
()

Returns a var handle which can be used to access values described by this value layout, in a given memory segment.

public ValueLayout
withByteAlignment(long byteAlignment)

Redeclares java.lang.foreign.MemoryLayout.withByteAlignment.

Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes).

public ValueLayout
withName(String name)

Redeclares java.lang.foreign.MemoryLayout.withName.

Returns a memory layout with the same characteristics as this layout, but with the given name.

public ValueLayout

Returns:

a value layout with the same characteristics as this layout, but with the given byte order
withOrder
(ByteOrder
the desired byte order
order
)

Returns a value layout with the same characteristics as this layout, but with the given byte order.

public ValueLayout
withoutName()

Redeclares java.lang.foreign.MemoryLayout.withoutName.

Returns a memory layout with the same characteristics as this layout, but with no name.

Inherited from java.lang.foreign.MemoryLayout:
arrayElementVarHandlebyteAlignmentbyteOffsetbyteOffsetHandlebyteSizeequalshashCodenamepaddingLayoutscalescaleHandleselectsequenceLayoutsliceHandlestructLayouttoStringunionLayoutvarHandle