- All Implemented Interfaces:
Constable
,MemoryLayout
- Direct Known Subclasses:
ValueLayout.OfAddress
,ValueLayout.OfBoolean
,ValueLayout.OfByte
,ValueLayout.OfChar
,ValueLayout.OfDouble
,ValueLayout.OfFloat
,ValueLayout.OfInt
,ValueLayout.OfLong
,ValueLayout.OfShort
This class defines useful value layout constants for Java primitive types and addresses.
The layout constants in this class make implicit alignment and byte-ordering assumption: all layout
constants in this class are byte-aligned, and their byte order is set to the platform default,
thus making it easy to work with other APIs, such as arrays and ByteBuffer
.
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
Modifier and TypeClassDescriptionstatic final class
A value layout whose carrier isMemoryAddress.class
.static final class
A value layout whose carrier isboolean.class
.static final class
A value layout whose carrier isbyte.class
.static final class
A value layout whose carrier ischar.class
.static final class
A value layout whose carrier isdouble.class
.static final class
A value layout whose carrier isfloat.class
.static final class
A value layout whose carrier isint.class
.static final class
A value layout whose carrier islong.class
.static final class
A value layout whose carrier isshort.class
.Nested classes/interfaces declared in interface jdk.incubator.foreign.MemoryLayout
MemoryLayout.PathElement
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ValueLayout.OfAddress
A value layout constant whose size is the same as that of a machine address (size_t
), bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfBoolean
A value layout constant whose size is the same as that of a Javaboolean
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfByte
A value layout constant whose size is the same as that of a Javabyte
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfChar
A value layout constant whose size is the same as that of a Javachar
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfDouble
A value layout constant whose size is the same as that of a Javadouble
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfFloat
A value layout constant whose size is the same as that of a Javafloat
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfInt
A value layout constant whose size is the same as that of a Javaint
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfLong
A value layout constant whose size is the same as that of a Javalong
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
.static final ValueLayout.OfShort
A value layout constant whose size is the same as that of a Javashort
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. -
Method Summary
Modifier and TypeMethodDescriptionfinal long
Returns the alignment constraint associated with this layout, expressed in bits.long
bitSize()
Returns the layout size, in bits.long
byteSize()
Returns the layout size, in bytes.Class<?>
carrier()
Returns the carrier associated with this value layout.boolean
Indicates whether some other object is "equal to" this one.int
hashCode()
Returns a hash code value for the object.boolean
hasSize()
Returnstrue
if this layout has a specified size.boolean
Returns true, if this layout is a padding layout.name()
Returns the name (if any) associated with this layout.order()
Returns the value's byte order.toString()
Returns a string representation of the object.withBitAlignment
(long alignmentBits) Creates a new layout which features the desired alignment constraint.Creates a new layout which features the desired layout name.Returns a new value layout with given byte order.Methods declared in class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface jdk.incubator.foreign.MemoryLayout
bitAlignment, bitOffset, bitOffsetHandle, bitSize, byteAlignment, byteOffset, byteOffsetHandle, byteSize, hasSize, isPadding, map, name, select, sliceHandle, varHandle
-
Field Details
-
ADDRESS
A value layout constant whose size is the same as that of a machine address (size_t
), bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(MemoryAddress.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_BYTE
A value layout constant whose size is the same as that of a Javabyte
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(byte.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_BOOLEAN
A value layout constant whose size is the same as that of a Javaboolean
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(boolean.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_CHAR
A value layout constant whose size is the same as that of a Javachar
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(char.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_SHORT
A value layout constant whose size is the same as that of a Javashort
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(short.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_INT
A value layout constant whose size is the same as that of a Javaint
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(int.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_LONG
A value layout constant whose size is the same as that of a Javalong
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(long.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_FLOAT
A value layout constant whose size is the same as that of a Javafloat
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(float.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
JAVA_DOUBLE
A value layout constant whose size is the same as that of a Javadouble
, bit alignment set to 8, and byte order set toByteOrder.nativeOrder()
. Equivalent to the following code:MemoryLayout.valueLayout(double.class, ByteOrder.nativeOrder()).withBitAlignment(8);
-
-
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.
-
toString
Description copied from class:Object
Returns a string representation of the object.- Specified by:
toString
in interfaceMemoryLayout
- Overrides:
toString
in classObject
- Returns:
- a string representation of the object.
-
equals
Description copied from class:Object
Indicates whether some other object is "equal to" this one.The
equals
method implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
- Specified by:
equals
in interfaceMemoryLayout
- Parameters:
other
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.- See Also:
- It is reflexive: for any non-null reference value
-
carrier
Returns the carrier associated with this value layout.- Returns:
- the carrier associated with this value layout
-
hashCode
public int hashCode()Description copied from class:Object
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap
.The general contract of
hashCode
is:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equals
method, then calling thehashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
- Specified by:
hashCode
in interfaceMemoryLayout
- Returns:
- a hash code value for this object.
- See Also:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
describeConstable
Description copied from interface:MemoryLayout
Returns anOptional
containing the nominal descriptor for this layout, if one can be constructed, or an emptyOptional
if one cannot be constructed.- Specified by:
describeConstable
in interfaceConstable
- Specified by:
describeConstable
in interfaceMemoryLayout
- Returns:
- an
Optional
containing the nominal descriptor for this layout, if one can be constructed, or an emptyOptional
if one cannot be constructed
-
withName
Creates a new layout which features the desired layout name.- Specified by:
withName
in 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:
withBitAlignment
in 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.
-
name
Description copied from interface:MemoryLayout
Returns the name (if any) associated with this layout.- Specified by:
name
in interfaceMemoryLayout
- Returns:
- the name (if any) associated with this layout
- See Also:
-
bitAlignment
public final long bitAlignment()Description copied from interface:MemoryLayout
Returns the alignment constraint associated with this layout, expressed in bits. Layout alignment defines a power of twoA
which is the bit-wise alignment of the layout. IfA <= 8
thenA/8
is the number of bytes that must be aligned for any pointer that correctly points to this layout. Thus:A=8
means unaligned (in the usual sense), which is common in packets.A=64
means word aligned (on LP64),A=32
int aligned,A=16
short aligned, etc.A=512
is 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:
bitAlignment
in interfaceMemoryLayout
- Returns:
- the layout alignment constraint, in bits.
-
byteSize
public long byteSize()Description copied from interface:MemoryLayout
Returns the layout size, in bytes.- Specified by:
byteSize
in interfaceMemoryLayout
- Returns:
- the layout size, in bytes
-
hasSize
public boolean hasSize()Description copied from interface:MemoryLayout
Returnstrue
if this layout has 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 returnstrue
in these cases.- Specified by:
hasSize
in interfaceMemoryLayout
- Returns:
true
, if this layout has a specified size.
-
bitSize
public long bitSize()Description copied from interface:MemoryLayout
Returns the layout size, in bits.- Specified by:
bitSize
in interfaceMemoryLayout
- Returns:
- the layout size, in bits
-
isPadding
public boolean isPadding()Description copied from interface:MemoryLayout
Returns true, if this layout is a padding layout.- Specified by:
isPadding
in interfaceMemoryLayout
- Returns:
- true, if this layout is a padding layout
-