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

public final Class SegmentBulkOperations

extends Object
Class Inheritance
Imports
jdk.internal.misc.ScopedMemoryAccess, jdk.internal.util.Architecture, .ArraysSupport, jdk.internal.vm.annotation.ForceInline, .Stable, java.lang.foreign.MemorySegment

This class contains optimized bulk operation methods that operate on one or several memory segments.

Generally, the methods attempt to work with as-large-as-possible units of memory at a time.

It should be noted that when invoking scoped memory access get/set operations, it is imperative from a performance perspective to convey the sharp types from the call site in order for the compiler to pick the correct Unsafe access variant.

Field Summary

Modifier and TypeField and Description
private static final long
private static final long
private static final int
private static final int
private static final int
private static final int[]
pack-priv static final String
private static final ScopedMemoryAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

a 32-bit hash value calculated from the content in the provided segment between the provided offsets
contentHash
(AbstractMemorySegmentImpl
from which a content hash should be computed
segment
,
long
starting offset (inclusive) in the segment
fromOffset
,
long
ending offset (non-inclusive) in the segment
toOffset
)

Returns a 32-bit hash value calculated from the content in the provided segment between the provided offsets.

public static void
copy(AbstractMemorySegmentImpl src, long srcOffset, AbstractMemorySegmentImpl dst, long dstOffset, long size)

public static MemorySegment
public static long
mismatch(AbstractMemorySegmentImpl src, long srcFromOffset, long srcToOffset, AbstractMemorySegmentImpl dst, long dstFromOffset, long dstToOffset)

private static long
mismatch(AbstractMemorySegmentImpl src, long srcFromOffset, AbstractMemorySegmentImpl dst, long dstFromOffset, long start, int length, boolean srcAndDstBytesDiffer)

private static int
mismatch(long first, long second)

private static int
mismatch(int first, int second)

private static int
mismatch(short first, short second)

pack-priv static int
powerOfPropertyOr(String name, int defaultPower)

private static long
vectorizedMismatchLargeForBytes(MemorySessionImpl aSession, MemorySessionImpl bSession, Object a, long aOffset, Object b, long bOffset, long length)

Mismatch over long lengths.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE_REPLICATORback to summary
private static final long BYTE_REPLICATOR
LONG_MASKback to summary
private static final long LONG_MASK
NATIVE_THRESHOLD_COPYback to summary
private static final int NATIVE_THRESHOLD_COPY
NATIVE_THRESHOLD_FILLback to summary
private static final int NATIVE_THRESHOLD_FILL
NATIVE_THRESHOLD_MISMATCHback to summary
private static final int NATIVE_THRESHOLD_MISMATCH
POWERS_OF_31back to summary
private static final int[] POWERS_OF_31
Annotations
@Stable
PROPERTY_PATHback to summary
pack-priv static final String PROPERTY_PATH
SCOPED_MEMORY_ACCESSback to summary
private static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS

Constructor Detail

SegmentBulkOperationsback to summary
private SegmentBulkOperations()

Method Detail

contentHashback to summary
public static int contentHash(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)

Returns a 32-bit hash value calculated from the content in the provided segment between the provided offsets.

The method is implemented as a 32-bit polynomial hash function equivalent to:

final long length = toOffset - fromOffset; segment.checkBounds(fromOffset, length); int result = 1; for (long i = fromOffset; i < toOffset; i++) { result = 31 * result + segment.get(JAVA_BYTE, i); } return result;
final long length = toOffset - fromOffset;
segment.checkBounds(fromOffset, length);
int result = 1;
for (long i = fromOffset; i < toOffset; i++) {
    result = 31 * result + segment.get(JAVA_BYTE, i);
}
return result;
but is potentially more performant.
Parameters
segment:AbstractMemorySegmentImpl

from which a content hash should be computed

fromOffset:long

starting offset (inclusive) in the segment

toOffset:long

ending offset (non-inclusive) in the segment

Returns:int

a 32-bit hash value calculated from the content in the provided segment between the provided offsets

Annotations
@ForceInline
Exceptions
WrongThreadException:
if this method is called from a thread T, such that srcSegment.isAccessibleBy(T) == false
IllegalStateException:
if the scope associated with segment is not alive
IndexOutOfBoundsException:
  • if either fromOffset or toOffset are > segment.byteSize
  • if either fromOffset or toOffset are < 0
  • if toOffset - fromOffset is < 0
copyback to summary
public static void copy(AbstractMemorySegmentImpl src, long srcOffset, AbstractMemorySegmentImpl dst, long dstOffset, long size)
Annotations
@ForceInline
fillback to summary
public static MemorySegment fill(AbstractMemorySegmentImpl dst, byte value)
Annotations
@ForceInline
mismatchback to summary
public static long mismatch(AbstractMemorySegmentImpl src, long srcFromOffset, long srcToOffset, AbstractMemorySegmentImpl dst, long dstFromOffset, long dstToOffset)
Annotations
@ForceInline
mismatchback to summary
private static long mismatch(AbstractMemorySegmentImpl src, long srcFromOffset, AbstractMemorySegmentImpl dst, long dstFromOffset, long start, int length, boolean srcAndDstBytesDiffer)
Annotations
@ForceInline
mismatchback to summary
private static int mismatch(long first, long second)
Annotations
@ForceInline
mismatchback to summary
private static int mismatch(int first, int second)
Annotations
@ForceInline
mismatchback to summary
private static int mismatch(short first, short second)
Annotations
@ForceInline
powerOfPropertyOrback to summary
pack-priv static int powerOfPropertyOr(String name, int defaultPower)
vectorizedMismatchLargeForBytesback to summary
private static long vectorizedMismatchLargeForBytes(MemorySessionImpl aSession, MemorySessionImpl bSession, Object a, long aOffset, Object b, long bOffset, long length)

Mismatch over long lengths.