Integrated: 8188055: (ref) Add Reference::refersTo predicate

Kim Barrett kbarrett at
Wed Nov 4 09:23:00 UTC 2020

On Sun, 4 Oct 2020 03:59:59 GMT, Kim Barrett <kbarrett at> wrote:

> Finally returning to this review that was started in April 2020.  I've
> recast it as a github PR.  I think the security concern raised by Gil
> has been adequately answered.
> Please review a new function: java.lang.ref.Reference.refersTo.
> This function is needed to test the referent of a Reference object without
> artificially extending the lifetime of the referent object, as may happen
> when calling Reference.get.  Some garbage collectors require extending the
> lifetime of a weak referent when accessed, in order to maintain collector
> invariants.  Lifetime extension may occur with any collector when the
> Reference is a SoftReference, as calling get indicates recent access.  This
> new function also allows testing the referent of a PhantomReference, which
> can't be accessed by calling get.
> The new function uses native methods whose implementations are in the VM so
> they can use the Access API.  It is the intent that these methods will be
> intrinsified by optimizing compilers like C2 or graal, but that hasn't been
> implemented yet.  Bear that in mind before rushing off to change existing
> uses of Reference.get.
> There are two native methods involved, one in Reference and an override in
> PhantomReference, both package private in java.lang.ref. The reason for this
> split is to simplify the intrinsification. This is a change from the version
> from April 2020; that version had a single native method in Reference,
> implemented using the ON_UNKNOWN_OOP_REF Access reference strength category.
> However, adding support for that category in the compilers adds significant
> implementation effort and complexity. Splitting avoids that complexity.
> Testing:
> mach5 tier1
> Locally (linux-x64) verified the new test passes with various garbage collectors.

This pull request has now been integrated.

Changeset: 6023f6b1
Author:    Kim Barrett <kbarrett at>
Stats:     501 lines in 13 files changed: 488 ins; 0 del; 13 mod

8188055: (ref) Add Reference::refersTo predicate

Reviewed-by: mchung, pliden, rriggs, dholmes, ihse, smarks, alanb



More information about the hotspot-gc-dev mailing list