JDK-8291867 : Cleaner has reachabilityFence in wrong place
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2022-08-03
  • Updated: 2022-08-05
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 :  
Relates :  
Relates :  
Description
During the review of java.lang.ref.Cleaner it was recognized that reachabilityFence was needed to ensure the referent and the cleaner remained live beyond certain operations.  A temporary workaround was put in place and later replaced with reachabilityFence once it became available (JDK-8145459).  Unfortunately, I think that was done in the wrong place.

The reachabilityFences are at the end of the PhantomCleanable constructor.  However, this could permit the cleanup to be triggered before the later assignment of CleanerImpl.PhantomCleanableRef's action field. (This is the same kind of problem as discussed in JDK-8149610.) The fences need to follow that assignment, either at the end of PhantomCleanableRef's constructor or at the end of Cleaner.register.