java.lang.Object
jdk.incubator.foreign.GroupLayout
- All Implemented Interfaces:
Constable,MemoryLayout
A group layout is used to combine together multiple member layouts. There are two ways in which member layouts
can be combined: if member layouts are laid out one after the other, the resulting group layout is said to be a struct
(see
MemoryLayout.structLayout(MemoryLayout...)); conversely, if all member layouts are laid out at the same starting offset,
the resulting group layout is said to be a union (see MemoryLayout.unionLayout(MemoryLayout...)).
This is a value-based
class; programmers should treat instances that are
equal as interchangeable and should not
use instances for synchronization, or unpredictable behavior may
occur. For example, in a future release, synchronization may fail.
The equals method should be used for comparisons.
Unless otherwise specified, passing a null argument, or an array argument containing one or more null
elements to a method in this class causes a NullPointerException to be thrown.
- Implementation Requirements:
- This class is immutable and thread-safe.
-
Nested Class Summary
Nested classes/interfaces declared in interface jdk.incubator.foreign.MemoryLayout
MemoryLayout.PathElement -
Field Summary
Fields declared in interface jdk.incubator.foreign.MemoryLayout
LAYOUT_NAME -
Method Summary
Modifier and TypeMethodDescriptionReturns the attribute with the given name (if it exists).Returns a stream of the attribute names associated with this layout.final longReturns the alignment constraint associated with this layout, expressed in bits.longbitSize()Computes the layout size, in bits.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.inthashCode()Answers an integer hash code for the receiver.booleanhasSize()Does this layout have a specified size?booleanIs this a padding layout (e.g. a layout created fromMemoryLayout.paddingLayout(long)) ?booleanisStruct()Is this group layout a struct?booleanisUnion()Is this group layout a union?Returns the member layouts associated with this group.name()Return the name (if any) associated with this layout.toString()Answers a string containing a concise, human-readable description of the receiver.withAttribute(String name, Constable value) Returns a new memory layout which features the same attributes as this layout, plus the newly specified attribute.withBitAlignment(long alignmentBits) Creates a new layout which features the desired alignment constraint.Creates a new layout which features the desired layout name.Methods declared in class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods declared in interface jdk.incubator.foreign.MemoryLayout
attribute, attributes, bitAlignment, bitOffset, bitOffsetHandle, bitSize, byteAlignment, byteOffset, byteOffsetHandle, byteSize, hasSize, isPadding, map, name, select, sliceHandle, varHandle
-
Method Details
-
memberLayouts
Returns the member layouts associated with this group.- API Note:
- the order in which member layouts are returned is the same order in which member layouts have
been passed to one of the group layout factory methods (see
MemoryLayout.structLayout(MemoryLayout...),MemoryLayout.unionLayout(MemoryLayout...)). - Returns:
- the member layouts associated with this group.
-
toString
Description copied from class:ObjectAnswers a string containing a concise, human-readable description of the receiver.- Specified by:
toStringin interfaceMemoryLayout- Overrides:
toStringin classObject- Returns:
- String a printable representation for the receiver.
-
isStruct
public boolean isStruct()Is this group layout a struct?- Returns:
- true, if this group layout is a struct.
-
isUnion
public boolean isUnion()Is this group layout a union?- Returns:
- true, if this group layout is a union.
-
equals
Description copied from class:ObjectCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. The implementation in Object answers true only if the argument is the exact same object as the receiver (==).- Specified by:
equalsin interfaceMemoryLayout- Parameters:
other- Object the object to compare with this object.- Returns:
- boolean
trueif the object is the same as this objectfalseif it is different from this object. - See Also:
-
hashCode
public int hashCode()Description copied from class:ObjectAnswers an integer hash code for the receiver. Any two objects which answertruewhen passed to.equalsmust answer the same value for this method.- Specified by:
hashCodein interfaceMemoryLayout- Returns:
- the receiver's hash.
- See Also:
-
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.This is equivalent to the following code:
withAttribute(LAYOUT_NAME, 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 with it.
- See Also:
-
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 with it.
-
withAttribute
Returns a new memory layout which features the same attributes as this layout, plus the newly specified attribute. If this layout already contains an attribute with the same name, the existing attribute value is overwritten in the returned layout.- Specified by:
withAttributein interfaceMemoryLayout- Parameters:
name- the attribute name.value- the attribute value.- Returns:
- a new memory layout which features the same attributes as this layout, plus the newly specified attribute.
-
name
Description copied from interface:MemoryLayoutReturn the name (if any) associated with this layout.This is equivalent to the following code:
attribute(LAYOUT_NAME).map(String.class::cast);- Specified by:
namein interfaceMemoryLayout- Returns:
- the layout name (if any).
- See Also:
-
attribute
Description copied from interface:MemoryLayoutReturns the attribute with the given name (if it exists).- Specified by:
attributein interfaceMemoryLayout- Parameters:
name- the attribute name- Returns:
- the attribute with the given name (if it exists).
-
attributes
Description copied from interface:MemoryLayoutReturns a stream of the attribute names associated with this layout.- Specified by:
attributesin interfaceMemoryLayout- Returns:
- a stream of the attribute names associated with this layout.
-
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.paddingLayout(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.
-
isPadding
public boolean isPadding()Description copied from interface:MemoryLayoutIs this a padding layout (e.g. a layout created fromMemoryLayout.paddingLayout(long)) ?- Specified by:
isPaddingin interfaceMemoryLayout- Returns:
- true, if this layout is a padding layout.
-