public final class ObjectHandlesImpl extends Object implements org.graalvm.nativeimage.ObjectHandles
word
-sized integer handles that refer to Java objects.
Creating
, dereferencing
and
destroying
handles is thread-safe and the handles themselves are
valid across threads. This class also supports weak handles, with which the referenced object may
be garbage-collected, after which ObjectHandlesImpl.get(ObjectHandle)
returns null
. Still, weak
handles must also be explicitly destroyed
to reclaim their
handle value.
The implementation uses a variable number of object arrays, in which each array element
represents a handle. The array element's index determines the handle's integer value, and the
element's stored value is the referenced object. Creating a handle entails finding a null
array element and using compare-and-set to write the referenced object into it, avoiding a
heavy-weight lock. If there are no null
elements in the existing arrays, an additional
array is created. This array has twice the capacity of the previous array, which plays a
significant role in how indexing is implemented.
Constructor and Description |
---|
ObjectHandlesImpl() |
ObjectHandlesImpl(org.graalvm.word.SignedWord rangeMin,
org.graalvm.word.SignedWord rangeMax,
org.graalvm.word.SignedWord nullHandle) |
Modifier and Type | Method and Description |
---|---|
long |
computeCurrentCapacity() |
long |
computeCurrentCount() |
org.graalvm.nativeimage.ObjectHandle |
create(Object obj) |
org.graalvm.nativeimage.ObjectHandle |
createWeak(Object obj) |
void |
destroy(org.graalvm.nativeimage.ObjectHandle handle) |
void |
destroyWeak(org.graalvm.nativeimage.ObjectHandle handle) |
<T> T |
get(org.graalvm.nativeimage.ObjectHandle handle) |
boolean |
isInRange(org.graalvm.nativeimage.ObjectHandle handle) |
boolean |
isWeak(org.graalvm.nativeimage.ObjectHandle handle) |
public ObjectHandlesImpl()
public ObjectHandlesImpl(org.graalvm.word.SignedWord rangeMin, org.graalvm.word.SignedWord rangeMax, org.graalvm.word.SignedWord nullHandle)
public boolean isInRange(org.graalvm.nativeimage.ObjectHandle handle)
public org.graalvm.nativeimage.ObjectHandle create(Object obj)
create
in interface org.graalvm.nativeimage.ObjectHandles
public org.graalvm.nativeimage.ObjectHandle createWeak(Object obj)
public <T> T get(org.graalvm.nativeimage.ObjectHandle handle)
get
in interface org.graalvm.nativeimage.ObjectHandles
public boolean isWeak(org.graalvm.nativeimage.ObjectHandle handle)
public void destroy(org.graalvm.nativeimage.ObjectHandle handle)
destroy
in interface org.graalvm.nativeimage.ObjectHandles
public void destroyWeak(org.graalvm.nativeimage.ObjectHandle handle)
public long computeCurrentCount()
public long computeCurrentCapacity()