RFR: 8293207: Add assert to JVM_ReferenceRefersTo to clarify its API
Kim Barrett
kbarrett at openjdk.org
Fri Sep 2 00:24:42 UTC 2022
On Thu, 1 Sep 2022 10:47:50 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
> JVM_ReferenceRefersTo should only be used for soft/weak references and not phantom references, which has its own implementation. This is not clear from the name. `java_lang_ref_Reference::weak_referent_no_keepalive(ref_oop)` is only a valid call if `!java_lang_ref_Reference::is_phantom(ref_oop)`.
>
> Adds an assert and comment to make this clear.
>
> Testing: Oracle platforms tier 1-3
src/hotspot/share/prims/jvm.cpp line 3286:
> 3284: oop ref_oop = JNIHandles::resolve_non_null(ref);
> 3285: // PhantomReference has it's own implementation of refersTo().
> 3286: assert(!java_lang_ref_Reference::is_phantom(ref_oop), "precondition");
Maybe instead assertions should be added to the java_lang_ref_Reference functions for accessing the referent? (weak_referent_no_keepalive, weak_referent, phantom_referent_no_keepalive)
-------------
PR: https://git.openjdk.org/jdk/pull/10117
More information about the hotspot-dev
mailing list