Skip to content
Permalink
Browse files
8271862: C2 intrinsic for Reference.refersTo() is often not used
Reviewed-by: kbarrett, mchung
  • Loading branch information
pliden committed Aug 11, 2021
1 parent abebbe2 commit 3f723ca4577b9cffeb6153ee386edd75f1dfb1c6
Showing with 14 additions and 3 deletions.
  1. +5 −1 src/java.base/share/classes/java/lang/ref/PhantomReference.java
  2. +9 −2 src/java.base/share/classes/java/lang/ref/Reference.java
@@ -69,8 +69,12 @@ public T get() {
* do reference processing concurrently.
*/
@Override
boolean refersToImpl(T obj) {
return refersTo0(obj);
}

@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
@@ -363,13 +363,20 @@ public T get() {
* @since 16
*/
public final boolean refersTo(T obj) {
return refersTo0(obj);
return refersToImpl(obj);
}

/* 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
native boolean refersTo0(Object o);
private native boolean refersTo0(Object o);

/**
* Clears this reference object. Invoking this method will not cause this

1 comment on commit 3f723ca

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 3f723ca Aug 11, 2021

Please sign in to comment.