[9] RFR (XS): 8169000: Define reference reachability more precisely in java.lang.ref package
Peter Levart
peter.levart at gmail.com
Fri Nov 11 15:33:21 UTC 2016
Hi Zoltan,
On 11/11/2016 10:25 AM, Zoltán Majó wrote:
> Hi,
>
>
> please review the fix for 8169000:
>
> https://bugs.openjdk.java.net/browse/JDK-8169000
> http://cr.openjdk.java.net/~zmajo/8169000/webrev.00/
>
> The bug was filed because different behavior of interpreted and
> compiled code in HotSpot was observed (different behavior with respect
> to phantom references). After discussions with Maurizio C, Alex B,
> and David H, the best way to address this problem seems to be to
> update update the documentation of the java.lang.ref to avoid
> confusion in the future. David's comment in the bug report [1]
> accurately and concisely summarizes the reasons for the suggested
> patch. For more details please feel free to look at the comments in
> the bug report.
>
> Thank you!
>
> Best regards,
>
>
> Zoltan
>
> [1]
> https://bugs.openjdk.java.net/browse/JDK-8169000?focusedCommentId=14021250&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14021250
>
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.
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
More information about the core-libs-dev
mailing list