Top Description Inners Fields Constructors Methods
org.graalvm.jniutils

public Class HSObject

extends Object
Class Inheritance
Static Imports
org.graalvm.jniutils.JNIUtil.DeleteGlobalRef, .JNIUtil.DeleteWeakGlobalRef, .JNIUtil.NewGlobalRef, .JNIUtil.NewWeakGlobalRef

Encapsulates a JNI handle to an object in the HotSpot heap. Depending on which constructor is used, the handle is either local to a JNIMethodScope and thus invalid once the scope exits or a global JNI handle that is only released sometime after the HSObject dies.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final HSObject.Cleaner
cleaner

Cleaner for Global Reference.

private static final Set<HSObject.Cleaner>
CLEANERS

Strong references to the PhantomReference objects.

private static final ReferenceQueue<HSObject>
CLEANERS_QUEUE

Queue into which a Cleaner is enqueued when its HSObject referent becomes unreachable.

private final JNI.JObject
handle

JNI handle to the HotSpot object.

private HSObject
next

Link to next the next scope local object.

Constructor Summary

AccessConstructor and Description
public
HSObject(JNI.JNIEnv env, JNI.JObject handle)

Creates an object encapsulating a handle whose lifetime is determined by this object.

public
HSObject(JNI.JNIEnv env, JNI.JObject handle, boolean allowGlobalDuplicates, boolean weak)

Creates an object encapsulating a handle whose lifetime is determined by this object.

public
HSObject(JNIMethodScope scope, JNI.JObject handle)

Creates an object encapsulating a handle whose lifetime is limited to scope.

Method Summary

Modifier and TypeMethod and Description
private static boolean
private static boolean
checkingGlobalDuplicates(boolean allowGlobalDuplicates)

private static void
public static void
cleanHandles(JNI.JNIEnv env)

Processes CLEANERS_QUEUE to release any handles whose objects are now unreachable.

public final JNI.JObject
pack-priv static int

Returns:

the number of objects in the list
invalidate
(HSObject head)

Invalidates the objects in the list starting at head such that subsequently calling getHandle() on any of the objects results in an IllegalArgumentException.

public final void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cleanerback to summary
private final HSObject.Cleaner cleaner

Cleaner for Global Reference.

CLEANERSback to summary
private static final Set<HSObject.Cleaner> CLEANERS

Strong references to the PhantomReference objects.

CLEANERS_QUEUEback to summary
private static final ReferenceQueue<HSObject> CLEANERS_QUEUE

Queue into which a Cleaner is enqueued when its HSObject referent becomes unreachable.

handleback to summary
private final JNI.JObject handle

JNI handle to the HotSpot object.

nextback to summary
private HSObject next

Link to next the next scope local object. The head of the list is in JNIMethodScope#locals. The handle of a scope local object is only valid for the lifetime of a JNIMethodScope. A self-reference (i.e. this.next == this) denotes an object whose JNIMethodScope has closed. This field is null for a non-scope local object.

Constructor Detail

HSObjectback to summary
public HSObject(JNI.JNIEnv env, JNI.JObject handle)

Creates an object encapsulating a handle whose lifetime is determined by this object. The created HSObject uses a JNI global reference and does not allow duplicate JNI references. Use HSObject(JNIEnv, JObject, boolean, boolean) to create HSObject using a JNI weak reference or allowing duplicate JNI references.

HSObjectback to summary
public HSObject(JNI.JNIEnv env, JNI.JObject handle, boolean allowGlobalDuplicates, boolean weak)

Creates an object encapsulating a handle whose lifetime is determined by this object. The created HSObject possibly allows duplicate JNI global handles.

HSObjectback to summary
public HSObject(JNIMethodScope scope, JNI.JObject handle)

Creates an object encapsulating a handle whose lifetime is limited to scope. Once scope.close() is called, any attempt to use the handle will result in an IllegalArgumentException.

Method Detail

assertionsEnabledback to summary
private static boolean assertionsEnabled()
checkingGlobalDuplicatesback to summary
private static boolean checkingGlobalDuplicates(boolean allowGlobalDuplicates)
checkNonExistingGlobalReferenceback to summary
private static void checkNonExistingGlobalReference(JNI.JNIEnv env, JNI.JObject handle)
cleanHandlesback to summary
public static void cleanHandles(JNI.JNIEnv env)

Processes CLEANERS_QUEUE to release any handles whose objects are now unreachable.

getHandleback to summary
public final JNI.JObject getHandle()
invalidateback to summary
pack-priv static int invalidate(HSObject head)

Invalidates the objects in the list starting at head such that subsequently calling getHandle() on any of the objects results in an IllegalArgumentException.

Returns:int

the number of objects in the list

releaseback to summary
public final void release(JNI.JNIEnv env)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.graalvm.jniutils back to summary

private final Class HSObject.Cleaner

extends PhantomReference<HSObject>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final boolean
private JNI.JObject
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Cleaner(HSObject referent, JNI.JObject handle, boolean allowGlobalDuplicates, boolean weak)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
private void
Inherited from java.lang.ref.PhantomReference:
get

Field Detail

allowGlobalDuplicatesback to summary
private final boolean allowGlobalDuplicates
handleback to summary
private JNI.JObject handle
weakback to summary
private final boolean weak

Constructor Detail

Cleanerback to summary
pack-priv Cleaner(HSObject referent, JNI.JObject handle, boolean allowGlobalDuplicates, boolean weak)

Method Detail

cleanback to summary
pack-priv void clean(JNI.JNIEnv env)
deleteback to summary
private void delete(JNI.JNIEnv env)