APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.foreign

public sealed Class NativeMemorySegmentImpl

extends AbstractMemorySegmentImpl
permits MappedMemorySegmentImpl
Class Inheritance
Known Direct Subclasses
jdk.internal.foreign.MappedMemorySegmentImpl
Imports
jdk.internal.misc.Unsafe, jdk.internal.vm.annotation.ForceInline, java.nio.ByteBuffer, java.util.Optional

Implementation for native memory segments. A native memory segment is essentially a wrapper around a native long address.

Field Summary

Modifier and TypeField and Description
pack-priv final long
Inherited from jdk.internal.foreign.AbstractMemorySegmentImpl:
lengthNIO_ACCESSreadOnlyscope

Constructor Summary

AccessConstructor and Description
pack-priv
NativeMemorySegmentImpl(long min, long length, boolean readOnly, MemorySessionImpl scope)

Method Summary

Modifier and TypeMethod and Description
public long
address()

Implements java.lang.foreign.MemorySegment.address.

Returns the address of this memory segment.

pack-priv NativeMemorySegmentImpl
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.dup.

public Optional<Object>
heapBase()

Implements java.lang.foreign.MemorySegment.heapBase.

Returns the Java object stored in the on-heap region of memory backing this memory segment, if any.

public boolean
isNative()

Overrides jdk.internal.foreign.AbstractMemorySegmentImpl.isNative.

Implements java.lang.foreign.MemorySegment.isNative.

Returns true if this segment is a native segment.

pack-priv ByteBuffer
public long
public final long
maxByteAlignment()

Implements java.lang.foreign.MemorySegment.maxByteAlignment.

Returns the maximum byte alignment associated with this memory segment.

public Object
public long
Inherited from jdk.internal.foreign.AbstractMemorySegmentImpl:
allocateasByteBufferasOverlappingSliceasReadOnlyasSliceasSliceasSliceasSlicebyteSizecheckAccesscheckAccessBoundscheckEnclosingLayoutcheckReadOnlycheckSliceBoundscopycopycopycopycopyFromelementsequalsfillforcegetgetgetgetgetgetgetgetgetgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetStringgetStringgetStringhashCodeisAccessibleByisAlignedForElementisAlignedForElementisLoadedisMappedisReadOnlyloadmismatchofBufferoverlapsreinterpretreinterpretreinterpretscopesessionImplsetsetsetsetsetsetsetsetsetsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetStringsetStringspliteratortoArraytoArraytoArraytoArraytoArraytoArraytoArraytoStringunload

Field Detail

minback to summary
pack-priv final long min

Constructor Detail

NativeMemorySegmentImplback to summary
pack-priv NativeMemorySegmentImpl(long min, long length, boolean readOnly, MemorySessionImpl scope)
Annotations
@ForceInline

Method Detail

addressback to summary
public long address()

Implements java.lang.foreign.MemorySegment.address.

Doc from java.lang.foreign.MemorySegment.address.

Returns the address of this memory segment.

Annotations
@Override
dupback to summary
pack-priv NativeMemorySegmentImpl dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.dup.

Annotations
@ForceInline
@Override
heapBaseback to summary
public Optional<Object> heapBase()

Implements java.lang.foreign.MemorySegment.heapBase.

Doc from java.lang.foreign.MemorySegment.heapBase.

Returns the Java object stored in the on-heap region of memory backing this memory segment, if any. For instance, if this memory segment is a heap segment created with the ofArray(byte[]) factory method, this method will return the byte[] object which was used to obtain the segment. This method returns an empty Optional value if either this segment is a native segment, or if this segment is read-only.

Annotations
@Override
isNativeback to summary
public boolean isNative()

Overrides jdk.internal.foreign.AbstractMemorySegmentImpl.isNative.

Implements java.lang.foreign.MemorySegment.isNative.

Doc from java.lang.foreign.MemorySegment.isNative.

Returns true if this segment is a native segment.

A native segment is created e.g. using the Arena#allocate(long, long) (and related) factory, or by wrapping a direct buffer.

Annotations
@Override
makeByteBufferback to summary
pack-priv ByteBuffer makeByteBuffer()

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.makeByteBuffer.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.maxAlignMask.

Annotations
@Override
maxByteAlignmentback to summary
public final long maxByteAlignment()

Implements java.lang.foreign.MemorySegment.maxByteAlignment.

Doc from java.lang.foreign.MemorySegment.maxByteAlignment.

Returns the maximum byte alignment associated with this memory segment.

The returned alignment is always a power of two and is derived from the segment address() and, if it is a heap segment, the type of the backing heap storage.

This method can be used to ensure that a segment is sufficiently aligned with a layout:

MemoryLayout layout = ... MemorySegment segment = ... if (segment.maxByteAlignment() < layout.byteAlignment()) { // Take action (e.g. throw an Exception) }
MemoryLayout layout = ...
MemorySegment segment = ...
if (segment.maxByteAlignment() < layout.byteAlignment()) {
    // Take action (e.g. throw an Exception)
}
unsafeGetBaseback to summary
public Object unsafeGetBase()

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.unsafeGetBase.

Annotations
@Override
unsafeGetOffsetback to summary
public long unsafeGetOffset()

Implements abstract jdk.internal.foreign.AbstractMemorySegmentImpl.unsafeGetOffset.

Annotations
@Override