Suggested fix for JDK-4724038 (Add unmap method to MappedByteBuffer)

Andrew Haley aph at
Tue Sep 8 17:40:55 UTC 2015

On 09/08/2015 06:03 PM, David M. Lloyd wrote:
> On 09/08/2015 08:11 AM, Andrew Haley wrote:
>> On 09/08/2015 12:37 PM, David M. Lloyd wrote:
>>> Then you do the real unmap when
>>> the buffer is GC'd (maybe via Cleaner).  This is very akin to how file
>>> descriptors are cleaned up, AFAICT.
>> Indeed it is, and it's no better than the status quo.  This is an attempt
>> to do better.
> Actually it *is* better, as it releases the mapping to the underlying 
> file, and does not require any resources (outside of the page table 
> itself and any associated kernel bookkeeping) to maintain a valid state 
> during the time window between user-driven unmap and automatic GC.  The 
> underlying file can (for example) immediately relinquish reserved disk 
> storage or RAM at unmap time (the desired effect), rather than waiting 
> for GC to come around (status quo).
> I believe that reclaiming the reserved address space is of much less 
> importance than freeing the backing resources (especially for 64-bit 
> systems), which is why I suggest this approach.

I think you may be assuming rather a lot about the way that the
underlying OS actually works.  The bug report mentions race conditions
when remapping, and not every OS has nice UNIXy semantics.  Hence my
proposal, which might be portable to other OSs.


More information about the core-libs-dev mailing list