Class HSObject

java.lang.Object
org.graalvm.jniutils.HSObject

public class HSObject extends Object
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.
  • Constructor Details

    • HSObject

      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.
    • HSObject

      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.
    • HSObject

      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 Details

    • getHandle

      public final JNI.JObject getHandle()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • release

      public final void release(JNI.JNIEnv env)
    • cleanHandles

      public static void cleanHandles(JNI.JNIEnv env)
      Processes CLEANERS_QUEUE to release any handles whose objects are now unreachable.