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

Kim Barrett kim.barrett at oracle.com
Thu Oct 8 07:54:26 UTC 2020


> On Oct 5, 2020, at 8:22 PM, Mandy Chung <mchung at openjdk.java.net> wrote:
> 
> Can you add a unit test in `test/jdk/java/lang/ref` that serves as a basic API test for this new `refersTo` API without
> depending the WhiteBox API?     test/hotspot/jtreg/gc` test serves as a more white-boxed type and comprehensive test.

Adding test/jdk/java/lang/ref/ReferenceRefersTo.java

> src/java.base/share/classes/java/lang/ref/Reference.java line 361:
> 
>> 359:
>> 360:     /* Type-erased implementation of refersTo(). */
>> 361:     native boolean refersTo0(Object o);
> 
> Is there any reason why it can't use the parameter type like `refersTo0(T o)`?  Same for `PhantomReference::refersTo0(T
> o)`

I incorrectly assumed there would be a problem with determining the type of
the C function that implements the native method, but it seems the type
parameter gets erased to Object automatically.  So the signature taking
Object is really just truth in advertising, whereas using the parameterized
type is kind of lying (even more so than is usual for Java generics).  There
is also Daniel's question to consider.  So I haven't made any change here
yet.

> src/hotspot/share/include/jvm.h line 334:
> 
>> 332:  */
>> 333: JNIEXPORT jboolean JNICALL
>> 334: JVM_PhantomReferenceRefersTo(JNIEnv *env, jobject ref, jobject o);
> 
> Instead of a separate `PhantomReference::refersTo0` native method (and new PhantomReference.c), an alternative approach
> could be to detect if `ref` is an instance of `PhantomReference`  or other `Reference` and get the referent accordingly.

See response to Roger's question about refersTo0.



More information about the core-libs-dev mailing list