Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6493567

(ref) Add a java.lang.ref.ExclusiveStrongReference class

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      It would be useful to have a type of Reference that can be enqueued when the garbage collector determines that that particular reference is the only remaining strong reference to the object. Note that this semantics would be a little bit different than that for Soft or Weak references. The proposed reference type could only be enqueued if it is the *only* reference to the object (as opposed to only reachable through *any* "ExclusiveStrongReference"). e.g., if one were to do the following:

      Obj referent = new Object();
      Reference ref = new ExclusiveStrongReference(referent, queue);

      Then "ref" would only get enqueued on "queue" when the garbage collector determines that no other "normal" strong references or ExclusiveStrongReferences can reach the referent.

      JUSTIFICATION :
      This guarantees the opportunity to robustly perform cleanup on objects that may escape to untrusted code. Soft, Weak, and Phantom references do not allow access to their referent once they have been posted to the queue, so it is impossible to perform any cleanup on, or capture of information from, the state of the referent itself. In other words they can only be used for entirely disposable referents, or cleanup of non-referent resources associated with the referent.

      The availability of the proposed class would fill a gap in the ability to obtain useful information from the already standard behavior of the garbage collector. Used properly, this could function as a highly useful replacement for the unreliable (un-guaranteed), and therefore close to useless, finalization mechanism.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The ability to create a reference that will be enqueued when the garbage collector determines that the reference is exclusively accessible through that reference, and which provides access to the referent.

      The garbage collector will of course not be attempting to reclaim the object -- that will only be possible on a subsequent GC cycle if the reference is then cleared, eliminating all strong references. As this is roughly the complement of the process of determining weakly/softly/phantom reachable objects, it should be reasonable to implement.

      Note: It might also be possible to integrate this with existing RFE's for a basic StrongReference class, for which I believe there is a legitimate consistency justification.
      ACTUAL -
      For any given object, there is currently no way to determine when no other strong references exist to that object, while still retaining access to the object.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              tyao Ting-Yun Ingrid Yao (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: