8271862: C2 intrinsic for Reference.refersTo() is often not used

Reviewed-by: kbarrett, mchung
This commit is contained in:
Per Liden 2021-08-11 11:09:59 +00:00
parent abebbe2335
commit 3f723ca457
2 changed files with 14 additions and 3 deletions

View file

@ -69,8 +69,12 @@ public class PhantomReference<T> extends Reference<T> {
* do reference processing concurrently. * do reference processing concurrently.
*/ */
@Override @Override
boolean refersToImpl(T obj) {
return refersTo0(obj);
}
@IntrinsicCandidate @IntrinsicCandidate
native final boolean refersTo0(Object o); private native boolean refersTo0(Object o);
/** /**
* Creates a new phantom reference that refers to the given object and * Creates a new phantom reference that refers to the given object and

View file

@ -363,13 +363,20 @@ public abstract class Reference<T> {
* @since 16 * @since 16
*/ */
public final boolean refersTo(T obj) { public final boolean refersTo(T obj) {
return refersTo0(obj); return refersToImpl(obj);
} }
/* Implementation of refersTo(), overridden for phantom references. /* Implementation of refersTo(), overridden for phantom references.
* This method exists only to avoid making refersTo0() virtual. Making
* refersTo0() virtual has the undesirable effect of C2 often preferring
* to call the native implementation over the intrinsic.
*/ */
boolean refersToImpl(T obj) {
return refersTo0(obj);
}
@IntrinsicCandidate @IntrinsicCandidate
native boolean refersTo0(Object o); private native boolean refersTo0(Object o);
/** /**
* Clears this reference object. Invoking this method will not cause this * Clears this reference object. Invoking this method will not cause this