RFR : 8221696: MappedByteBuffer.force method to specify range

Andrew Dinn adinn at redhat.com
Tue Apr 9 12:37:52 UTC 2019

Hi Daniel,

Thanks for looking at this.

On 09/04/2019 12:28, Daniel Fuchs wrote:
> Hi Andrew,
> On 09/04/2019 11:42, Andrew Dinn wrote:
>> One detail that is worth highlighting is that for file-backed buffers
>> the start address passed to the native method force0 is rounded down to
>> a page boundary. This is needed for Unix implementations to ensure that
>> the underlying msync system call does not throw an exception.
> Maybe this should be highlighted in the API documentation too,
> possibly as a non-normative implementation detail - stating
> that an implementation is free to do this (e.g. in an
> @implNote).
> My reading of your current proposed specification is that
> `from` is
>  234      *        The offset to the first byte in the buffer region that
>  235      *        is to be written back to storage
> and well - if I'm not mistaken then it appears the implementation
> can write some bytes before `from`, and that would be observable
> if you compared the file before and after calling force, isn't it?
There is no implication in the current documentation that a call to
force will /only/ write back bytes in the affected region. However, I
agree that it should be stated explicitly that this may happen.

I am not sure that this needs to be mentioned in an implNote. It is of
the nature of most memory-mapped storage devices that writeback has a
minimum granularity well above byte level. Would you be ok with a
correspondingly general caveat?

For example, what if I changed the second paragraph in the commment to:

     * <p> If the file mapped into this buffer resides on a local
     * storage device then when this method returns it is guaranteed
     * that all changes made to the selected region of the buffer since
     * it was created, or since this method was last invoked, will have
     * been written to that device. The force operation is free to
     * write bytes that lie outside the specified region, for example
     * to ensure that data blocks of some device-specific granularity
     * are transferred in their entirety.


Andrew Dinn
Senior Principal Software Engineer
Red Hat UK Ltd
Registered in England and Wales under Company Registration No. 03798903
Directors: Michael Cunningham, Michael ("Mike") O'Neill, Eric Shander

More information about the core-libs-dev mailing list