mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8329597: C2: Intrinsify Reference.clear
Reviewed-by: rcastanedalo, eosterlund, kvn
This commit is contained in:
parent
1cc32237ae
commit
7625b29920
26 changed files with 362 additions and 21 deletions
|
@ -77,6 +77,19 @@ public non-sealed class PhantomReference<T> extends Reference<T> {
|
|||
@IntrinsicCandidate
|
||||
private native boolean refersTo0(Object o);
|
||||
|
||||
/* Override the implementation of Reference.clear.
|
||||
* Phantom references are weaker than finalization, so the referent
|
||||
* access needs to be handled differently for garbage collectors that
|
||||
* do reference processing concurrently.
|
||||
*/
|
||||
@Override
|
||||
void clearImpl() {
|
||||
clear0();
|
||||
}
|
||||
|
||||
@IntrinsicCandidate
|
||||
private native void clear0();
|
||||
|
||||
/**
|
||||
* Creates a new phantom reference that refers to the given object and
|
||||
* is registered with the given queue.
|
||||
|
|
|
@ -403,13 +403,23 @@ public abstract sealed class Reference<T>
|
|||
* necessary.
|
||||
*/
|
||||
public void clear() {
|
||||
clearImpl();
|
||||
}
|
||||
|
||||
/* Implementation of clear(). A simple assignment of the referent field
|
||||
* won't do for some garbage collectors. There is the override for phantom
|
||||
* references, which requires different semantics. This method is also
|
||||
* used by enqueue().
|
||||
*
|
||||
* <p>This method exists only to avoid making clear0() virtual. Making
|
||||
* clear0() virtual has the undesirable effect of C2 often preferring
|
||||
* to call the native implementation over the intrinsic.
|
||||
*/
|
||||
void clearImpl() {
|
||||
clear0();
|
||||
}
|
||||
|
||||
/* Implementation of clear(), also used by enqueue(). A simple
|
||||
* assignment of the referent field won't do for some garbage
|
||||
* collectors.
|
||||
*/
|
||||
@IntrinsicCandidate
|
||||
private native void clear0();
|
||||
|
||||
/* -- Operations on inactive FinalReferences -- */
|
||||
|
@ -511,7 +521,7 @@ public abstract sealed class Reference<T>
|
|||
* it was not registered with a queue when it was created
|
||||
*/
|
||||
public boolean enqueue() {
|
||||
clear0(); // Intentionally clear0() rather than clear()
|
||||
clearImpl(); // Intentionally clearImpl() to dispatch to overridden method, if needed
|
||||
return this.queue.enqueue(this);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue