W3cubDocs

/OpenJDK 25

Interface AddressLayout

All Superinterfaces:
MemoryLayout, ValueLayout
public sealed interface AddressLayout extends ValueLayout
A value layout used to model the address of some region of memory. The carrier associated with an address layout is MemorySegment.class. The size and alignment of an address layout are platform-dependent (e.g. on a 64-bit platform, the size and alignment of an address layout are set to 8 bytes).

An address layout may optionally feature a target layout. An address layout with target layout T can be used to model the address of a region of memory whose layout is T. For instance, an address layout with target layout ValueLayout.JAVA_INT can be used to model the address of a region of memory that is 4 bytes long. Specifying a target layout can be useful in the following situations:

Implementation Requirements:
Implementations of this interface are immutable, thread-safe and value-based.
Since:
22
See Also:

Nested Class Summary

Nested classes/interfaces declared in interface MemoryLayout

MemoryLayout.PathElement

Field Summary

Method Summary

Modifier and Type Method Description
Optional<MemoryLayout> targetLayout()
Returns the target layout associated with this address layout (if any).
AddressLayout withByteAlignment(long byteAlignment)
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes).
AddressLayout withName(String name)
Returns a memory layout with the same characteristics as this layout, but with the given name.
AddressLayout withOrder(ByteOrder order)
Returns a value layout with the same characteristics as this layout, but with the given byte order.
AddressLayout withoutName()
Returns a memory layout with the same characteristics as this layout, but with no name.
AddressLayout withoutTargetLayout()
Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but with no target layout.
AddressLayout withTargetLayout(MemoryLayout layout)
Restricted.
Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but associated with the specified target layout.

Methods declared in interface ValueLayout

carrier, order, varHandle

Method Details

withName

AddressLayout withName(String name)
Returns a memory layout with the same characteristics as this layout, but with the given name.
Specified by:
withName in interface MemoryLayout
Specified by:
withName in interface ValueLayout
Parameters:
name - the layout name
Returns:
a memory layout with the same characteristics as this layout, but with the given name
See Also:

withoutName

AddressLayout withoutName()
Returns a memory layout with the same characteristics as this layout, but with no name.
Specified by:
withoutName in interface MemoryLayout
Specified by:
withoutName in interface ValueLayout
Returns:
a memory layout with the same characteristics as this layout, but with no name
See Also:

withByteAlignment

AddressLayout withByteAlignment(long byteAlignment)
Returns a memory layout with the same characteristics as this layout, but with the given alignment constraint (in bytes).
Specified by:
withByteAlignment in interface MemoryLayout
Specified by:
withByteAlignment in interface ValueLayout
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)

withOrder

AddressLayout withOrder(ByteOrder order)
Returns a value layout with the same characteristics as this layout, but with the given byte order.
Specified by:
withOrder in interface ValueLayout
Parameters:
order - the desired byte order
Returns:
a value layout with the same characteristics as this layout, but with the given byte order

withTargetLayout

AddressLayout withTargetLayout(MemoryLayout layout)
withTargetLayout is a restricted method of the Java platform.
Programs can only use withTargetLayout when access to restricted methods is enabled.
Restricted methods are unsafe, and, if used incorrectly, might crash the JVM or result in memory corruption.
Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but associated with the specified target layout. The returned address layout allows raw addresses to be accessed as memory segments whose size is set to the size of the specified layout. Moreover, if the accessed raw address is not compatible with the alignment constraint in the provided layout, IllegalArgumentException will be thrown.
API Note:
This method can also be used to create an address layout which, when used, creates native memory segments with maximal size (e.g. Long.MAX_VALUE). This can be done by using a target sequence layout with unspecified size, as follows:
 AddressLayout addressLayout   = ...
 AddressLayout unboundedLayout = addressLayout.withTargetLayout(
         MemoryLayout.sequenceLayout(Long.MAX_VALUE, ValueLayout.JAVA_BYTE));
Parameters:
layout - the target layout
Returns:
an address layout with same characteristics as this layout, but with the provided target layout
Throws:
IllegalCallerException - if the caller is in a module that does not have native access enabled
See Also:

withoutTargetLayout

AddressLayout withoutTargetLayout()
Returns an address layout with the same carrier, alignment constraint, name and order as this address layout, but with no target layout.
API Note:
This can be useful to compare two address layouts that have different target layouts, but are otherwise equal.
Returns:
an address layout with same characteristics as this layout, but with no target layout
See Also:

targetLayout

Optional<MemoryLayout> targetLayout()
Returns the target layout associated with this address layout (if any).
Returns:
the target layout associated with this address layout (if any)

© 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/AddressLayout.html