JDK-8286742 : Ensure Cleaner.Cleanable instance is not reclaimed until cleaning is complete
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2022-05-13
  • Updated: 2022-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
The java.lang.ref.Cleaner maintains Cleaner.Cleanable, a subclass of PhantomReference referring to an object and the corresponding cleaning function.
The Cleanable instances are visible to and retained by clients of the Cleaner.
It should be possible to observe the existence of the Cleanable to know whether the cleaning function has yet to be performed.

A race condition may exist in the processing of the Cleanable when it is removed from the ReferenceQueue that might indicate the cleaning function has been completed, while it is still in progress.

The race is between the garbage collector and the CleanerImpl.
After the reference to the Cleanable is removed from the ReferenceQueue, the cleaning function is invoked. The garbage collector may determine that the Cleanable itself is no longer referenced (except perhaps by another Weak/Soft/ or PhantomReference) and reclaim it.

jdk.internal.ref.CleanerImpl:144 should be a call to ReachabilityFence(ref) to keep it alive until the call to the cleaning function returns.