java.lang.Object
jdk.incubator.foreign.ValueLayout
- All Implemented Interfaces:
Constable,MemoryLayout
public final class ValueLayout extends Object implements MemoryLayout
A value layout. A value layout is used to model the memory layout associated with values of basic data types, such as integral types
(either signed or unsigned) and floating-point types. Each value layout has a size and a byte order (see
ByteOrder).
This is a value-based
class; use of identity-sensitive operations (including reference equality
(==), identity hash code, or synchronization) on instances of
ValueLayout may have unpredictable results and should be avoided.
The equals method should be used for comparisons.
- Implementation Requirements:
- This class is immutable and thread-safe.
-
Nested Class Summary
Nested classes/interfaces declared in interface jdk.incubator.foreign.MemoryLayout
MemoryLayout.PathElement -
Method Summary
Modifier and Type Method Description longbitAlignment()Returns the alignment constraint associated with this layout, expressed in bits.longbitSize()Computes the layout size, in bits.Optional<DynamicConstantDesc<ValueLayout>>describeConstable()booleanhasSize()Does this layout have a specified size?Optional<String>name()Return the name (if any) associated with this layout.ByteOrderorder()Returns the value's byte order.ValueLayoutwithBitAlignment(long alignmentBits)Creates a new layout which features the desired alignment constraint.ValueLayoutwithName(String name)Creates a new layout which features the desired layout name.ValueLayoutwithOrder(ByteOrder order)Returns a new value layout with given byte order.Methods declared in class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods declared in interface jdk.incubator.foreign.MemoryLayout
bitAlignment, bitSize, byteAlignment, byteSize, equals, hashCode, hasSize, map, name, offset, select, toString, varHandle
-
Method Details
-
order
Returns the value's byte order.- Returns:
- the value's byte order.
-
withOrder
Returns a new value layout with given byte order.- Parameters:
order- the desired byte order.- Returns:
- a new value layout with given byte order.
-
describeConstable
Description copied from interface:MemoryLayoutReturns anOptionalcontaining the nominal descriptor for this layout, if one can be constructed, or an emptyOptionalif one cannot be constructed.- Specified by:
describeConstablein interfaceConstable- Specified by:
describeConstablein interfaceMemoryLayout- Returns:
- An
Optionalcontaining the resulting nominal descriptor, or an emptyOptionalif one cannot be constructed.
-
withName
Creates a new layout which features the desired layout name.- Specified by:
withNamein interfaceMemoryLayout- Parameters:
name- the layout name.- Returns:
- a new layout which is the same as this layout, except for the name associated to it.
- See Also:
MemoryLayout.name()
-
withBitAlignment
Creates a new layout which features the desired alignment constraint.- Specified by:
withBitAlignmentin interfaceMemoryLayout- Parameters:
alignmentBits- the layout alignment constraint, expressed in bits.- Returns:
- a new layout which is the same as this layout, except for the alignment constraint associated to it.
-
name
Description copied from interface:MemoryLayoutReturn the name (if any) associated with this layout.- Specified by:
namein interfaceMemoryLayout- Returns:
- the layout name (if any).
- See Also:
MemoryLayout.withName(String)
-
bitAlignment
public final long bitAlignment()Description copied from interface:MemoryLayoutReturns the alignment constraint associated with this layout, expressed in bits. Layout alignment defines a power of twoAwhich is the bit-wise alignment of the layout. IfA <= 8thenA/8is the number of bytes that must be aligned for any pointer that correctly points to this layout. Thus:A=8means unaligned (in the usual sense), which is common in packets.A=64means word aligned (on LP64),A=32int aligned,A=16short aligned, etc.A=512is the most strict alignment required by the x86/SV ABI (for AVX-512 data).
MemoryLayout.withBitAlignment(long)), then this method returns the natural alignment constraint (in bits) associated with this layout.- Specified by:
bitAlignmentin interfaceMemoryLayout- Returns:
- the layout alignment constraint, in bits.
-
hasSize
public boolean hasSize()Description copied from interface:MemoryLayoutDoes this layout have a specified size? A layout does not have a specified size if it is (or contains) a sequence layout whose size is unspecified (seeSequenceLayout.elementCount()). Value layouts (seeValueLayout) and padding layouts (seeMemoryLayout.ofPaddingBits(long)) always have a specified size, therefore this method always returnstruein these cases.- Specified by:
hasSizein interfaceMemoryLayout- Returns:
true, if this layout has a specified size.
-
bitSize
public long bitSize()Description copied from interface:MemoryLayoutComputes the layout size, in bits.- Specified by:
bitSizein interfaceMemoryLayout- Returns:
- the layout size, in bits.
-