Class MutableTruffleString.FromNativePointerNode
- All Implemented Interfaces:
NodeInterface, Cloneable
- Enclosing class:
MutableTruffleString
MutableTruffleString from an interop object representing a
native pointer. See execute(Object, int, int, TruffleString.Encoding, boolean) for
details.- Since:
- 22.1
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children -
Method Summary
Modifier and TypeMethodDescriptioncreate()Create a newMutableTruffleString.FromNativePointerNode.abstract MutableTruffleStringexecute(Object pointerObject, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Create a newMutableTruffleStringfrom an interop object representing a native pointer (isPointer(pointerObject)must returntrue).Get the uncached version ofMutableTruffleString.FromNativePointerNode.Methods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Method Details
-
execute
public abstract MutableTruffleString execute(Object pointerObject, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Create a newMutableTruffleStringfrom an interop object representing a native pointer (isPointer(pointerObject)must returntrue). The pointer is immediately unboxed with (asPointer(pointerObject)) and saved until the end of the string's lifetime, i.e.MutableTruffleStringassumes that the pointer address does not change. The pointer's content is assumed to be encoded in the given encoding already. Ifcopyisfalse, the native pointer is used directly as the new string's backing storage. Caution: If the pointer's content is modified after string creation, the string must be notified of this viaMutableTruffleString.notifyExternalMutation().WARNING:
MutableTruffleStringcannot 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 thepointerObjectis alive (ifcopyisfalse). To help with this the MutableTruffleString keeps a reference to the givenpointerObject, so thepointerObjectis kept alive at least as long as the MutableTruffleString is used. In order to be able to use the string past the native pointer's life time, convert it to a managed string viaMutableTruffleString.AsManagedNodebefore 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 resultingMutableTruffleStringcannot 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 theMutableTruffleStringobject is alive.If
This operation requires native access permissions (copyistrue, the pointer's contents are copied to a Java byte array, and the pointer can be freed safely after the operation completes.TruffleLanguage.Env#isNativeAccessAllowed()).- Since:
- 22.1
-
create
Create a newMutableTruffleString.FromNativePointerNode.- Since:
- 22.1
-
getUncached
Get the uncached version ofMutableTruffleString.FromNativePointerNode.- Since:
- 22.1
-