8242477: (bf) MappedByteBuffer should clarify copying between overlapping mappings
Paul Sandoz
paul.sandoz at oracle.com
Mon Apr 13 16:51:10 UTC 2020
Ok. I was wondering about the behavior of Unsafe.copySwapMemory.
Buffers have a base + address that should be accessible for all kinds of buffer.
Paul.
> On Apr 13, 2020, at 9:19 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
>
>
>> On Apr 13, 2020, at 9:14 AM, Paul Sandoz <paul.sandoz at oracle.com <mailto:paul.sandoz at oracle.com>> wrote:
>>
>>>>> 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.
>>>
>>> I verified it with a small test.
>>>
>>
>> Is that due to the buffer implementation (in some cases not using the Unsafe mem-copy) rather than mapping two sources at different virtual memory addresses?
>>
>> If so it may be possible to fix it.
>
> The test used two float views, one little endian and one big endian, of the same direct ByteBuffer and did a relative put (ByteBuffer.put(ByteBuffer)) from one into the other. This devolves into the loopy default code more or less as
> while (src.hasRemaining())
> dst.put(src.get());
> Since the two are views there is no IAE although both refer to the same storage. As there is currently no way to check whether these refer eventually to the same storage I don’t think there’s a way to get to using Unsafe.
>
> Brian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200413/68152164/attachment.htm>
More information about the nio-dev
mailing list