MemoryLayoutpublic sealed interface SequenceLayout extends MemoryLayout
MemoryLayout.sequenceLayout(3, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
MemoryLayout.structLayout(
ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
MemoryLayout.PathElement
| Modifier and Type | Method | Description |
|---|---|---|
long |
elementCount() |
Returns the element count of this sequence layout. |
MemoryLayout |
elementLayout() |
Returns the element layout of this sequence layout. |
SequenceLayout |
flatten() |
Returns a flattened sequence layout. |
SequenceLayout |
reshape |
Rearranges the elements in this sequence layout into a multidimensional sequence layout. |
SequenceLayout |
withByteAlignment |
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes). |
SequenceLayout |
withElementCount |
Returns a sequence layout with the same characteristics of this layout, but with the given element count. |
SequenceLayout |
withName |
Returns a memory layout with the same characteristics as this layout, but with the given name. |
arrayElementVarHandle, byteAlignment, byteOffset, byteOffsetHandle, byteSize, equals, hashCode, name, scale, scaleHandle, select, sliceHandle, toString, varHandle, withoutName
MemoryLayout elementLayout()
long elementCount()
SequenceLayout withElementCount(long elementCount)
elementCount - the new element countIllegalArgumentException - if elementCount is negativeIllegalArgumentException - if elementLayout.bitSize() * elementCount overflowsSequenceLayout reshape(long... elementCounts)
For instance, given a sequence layout of the kind:
var seq = MemoryLayout.sequenceLayout(4, MemoryLayout.sequenceLayout(3, ValueLayout.JAVA_INT));
seq.reshape(2, 6) will yield the following sequence layout: var reshapeSeq = MemoryLayout.sequenceLayout(2, MemoryLayout.sequenceLayout(6, ValueLayout.JAVA_INT));
If one of the provided element counts is the special value -1, then the element count in that position will be inferred from the remaining element counts and the element count of the flattened projection of this layout. For instance, a layout equivalent to the above reshapeSeq can also be computed in the following ways:
var reshapeSeqImplicit1 = seq.reshape(-1, 6);
var reshapeSeqImplicit2 = seq.reshape(2, -1);
elementCounts - an array of element counts, of which at most one can be -1
flatten()) are re-arranged into one or more nested sequence layoutsIllegalArgumentException - if two or more element counts are set to -1, or if one or more element count is <= 0 (but other than -1) or, if, after any required inference, multiplying the element counts does not yield the same element count as the flattened projection of this sequence layoutSequenceLayout flatten()
MemoryLayout flatElementLayout(SequenceLayout sequenceLayout) {
return switch (sequenceLayout.elementLayout()) {
case SequenceLayout nestedSequenceLayout -> flatElementLayout(nestedSequenceLayout);
case MemoryLayout layout -> layout;
};
}
This transformation preserves the layout size; nested sequence layout in this sequence layout will be dropped and their element counts will be incorporated into that of the returned sequence layout. For instance, given a sequence layout of the kind:
var seq = MemoryLayout.sequenceLayout(4, MemoryLayout.sequenceLayout(3, ValueLayout.JAVA_INT));
seq.flatten() will yield the following sequence layout: var flattenedSeq = MemoryLayout.sequenceLayout(12, ValueLayout.JAVA_INT);
SequenceLayout withName(String name)
withName in interface MemoryLayout
name - the layout nameSequenceLayout withByteAlignment(long byteAlignment)
withByteAlignment in interface MemoryLayout
byteAlignment - the layout alignment constraint, expressed in bytesIllegalArgumentException - if byteAlignment is not a power of twoIllegalArgumentException - if byteAlignment < elementLayout().byteAlignment()
© 1993, 2025, 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/25/docs/api/java.base/java/lang/foreign/SequenceLayout.html