@Finalized

Doug Lea dl at cs.oswego.edu
Wed Aug 26 14:01:01 UTC 2015


In the course of JEP 188/193 related efforts, it has been pointed out
a few times that, as part of these efforts, finally adding method 
reachabilityFence(ref) with tentative spec pasted below should be
the first of two steps in helping developers avoid premature finalization
and reclamation. The second part seems to escape scope of these JEPs:
Supporting an annotation (most likely named @Finalized) that would
enable tools and/or compilers to convert methods of classes in
danger of premature finalization from
   { body }
to
   try { body } finally { Reference.reachabilityFence(this); }

And/or some variants, some of which were explored on the
jmm-dev list mainly in August 2014 -- see archives at
http://mail.openjdk.java.net/pipermail/jmm-dev/2014-August/thread.html

This is an issue of large importance to a small audience,
and is at the moment an orphan. To work out, I think it
requires at least some involvement from compiler and/or IDE
developers. If you are or know of someone who might be interested
in pursuing, please encourage them/yourself to consider it.

-Doug



class java.lang.ref.Reference {
     // add:

     /**
      * Ensures that the object referenced by the given reference
      * remains <em>strongly reachable</em> (as defined in the {@link
      * java.lang.ref} package documentation), regardless of any prior
      * actions of the program that might otherwise cause the object to
      * become unreachable. A reachabilityFence for a given reference
      * happens before the referenced object is reclaimed by garbage
      * collection, finalized, or added to a java.lang.ref queue.
      * Invocation of this method does not itself initiate garbage
      * collection or finalization.
      *
      * @param ref the reference. If null, this method has no effect.
      */
     public static void reachabilityFence(Object ref) {}

}




More information about the core-libs-dev mailing list