RFR: 8188055: (ref) Add Reference.refersTo predicate

Paul Sandoz paul.sandoz at oracle.com
Thu Apr 9 15:31:18 UTC 2020


Reference.java
—

 335      *
 336      * @return   The object to which this reference refers, or
 337      *           {@code null} if this reference object has been cleared

Add @see refersTo

 338      */
 339     @HotSpotIntrinsicCandidate
 340     public T get() {

Paul.

> On Apr 7, 2020, at 5:25 PM, Kim Barrett <kim.barrett at oracle.com> wrote:
> 
> [Note review on both core-libs and hotspot-gc-dev lists; try not to lose
> either when replying.]
> 
> 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 a native method whose implementation is in the
> VM so it can use the Access API.  It is the intent that this function
> 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.
> 
> CR:
> https://bugs.openjdk.java.net/browse/JDK-8188055
> https://bugs.openjdk.java.net/browse/JDK-8241029 (CSR)
> 
> Webrev:
> https://cr.openjdk.java.net/~kbarrett/8188055/open.04/
> 
> Testing:
> mach5 tier1
> 
> Locally (linux-x64) verified the new test passes with various garbage
> collectors. 
> 



More information about the core-libs-dev mailing list