Interface ValueLayout
- All Superinterfaces:
MemoryLayout
- All Known Subinterfaces:
AddressLayout,ValueLayout.OfBoolean,ValueLayout.OfByte,ValueLayout.OfChar,ValueLayout.OfDouble,ValueLayout.OfFloat,ValueLayout.OfInt,ValueLayout.OfLong,ValueLayout.OfShort
public sealed interfaceValueLayoutextendsMemoryLayoutpermitsValueLayout.OfBoolean,ValueLayout.OfByte,ValueLayout.OfChar,ValueLayout.OfShort,ValueLayout.OfInt,ValueLayout.OfFloat,ValueLayout.OfLong,ValueLayout.OfDouble,AddressLayout
A layout that models values of basic data types. Examples of values modeled bya value layout areintegral values (either signed or unsigned),floating-point values andaddress values.
Each value layout has a size, an alignment (both expressed in bytes),abyte order, and acarrier, that is, the Java typethat should be used whenaccessing aregion of memory using the value layout.
This class defines useful value layout constants for Java primitive types andaddresses.
- API Note:
- Some characteristics of the Java layout constants are platform-dependent. For instance, the byte order of these constants is set to thenative byte order, thus making it easy to work with other APIs, such as arrays and
ByteBuffer. - Implementation Requirements:
- implementing classes and subclasses are immutable, thread-safe andvalue-based.
- Sealed Class Hierarchy Graph:
- Since:
- 22
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA value layout whose carrier isboolean.class.static interfaceA value layout whose carrier isbyte.class.static interfaceA value layout whose carrier ischar.class.static interfaceA value layout whose carrier isdouble.class.static interfaceA value layout whose carrier isfloat.class.static interfaceA value layout whose carrier isint.class.static interfaceA value layout whose carrier islong.class.static interfaceA value layout whose carrier isshort.class.Nested classes/interfaces declared in interface MemoryLayout
MemoryLayout.PathElementField Summary
FieldsModifier and TypeFieldDescriptionstatic finalAddressLayoutAn address layout constant whose size is the same as that of amachine address (size_t), byte alignment set tosizeof(size_t),byte order set toByteOrder.nativeOrder().static finalAddressLayoutAn unaligned address layout constant whose size is the same as that of amachine address (size_t), and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfBooleanA value layout constant whose size is the same as that of a Javaboolean,byte alignment set to 1, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfByteA value layout constant whose size is the same as that of a Javabyte,byte alignment set to 1, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfCharA value layout constant whose size is the same as that of a Javachar,byte alignment set to 2, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfCharAn unaligned value layout constant whose size is the same as that of a Javacharand byte order set toByteOrder.nativeOrder().static finalValueLayout.OfDoubleA value layout constant whose size is the same as that of a Javadouble,byte alignment set to 8, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfDoubleAn unaligned value layout constant whose size is the same as that of a Javadoubleand byte order set toByteOrder.nativeOrder().static finalValueLayout.OfFloatA value layout constant whose size is the same as that of a Javafloat,byte alignment set to 4, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfFloatAn unaligned value layout constant whose size is the same as that of a Javafloatand byte order set toByteOrder.nativeOrder().static finalValueLayout.OfIntA value layout constant whose size is the same as that of a Javaint,byte alignment set to 4, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfIntAn unaligned value layout constant whose size is the same as that of a Javaintand byte order set toByteOrder.nativeOrder().static finalValueLayout.OfLongA value layout constant whose size is the same as that of a Javalong,byte alignment set to 8, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfLongAn unaligned value layout constant whose size is the same as that of a Javalongand byte order set toByteOrder.nativeOrder().static finalValueLayout.OfShortA value layout constant whose size is the same as that of a Javashort,byte alignment set to 2, and byte order set toByteOrder.nativeOrder().static finalValueLayout.OfShortAn unaligned value layout constant whose size is the same as that of a Javashortand byte order set toByteOrder.nativeOrder().Method Summary
Modifier and TypeMethodDescriptionClass<?> carrier()Returns the carrier associated with this value layout.order()Returns the value's byte order.Returns a var handle which can be used to access values described by this value layout, in a given memory segment.withByteAlignment(long byteAlignment) Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes).Returns a memory layout with the same characteristics as this layout, but with the given name.Returns a value layout with the same characteristics as this layout, but with the given byte order.Returns a memory layout with the same characteristics as this layout, but with no name.Methods declared in interface MemoryLayout
arrayElementVarHandle,byteAlignment,byteOffset,byteOffsetHandle,byteSize,equals,hashCode,name,scale,scaleHandle,select,sliceHandle,toString,varHandle
Field Details
ADDRESS
An address layout constant whose size is the same as that of amachine address (size_t), byte alignment set tosizeof(size_t),byte order set toByteOrder.nativeOrder().JAVA_BYTE
A value layout constant whose size is the same as that of a Javabyte,byte alignment set to 1, and byte order set toByteOrder.nativeOrder().JAVA_BOOLEAN
A value layout constant whose size is the same as that of a Javaboolean,byte alignment set to 1, and byte order set toByteOrder.nativeOrder().JAVA_CHAR
A value layout constant whose size is the same as that of a Javachar,byte alignment set to 2, and byte order set toByteOrder.nativeOrder().JAVA_SHORT
A value layout constant whose size is the same as that of a Javashort,byte alignment set to 2, and byte order set toByteOrder.nativeOrder().JAVA_INT
A value layout constant whose size is the same as that of a Javaint,byte alignment set to 4, and byte order set toByteOrder.nativeOrder().JAVA_LONG
A value layout constant whose size is the same as that of a Javalong,byte alignment set to 8, and byte order set toByteOrder.nativeOrder().JAVA_FLOAT
A value layout constant whose size is the same as that of a Javafloat,byte alignment set to 4, and byte order set toByteOrder.nativeOrder().JAVA_DOUBLE
A value layout constant whose size is the same as that of a Javadouble,byte alignment set to 8, and byte order set toByteOrder.nativeOrder().ADDRESS_UNALIGNED
An unaligned address layout constant whose size is the same as that of amachine address (size_t), and byte order set toByteOrder.nativeOrder().Equivalent to the following code:ADDRESS.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_CHAR_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javacharand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_CHAR.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_SHORT_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javashortand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_SHORT.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_INT_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javaintand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_INT.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_LONG_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javalongand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_LONG.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_FLOAT_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javafloatand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_FLOAT.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
JAVA_DOUBLE_UNALIGNED
An unaligned value layout constant whose size is the same as that of a Javadoubleand byte order set toByteOrder.nativeOrder().Equivalent to the following code:JAVA_DOUBLE.withByteAlignment(1);- API Note:
- Care should be taken when using unaligned value layouts as they may induce performance and portability issues.
Method Details
order
withOrder
Returns a value layout with the same characteristics as this layout, but with the given byte order.- Parameters:
order- the desired byte order- Returns:
- a value layout with the same characteristics as this layout, but with the given byte order
withoutName
ValueLayout withoutName()Returns a memory layout with the same characteristics as this layout, but with no name.- Specified by:
withoutNamein interfaceMemoryLayout- Returns:
- a memory layout with the same characteristics as this layout, but with no name
- See Also:
carrier
Class<?> carrier()Returns the carrier associated with this value layout.- Returns:
- the carrier associated with this value layout
withName
Returns a memory layout with the same characteristics as this layout, but with the given name.- Specified by:
withNamein interfaceMemoryLayout- Parameters:
name- the layout name- Returns:
- a memory layout with the same characteristics as this layout, but with the given name
- See Also:
withByteAlignment
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes).- Specified by:
withByteAlignmentin interfaceMemoryLayout- 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)
- Throws:
IllegalArgumentException- ifbyteAlignmentis not a power of two
varHandle
VarHandle varHandle()Returns a var handle which can be used to access values described by this value layout, in a given memory segment.The returned var handle'svar type is thecarrier type of this value layout, and thelist of coordinate types is
(MemorySegment, long), where thememory segment coordinate corresponds to the memory segment to be accessed, andthelongcoordinate corresponds to the byte offset into the accessedmemory segment at which the access occurs.The returned var handle checks that accesses are aligned according tothis value layout'salignment constraint.
- API Note:
- This method is similar, but more efficient than calling
MemoryLayout#varHandle(PathElement...)with an empty path element array, as it avoids the creation of the var args array., The returned var handle features certainaccess mode restrictions common to all memory access var handles derived from memory layouts. - Returns:
- a var handle which can be used to access values described by this value layout, in a given memory segment
- See Also: