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

public final Class StringSupport

extends Object
Class Inheritance
Imports
jdk.internal.access.JavaLangAccess, .SharedSecrets, jdk.internal.misc.ScopedMemoryAccess, jdk.internal.util.Architecture, .ArraysSupport, .Preconditions, jdk.internal.vm.annotation.ForceInline, java.lang.foreign.MemorySegment, java.lang.reflect.Array, java.nio.charset.CharacterCodingException, .Charset, java.util.Objects

Miscellaneous functions to read and write strings, in various charsets.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private static final long
private static final long
private static final long
private static final JavaLangAccess
private static final long
private static final long
private static final long
private static final long
private static final ScopedMemoryAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
bytesCompatible(String string, Charset charset, int srcIndex, int numChars)

public static int
copyBytes(String string, MemorySegment segment, Charset charset, long offset)

public static int
copyBytes(String string, MemorySegment segment, Charset charset, long offset, int srcIndex, int numChars)

public static void
copyToSegmentRaw(String string, MemorySegment segment, long offset, int srcIndex, int srcLength)

private static String
exceptionInfo(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)

private static boolean
pack-priv static boolean
pack-priv static boolean
private static IndexOutOfBoundsException
nullNotFound(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)

public static String
read(AbstractMemorySegmentImpl segment, long offset, Charset charset)

public static String
read(AbstractMemorySegmentImpl segment, long offset, Charset charset, long length)

private static String
readByte(AbstractMemorySegmentImpl segment, long offset, Charset charset)

public static String
readBytes(AbstractMemorySegmentImpl segment, long offset, Charset charset, long length)

private static String
readInt(AbstractMemorySegmentImpl segment, long offset, Charset charset)

private static String
readShort(AbstractMemorySegmentImpl segment, long offset, Charset charset)

private static int
requireWithinStringSize(long size, AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)

private static IllegalArgumentException
stringTooLarge(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)

public static int

Returns:

the index of the first zero byte beginning at the provided fromOffset to the encountering of a zero byte in the provided segment checking bytes before the toOffset
strlenByte
(final AbstractMemorySegmentImpl
to examine
segment
,
final long
from where examination shall begin (inclusive)
fromOffset
,
final long
to where examination shall end (exclusive)
toOffset
)

Returns the index of the first zero byte beginning at the provided fromOffset to the encountering of a zero byte in the provided segment checking bytes before the toOffset.

public static int
strlenInt(final AbstractMemorySegmentImpl segment, final long fromOffset, final long toOffset)

public static int
strlenShort(final AbstractMemorySegmentImpl segment, final long fromOffset, final long toOffset)

public static void
write(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)

private static void
writeByte(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)

private static void
writeInt(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)

private static void
writeShort(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HIMAGIC_FOR_BYTESback to summary
private static final long HIMAGIC_FOR_BYTES
HIMAGIC_FOR_INTSback to summary
private static final long HIMAGIC_FOR_INTS
HIMAGIC_FOR_SHORTSback to summary
private static final long HIMAGIC_FOR_SHORTS
JAVA_LANG_ACCESSback to summary
private static final JavaLangAccess JAVA_LANG_ACCESS
LOMAGIC_FOR_BYTESback to summary
private static final long LOMAGIC_FOR_BYTES
LOMAGIC_FOR_INTSback to summary
private static final long LOMAGIC_FOR_INTS
LOMAGIC_FOR_SHORTSback to summary
private static final long LOMAGIC_FOR_SHORTS
LONG_MASKback to summary
private static final long LONG_MASK
SCOPED_MEMORY_ACCESSback to summary
private static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS

Constructor Detail

StringSupportback to summary
private StringSupport()

Method Detail

bytesCompatibleback to summary
public static boolean bytesCompatible(String string, Charset charset, int srcIndex, int numChars)
copyBytesback to summary
public static int copyBytes(String string, MemorySegment segment, Charset charset, long offset)
copyBytesback to summary
public static int copyBytes(String string, MemorySegment segment, Charset charset, long offset, int srcIndex, int numChars)
copyToSegmentRawback to summary
public static void copyToSegmentRaw(String string, MemorySegment segment, long offset, int srcIndex, int srcLength)
exceptionInfoback to summary
private static String exceptionInfo(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)
mightContainZeroByteback to summary
private static boolean mightContainZeroByte(long l)
mightContainZeroIntback to summary
pack-priv static boolean mightContainZeroInt(long l)
mightContainZeroShortback to summary
pack-priv static boolean mightContainZeroShort(long l)
nullNotFoundback to summary
private static IndexOutOfBoundsException nullNotFound(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)
readback to summary
public static String read(AbstractMemorySegmentImpl segment, long offset, Charset charset)
Annotations
@ForceInline
readback to summary
public static String read(AbstractMemorySegmentImpl segment, long offset, Charset charset, long length)
Annotations
@ForceInline
readByteback to summary
private static String readByte(AbstractMemorySegmentImpl segment, long offset, Charset charset)
Annotations
@ForceInline
readBytesback to summary
public static String readBytes(AbstractMemorySegmentImpl segment, long offset, Charset charset, long length)
Annotations
@ForceInline
readIntback to summary
private static String readInt(AbstractMemorySegmentImpl segment, long offset, Charset charset)
Annotations
@ForceInline
readShortback to summary
private static String readShort(AbstractMemorySegmentImpl segment, long offset, Charset charset)
Annotations
@ForceInline
requireWithinStringSizeback to summary
private static int requireWithinStringSize(long size, AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)
stringTooLargeback to summary
private static IllegalArgumentException stringTooLarge(AbstractMemorySegmentImpl segment, long fromOffset, long toOffset)
strlenByteback to summary
public static int strlenByte(final AbstractMemorySegmentImpl segment, final long fromOffset, final long toOffset)

Returns the index of the first zero byte beginning at the provided fromOffset to the encountering of a zero byte in the provided segment checking bytes before the toOffset.

The method is using a heuristic method to determine if a long word contains a zero byte. The method might have false positives but never false negatives.

This method is inspired by the `glibc/string/strlen.c` implementation

Parameters
segment:AbstractMemorySegmentImpl

to examine

fromOffset:long

from where examination shall begin (inclusive)

toOffset:long

to where examination shall end (exclusive)

Returns:int

the index of the first zero byte beginning at the provided fromOffset to the encountering of a zero byte in the provided segment checking bytes before the toOffset

Annotations
@ForceInline
Exceptions
IllegalArgumentException:
if the examined region contains no zero bytes within a length that can be accepted by a String
strlenIntback to summary
public static int strlenInt(final AbstractMemorySegmentImpl segment, final long fromOffset, final long toOffset)
Annotations
@ForceInline
strlenShortback to summary
public static int strlenShort(final AbstractMemorySegmentImpl segment, final long fromOffset, final long toOffset)
Annotations
@ForceInline
writeback to summary
public static void write(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)
Annotations
@ForceInline
writeByteback to summary
private static void writeByte(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)
Annotations
@ForceInline
writeIntback to summary
private static void writeInt(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)
Annotations
@ForceInline
writeShortback to summary
private static void writeShort(AbstractMemorySegmentImpl segment, long offset, Charset charset, String string)
Annotations
@ForceInline
jdk.internal.foreign back to summary

public final Enum StringSupport.CharsetKind

extends Enum<StringSupport.CharsetKind>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final StringSupport.CharsetKind
public static final StringSupport.CharsetKind
public static final StringSupport.CharsetKind
pack-priv final int

Constructor Summary

AccessConstructor and Description
private
CharsetKind(int terminatorCharSize)

Method Summary

Modifier and TypeMethod and Description
public static StringSupport.CharsetKind
of(Charset charset)

public int
public static StringSupport.CharsetKind
public static StringSupport.CharsetKind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DOUBLE_BYTEback to summary
public static final StringSupport.CharsetKind DOUBLE_BYTE
QUAD_BYTEback to summary
public static final StringSupport.CharsetKind QUAD_BYTE
SINGLE_BYTEback to summary
public static final StringSupport.CharsetKind SINGLE_BYTE
terminatorCharSizeback to summary
pack-priv final int terminatorCharSize

Constructor Detail

CharsetKindback to summary
private CharsetKind(int terminatorCharSize)

Method Detail

ofback to summary
public static StringSupport.CharsetKind of(Charset charset)
terminatorCharSizeback to summary
public int terminatorCharSize()
valueOfback to summary
public static StringSupport.CharsetKind valueOf(String name)
valuesback to summary
public static StringSupport.CharsetKind[] values()