Skip to content

Commit

Permalink
8271862: C2 intrinsic for Reference.refersTo() is often not used
Browse files Browse the repository at this point in the history
Backport-of: 3f723ca4577b9cffeb6153ee386edd75f1dfb1c6
  • Loading branch information
shipilev committed Sep 20, 2021
1 parent 92ff652 commit bf788ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/java.base/share/classes/java/lang/ref/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit bf788ee

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.