Hi Zoltan,

On 11/14/2016 03:28 PM, Zoltán Majó wrote:
Hi Peter,


On 11/11/2016 04:33 PM, Peter Levart wrote:
[...]
I think the wording could be even less specific about "detecting" the reachability of the reference object. For example:

... If a registered reference becomes unreachable itself, then it *may* never be enqueued.


In addition, the situations that describe when the reference *may* not be enqueued could be expanded. For example:

... If a registered reference ceases to be strongly reachable itself, then it *may* never be enqueued.


thank you for the suggestion and for the example program!

Here is the updated webrev with the updated text:

http://cr.openjdk.java.net/~zmajo/8169000/webrev.01/

Does that look reasonable to you?

Yes, I think this is good. Maybe just a nit. This last statement:

"It is the responsibility of the program using reference objects to ensure that the objects remain strongly reachable for as long as the program is interested in their referents."

...could be written more nicely like:

"It is the responsibility of the program to ensure that reference objects remain strongly reachable for as long as it is interested in their referents."

...or even:

"It is the responsibility of the program to ensure that reference objects remain strongly reachable for as long as it is interested in tracking the reachability of their referents."


What do you think?


Regards, Peter


Thank you!

Best regards,


Zoltan


The following modified test shows this situation:


public class WeaklyReachablePhantomReference {

    static ReferenceQueue<Object> rq = new ReferenceQueue<>();
    static WeakReference<PhantomReference<Object>> weakRefRef;

    public static void main(final String[] args) throws Exception {
        weakRefRef = new WeakReference<>(
            new PhantomReference<>(
                new Object(),
                rq
            )
        );
        // <- here
        System.gc();
        Reference rmRef = rq.remove(1000);
        if (rmRef == null) {
            System.out.println("PhantomReference NOT enqueued");
        } else {
            System.out.println("PhantomReference enqueued");
        }
    }
}


At "<-- here" the PhantomReference object becomes weakly reachable while its referent becomes phantom reachable and this is enough for PhantomReference to not be enqueued.


Regards, Peter



Reply via email to