Top Description Methods
org.graalvm.nativeimage

public Interface PinnedObject

extends AutoCloseable
Imports
org.graalvm.nativeimage.impl.PinnedObjectSupport, org.graalvm.word.PointerBase

Holder for a pinned object, such that the object doesn't move until the pin is removed. The garbage collector treats pinned object specially to ensure that they are not moved or discarded.

This class implements AutoCloseable so that the pinning can be managed conveniently with a try-with-resource block that releases the pinning automatically:

  int[] array = ...
  try (PinnedObject pin = PinnedObject.create(array)) {
    CIntPointer rawData = pin.addressOfArrayElement(0);
    // it is safe to pass rawData to a C function.
  }
  // it is no longer safe to access rawData.
Since
19.0

Method Summary

Modifier and TypeMethod and Description
public <T extends PointerBase> T
addressOfArrayElement(int index)

Returns a pointer to the array element with the specified index.

public PointerBase
addressOfObject()

Returns the raw address of the pinned object.

public void
close()

Redeclares java.lang.AutoCloseable.close.

Releases the pin for the object.

public static PinnedObject
create(Object object)

Create an open PinnedObject.

public Object
getObject()

Returns the Object that is the referent of this PinnedObject.

Method Detail

addressOfArrayElementback to summary
public <T extends PointerBase> T addressOfArrayElement(int index)

Returns a pointer to the array element with the specified index. The object must be an array. No array bounds check for the index is performed.

Since
19.0
addressOfObjectback to summary
public PointerBase addressOfObject()

Returns the raw address of the pinned object. The object layout is not specified, but usually the address of an object is a pointer to to the first header word. In particular, the result is not a pointer to the first array element when the object is an array.

Since
19.0
closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Releases the pin for the object. After this call, the object can be moved or discarded by the garbage collector.

Annotations
@Override
Since
19.0
createback to summary
public static PinnedObject create(Object object)

Create an open PinnedObject.

Since
19.0
getObjectback to summary
public Object getObject()

Returns the Object that is the referent of this PinnedObject.

Since
19.0