JDK-8199462 : Use Reference.reachabilityFence in direct ByteBuffer methods
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2018-03-12
  • Updated: 2022-07-22
  • Resolved: 2018-03-12
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.
JDK 11
11 b05Fixed
Related Reports
Relates :  
Relates :  
Description
There is a very small risk when using direct ByteBuffer that the buffer instance will be GC'ed and the buffer's memory reclaimed while the memory address is still be used by a buffer method.

This can be fixed by judiciously using Reference.reachabilityFence to keep references alive for the duration of use. Performance reasons held up such use but further analysis has revealed that it is possible to annotate Reference.reachabilityFence with @ForceInline (rather than @DontInline) since the HotSpot compilers currently track the usage scope of variables via bytecode analysis rather than IR analysis.  So even if a compiler performs dead code elimination any eliminated variables will still live beyond their use (in accordance with the bytecode usage). Other non-HotSpot compilers may differ in this behaviour.
Comments
Review thread "[PATCH] Reduce Chance Of Mistakenly Early Backing Memory Cleanup" at: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-February/thread.html#51221 http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-March/thread.html#51863
10-10-2018

URL: http://hg.openjdk.java.net/jdk/jdk/rev/7c795d301dbf User: psandoz Date: 2018-03-12 23:14:45 +0000
12-03-2018