More APIs based on MemorySegment

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Dec 11 12:59:22 UTC 2023


Hi Glavo,
we do not have plans to update these APIs at the moment. It is possible 
to map a segment into a bytebuffer and then to use existing methods. Of 
course, as you mention, this will suffer from issues if the segment is 
too big to fit in to a buffer, but I guess we'd like to assess how big 
of an issue that is, what kind of workaround would clients need to write 
etc. before doing a blanket sprinkling of MS in the entire JDK.

Looking at your list, concretely:

>  1. X-Buffer::get(int, MemorySegment, long, long)
>  2. X-Buffer::put(int, MemorySegment, long, long)
>  3. ReadableByteChannel::read(MemorySegment, long, long)
>  4. WritableByteChannel::write(MemorySegment, long, long)
>  5. InputStream::read(MemorySegment, long, long)
>  6. OutputStream::write(MemorySegment, long, long)
>  7. Checksum::update(MemorySegment, long, long)
>  8. Deflater::setInput(MemorySegment, long, long)
>  9. Deflater::deflate(MemorySegment, long, long)
> 10. Inflater::setInput(MemorySegment, long, long)
> 11. Inflater::inflate(MemorySegment, long, long)
> 12. Files.readAllBytesToNative(Path): MemorySegment
> 13. Files.write(Path, MemorySegment, OpenOpetion...)
>
It seems like you are conflating two aspects:

* there are some methods that are accepting a ByteBuffer today, so the 
question is whether they should accept a MS in the future (3, 4, 7, 8, 
9, 10, 11)
* there are other methods that are accepting a byte[] today, the 
question is whether we want to enhance them to work on buffer/segments 
(1, 2, 5, 6, 12, 13)

IMHO, the first group has a somewhat higher priority than the second 
(methods in that group don't even work with BB today, is there really a 
demand to have them working with MS?)

And, in the first group, my hunch is that doing 
Readable/WriteableFileChannel will address 80% of the use cases?

Maurizio


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20231211/409bbf20/attachment.htm>


More information about the valhalla-dev mailing list