Hi Roger,

I now think that this is the right move. The simplified API is really only useful for PhantomReference(s). Since Cleaner.Cleanable interface does not provide access to the referent, it would be tempting for users to do two things at once for the same referent with Weak or Soft reachability:

- register cleanup function with: Cleaner.registerWeak(referent, () -> ...); and - wrap the referent with: WeakReference<Referent> wr = new WeakReference<>(referent);

...to get both features: obtainable referent and automatically managed cleanup.

This would of course work, but would not be very efficient. In Phantom-only world, they will not be tempted to do such thing.

Regards, Peter

On 12/02/2015 09:23 PM, Roger Riggs wrote:
Please review the java.lang.ref.Cleaner and tests following the recommendation to simplify the public
interface to support only phantom cleanup.

Webrev:
  http://cr.openjdk.java.net/~rriggs/webrev-cleaner-8138696/

Javadoc:
   http://cr.openjdk.java.net/~rriggs/cleaner-doc/index.html

Thanks, Roger


On 11/23/2015 5:32 PM, mark.reinh...@oracle.com wrote:
( Finally getting back to this, after too many weeks of travel ... )

2015/10/20 11:28 -0700, roger.ri...@oracle.com:
Sorry for the silence, JavaOne preparations and the availability of
folks who wanted to review have stretched things out.

The Cleaner API was very simple and saw feature creep as the ideas for
how it might be used were explored.  There are concerns about
committing to supporting subclassable CleanableReferences in all
future JDK versions before there had been a chance to see how if they
would be useful and necessary to address the need to reduce the use of
finalization within the OpenJDK and beyond.

...

Updated Javadoc:
    http://cr.openjdk.java.net/~rriggs/cleaner-doc/

Updated Webrev:
http://cr.openjdk.java.net/~rriggs/webrev-cleaner-8138696/
I'm very happy to see this API return to something like its original
simple form, but I think it can be simplified even further.

We have a very strong need for phantom-ref-based cleaners, so as to
discourage people from relying upon flaky finalization. The arguments in
support of the weak and soft forms have, by contrast, been rather weak
(and soft?).  I don't think it's right to bake methods into a core API
based on just a couple of hypothetical use cases.  I'd much rather see
the Cleaner::{phantom,soft,weak}Cleanable methods reduced to a single
register method,

     Cleaner.Cleanable register(Object, Runnable);

which would create the phantom form only.  If strong justification for
the other forms arise then we can generalize this later, either to
distinct register{Soft,Weak} methods or, perhaps, to a method that takes
a type token.

- Mark


Reply via email to