Elide GraalVM25.6.0-elide.4
All types
Versions and modules

TruffleString.FromNativePointerNode

Javaabstract classin com.oracle.truffle.api.stringssince 22.1

public abstract static class TruffleString.FromNativePointerNode extends AbstractPublicNode
Inheritance
  1. Object
  2. Node
  3. AbstractPublicNode
  4. FromNativePointerNode
Enclosing type
TruffleString

Node to create a new TruffleString from an interop object representing a native pointer. See execute(Object, int, int, TruffleString.Encoding, boolean) for details.

Members shown

Methods3 + 26 inherited

TruffleString execute(Object, int, int, TruffleString.Encoding, boolean)

execute

abstractsince 22.1
public abstract TruffleString execute(
    Object pointerObject,
    int byteOffset,
    int byteLength,
    TruffleString.Encoding encoding,
    boolean copy
)

Create a new TruffleString from an interop object representing a native pointer ( isPointer(pointerObject) must return true). The pointer is immediately unboxed with (asPointer(pointerObject)) and saved in the TruffleString instance, i.e. TruffleString assumes that the pointer address does not change. The pointer's content is assumed to be encoded in the given encoding already. If copy is false, the native pointer is used directly as the new string's backing storage. Caution: TruffleString assumes the pointer's content to be immutable, do not modify the pointer's content after passing it to this operation!

WARNING: TruffleString cannot reason about the lifetime of the native pointer, so it is up to the user to make sure that the native pointer is valid to access and not freed as long the pointerObject is alive (if copy is false). To help with this the TruffleString keeps a reference to the given pointerObject, so the pointerObject is kept alive at least as long as the TruffleString is used. In order to be able to use the string past the native pointer's life time, convert it to a managed string via AsManagedNode before the native pointer is freed.

Since GraalVM version 25.1, the native pointer may also be passed as a boxed long value in place of pointerObject. Note that in this case, the resulting TruffleString cannot keep a reference an associated object for life-time tracking. The user is responsible for making sure the native buffer is not freed as long as the TruffleString object is alive.

If copy is true, the pointer's contents are copied to a Java byte array, and the pointer can be freed safely after the operation completes.

This operation requires native access permissions (TruffleLanguage.Env#isNativeAccessAllowed()).

Parameters

pointerObjectObject
No description.
byteOffsetint
No description.
byteLengthint
No description.
encodingTruffleString.Encoding
No description.
copyboolean
No description.

Returns

TruffleString
No description.
static TruffleString.FromNativePointerNode create()

create

staticsince 22.1
public static TruffleString.FromNativePointerNode create()

Create a new FromNativePointerNode.

static TruffleString.FromNativePointerNode getUncached()

getUncached

staticsince 22.1
public static TruffleString.FromNativePointerNode getUncached()

Get the uncached version of FromNativePointerNode.

Inherited members