Skip to content

Commit 96e0261

Browse files
committed
8256106: Bypass intrinsic/barrier when calling Reference.get() from Finalizer
Reviewed-by: eosterlund
1 parent 3c3469b commit 96e0261

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/java.base/share/classes/java/lang/ref/Finalizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void runFinalizer(JavaLangAccess jla) {
8282
}
8383

8484
try {
85-
Object finalizee = this.get();
85+
Object finalizee = this.getInactive();
8686
if (finalizee != null && !(finalizee instanceof java.lang.Enum)) {
8787
jla.invokeFinalize(finalizee);
8888

src/java.base/share/classes/java/lang/ref/Reference.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,20 @@ public T get() {
342342
return this.referent;
343343
}
344344

345+
/**
346+
* Load referent with strong semantics. Treating the referent
347+
* as strong referent is ok when the Reference is inactive,
348+
* because then the referent is switched to strong semantics
349+
* anyway.
350+
*
351+
* This is only used from Finalizer to bypass the intrinsic,
352+
* which might return a null referent, even though it is not
353+
* null, and would subsequently not finalize the referent/finalizee.
354+
*/
355+
T getInactive() {
356+
return this.referent;
357+
}
358+
345359
/**
346360
* Tests if the referent of this reference object is {@code obj}.
347361
* Using a {@code null} {@code obj} returns {@code true} if the

0 commit comments

Comments
 (0)