RFR: 4833719: (bf) Views of MappedByteBuffers are not MappedByteBuffers, and cannot be forced [v4]
Andrew Dinn
adinn at openjdk.java.net
Tue Mar 16 14:30:10 UTC 2021
On Tue, 16 Mar 2021 13:44:57 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> src/java.base/share/classes/java/nio/MappedByteBuffer.java line 377:
>>
>>> 375: * {@code force()} on the returned buffer, will only act on the sub-range
>>> 376: * of this buffer that the returned buffer represents, namely
>>> 377: * {@code [position(),limit()]}.
>>
>> Is the closing bracket on this interval meant to be ']' or ')'? i.e. is the interval inclusive of exclusive of the value at the index returned by limit()?
>
> The no-arg force method used to write back the entire buffer content [0, capacity]. It has been changed to use the limit, meaning [0, limit]. I don't recall this being an intentional change. I'm asking now because the change in this PR will specify the new behavior rather than the long standing behavior.
@AlanBateman Hmm, I think that's a different issue to my comment.
I asked my question above because the correction Brian made when documenting slice(int index, int length) employed a half-closed interval with an exclusive right bound for the interval
[index,index+length)
and I merely felt that the same should apply here in the documentation of slice()
[position(),limit())
I'm not sure I am in a position to provide the right answer to your question but I'll note that in the same pedantic vein the intervals you mention should be similarly semi-closed
[0, capacity)
and
[0, limit)
The byte at index limit/capacity is not necessarily flushed (modulo page roundings).
As to what might be a correct answer:
> The no-arg force method used to write back the entire buffer content [0, capacity]. It has been changed to use the limit, meaning [0, limit]. I don't recall this being an intentional change.
I believe this was done intentionally when I introduced the force(int,int) variant and re-implemented the noargs variant to indirect to it. I cannot recall why it changed from capacity to limit though.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2902
More information about the nio-dev
mailing list