8242477: (bf) MappedByteBuffer should clarify copying between overlapping mappings
Brian Burkhalter
brian.burkhalter at oracle.com
Thu Apr 23 02:08:24 UTC 2020
> On Apr 13, 2020, at 8:49 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> On 13/04/2020 16:42, Brian Burkhalter wrote:
>>
>>> On Apr 11, 2020, at 4:23 AM, Florian Weimer <fw at deneb.enyo.de <mailto:fw at deneb.enyo.de>> wrote:
>>>
>>> In principle, this also applies to direct buffer created via JNI's
>>> NewDirectByteBuffer. Such direct buffers could alias with each other
>>> or even MappedByteBuffer instances.
>>
>> Indeed. And in an even simpler case, two different views of the same direct buffer could produce unexpected results with a relative bulk put from one into the other.
>>
> Yes, it's a good point. Can you check out whether the statement could be added to the BB "Direct vs. non-direct buffer" sections.
I updated the proposed change to include such a statement which is included below. I’ll update the CSR [1] accordingly if this looks good.
Thanks,
Brian
[1] https://bugs.openjdk.java.net/browse/JDK-8242500
--- a/src/java.base/share/classes/java/nio/MappedByteBuffer.java
+++ b/src/java.base/share/classes/java/nio/MappedByteBuffer.java
@@ -58,6 +58,9 @@
* avoid the manipulation of a mapped file by this program, or by a
* concurrently running program, except to read or write the file's content.
*
+ * <p> The result of a bulk copy between two {@code MappedByteBuffer}s is
+ * unspecified if they are mapped from overlapping regions of the same file.
+ *
* <p> Mapped byte buffers otherwise behave no differently than ordinary direct
* byte buffers. </p>
*
--- a/src/java.base/share/classes/java/nio/X-Buffer.java.template
+++ b/src/java.base/share/classes/java/nio/X-Buffer.java.template
@@ -125,7 +125,9 @@
* instance of one of these kinds of buffers refers to an inaccessible region
* of memory then an attempt to access that region will not change the buffer's
* content and will cause an unspecified exception to be thrown either at the
- * time of the access or at some later time.
+ * time of the access or at some later time. The result of a bulk copy between
+ * two direct buffers created via JNI is unspecified if they refer to
+ * overlapping regions of memory.
*
* <p> Whether a byte buffer is direct or non-direct may be determined by
* invoking its {@link #isDirect isDirect} method. This method is provided so
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200422/c77ea301/attachment.htm>
More information about the nio-dev
mailing list