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

pack-priv abstract sealed Class HeapMemorySegmentImpl

extends AbstractMemorySegmentImpl
permits OfByte, OfChar, OfShort, OfInt, OfLong, OfFloat, OfDouble
Class Inheritance
Known Direct Subclasses
jdk.internal.foreign.HeapMemorySegmentImpl.OfByte, jdk.internal.foreign.HeapMemorySegmentImpl.OfChar, jdk.internal.foreign.HeapMemorySegmentImpl.OfShort, jdk.internal.foreign.HeapMemorySegmentImpl.OfInt, jdk.internal.foreign.HeapMemorySegmentImpl.OfLong, jdk.internal.foreign.HeapMemorySegmentImpl.OfFloat, jdk.internal.foreign.HeapMemorySegmentImpl.OfDouble
Imports
jdk.internal.ValueBased, jdk.internal.access.JavaNioAccess, .SharedSecrets, jdk.internal.vm.annotation.ForceInline, java.lang.foreign.ValueLayout, java.nio.ByteBuffer, java.util.Objects, .Optional

Implementation for heap memory segments. A heap memory segment is composed by an offset and a base object (typically an array). To enhance performances, the access to the base object needs to feature sharp type information, as well as sharp null-check information. For this reason, many concrete subclasses of HeapMemorySegmentImpl are defined (e.g. OfFloat), so that each subclass can override the HeapMemorySegmentImpl#unsafeGetBase() method so that it returns an array of the correct (sharp) type. Note that the field type storing the 'base' coordinate is just Object; similarly, all the constructor in the subclasses accept an Object 'base' parameter instead of a sharper type (e.g. byte[]). This is deliberate, as using sharper types would require use of type-conversions, which in turn would inhibit some C2 optimizations, such as the elimination of store barriers in methods like HeapMemorySegmentImpl#dup(long, long, boolean, MemorySessionImpl).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class
public static class
public static class
public static class
public static class

Field Summary

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

Constructor Summary

AccessConstructor and Description
pack-priv
HeapMemorySegmentImpl(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract HeapMemorySegmentImpl
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.

pack-priv ByteBuffer
public final long
maxByteAlignment()

Implements java.lang.foreign.MemorySegment.maxByteAlignment.

Returns the maximum byte alignment associated with this memory segment.

public long
Inherited from jdk.internal.foreign.AbstractMemorySegmentImpl:
allocateasByteBufferasOverlappingSliceasReadOnlyasSliceasSliceasSliceasSlicebyteSizecheckAccesscheckAccessBoundscheckEnclosingLayoutcheckReadOnlycheckSliceBoundscopycopycopycopycopyFromelementsequalsfillforcegetgetgetgetgetgetgetgetgetgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetAtIndexgetStringgetStringgetStringhashCodeisAccessibleByisAlignedForElementisAlignedForElementisLoadedisMappedisNativeisReadOnlyloadmaxAlignMaskmismatchofBufferoverlapsreinterpretreinterpretreinterpretscopesessionImplsetsetsetsetsetsetsetsetsetsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetAtIndexsetStringsetStringspliteratortoArraytoArraytoArraytoArraytoArraytoArraytoArraytoStringunloadunsafeGetBase

Field Detail

baseback to summary
pack-priv final Object base
MAX_ALIGN_BYTE_ARRAYback to summary
private static final long MAX_ALIGN_BYTE_ARRAY
MAX_ALIGN_INT_ARRAYback to summary
private static final long MAX_ALIGN_INT_ARRAY
MAX_ALIGN_LONG_ARRAYback to summary
private static final long MAX_ALIGN_LONG_ARRAY
MAX_ALIGN_SHORT_ARRAYback to summary
private static final long MAX_ALIGN_SHORT_ARRAY
offsetback to summary
pack-priv final long offset

Constructor Detail

HeapMemorySegmentImplback to summary
pack-priv HeapMemorySegmentImpl(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)
Annotations
@ForceInline

Method Detail

dupback to summary
pack-priv abstract HeapMemorySegmentImpl dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

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

Annotations
@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
makeByteBufferback to summary
pack-priv ByteBuffer makeByteBuffer()

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

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)
}
Annotations
@Override
unsafeGetOffsetback to summary
public long unsafeGetOffset()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfByte

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfByte(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfByte
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public byte[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfByteback to summary
pack-priv OfByte(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfByte dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public byte[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfChar

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfChar(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfChar
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public char[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfCharback to summary
pack-priv OfChar(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfChar dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public char[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfDouble

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfDouble(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfDouble
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public double[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfDoubleback to summary
pack-priv OfDouble(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfDouble dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public double[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfFloat

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfFloat(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfFloat
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public float[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfFloatback to summary
pack-priv OfFloat(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfFloat dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public float[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfInt

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfInt(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfInt
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public int[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfIntback to summary
pack-priv OfInt(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfInt dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public int[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfLong

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfLong(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfLong
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public long[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfLongback to summary
pack-priv OfLong(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfLong dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public long[] unsafeGetBase()

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

Annotations
@Override
jdk.internal.foreign back to summary

public final Class HeapMemorySegmentImpl.OfShort

extends HeapMemorySegmentImpl
Class Inheritance
Annotations
@ValueBased

Field Summary

Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
baseoffset

Constructor Summary

AccessConstructor and Description
pack-priv
OfShort(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfShort
dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

public long
public short[]
Inherited from jdk.internal.foreign.HeapMemorySegmentImpl:
heapBasemakeByteBuffermaxByteAlignmentunsafeGetOffset

Constructor Detail

OfShortback to summary
pack-priv OfShort(long offset, Object base, long length, boolean readOnly, MemorySessionImpl session)

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 HeapMemorySegmentImpl.OfShort dup(long offset, long size, boolean readOnly, MemorySessionImpl scope)

Implements abstract jdk.internal.foreign.HeapMemorySegmentImpl.dup.

Annotations
@Override
maxAlignMaskback to summary
public long maxAlignMask()

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

Annotations
@Override
unsafeGetBaseback to summary
public short[] unsafeGetBase()

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

Annotations
@Override