Mark Thornton wrote:
> One of my pet RFE's is 4724038 "(fs) Add unmap method to
> MappedByteBuffer". This is currently in fifth place on the RFE voting
> list.
> While I understand the problems with unmapping a specific buffer, the
> suggestion in several of the comments to that RFE for a method to
> force unmapping of unreachable buffers seems feasible. Especially
> given the fix to 6417205 (fc) "Out of address space because mapped
> ByteBuffers are not freed".
> For my own needs, it would be no problem to ensure that any buffers,
> that I wanted unmapped, were unreachable. Possibly the specification
> may only promise to make a "best effort" to unmap as many buffers as
> possible.
> Regards,
> Mark Thornton
It was inevitable that someone would bring up this topic :-) From your
mail it seems you have a good appreciation of the issues as to why
there isn't an unmap method. The suggestion for a "big hammer" to
initiate reference discovery so that unreachable buffers are unmapped is
something that we have looked into. To some extent you can do this
yourself by invoking the GC and this this will cause unreachable
buffers to be unmapped some time after. If you have a weak reference to
the buffer then it will be cleared and enqueued when the buffer becomes
finalizable. That may be good enough for some environments where you are
willing to take the performance hit. If your motive is to do some post
unmap clean-up (such as removing the file) then there is a timing issue
in that the buffer is unmapped after it becomes finalizable. One the
prototypes we did in this area provided a notification when the region
was unmapped and that could be useful for such cases. However it doesn't
address all requirements - for example it would be too expensive for
cases where you need to resize or you are sliding an aperture through a
huge file. For the later we have looked into supporting remapping but
the inability of some operating systems to support remapping as an
atomic operation means the solution isn't feasible everywhere. The fix
for 6417205 that you mention isn't pretty and essentially just invokes
the GC when there is insufficient memory to map the new region. In any
case, I'm interested to hear about your environment and if you would be
willing to take a hit to ensure that all unreachable buffers are unmapped.
-Alan.