RFR: 8357268: Use JavaNioAccess.getBufferAddress rather than DirectBuffer.address() [v7]

Valerie Peng valeriep at openjdk.org
Thu May 22 18:57:52 UTC 2025


On Wed, 21 May 2025 17:55:17 GMT, Valerie Peng <valeriep at openjdk.org> wrote:

>> src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java line 459:
>> 
>>> 457: 
>>> 458:             boolean pending = false;
>>> 459:             NIO_ACCESS.acquireSession(buf);
>> 
>> Here, we acquire the session *after* we have obtained the address. This is safe as we do not touch the segment before it is acquired. If a segment is deallocated before we try to acquire the session, an exception will be thrown.
>
> Is there documentation on when sessions should be acquired/released? Is this only for when using MemorySegment? In security area, the bytes are passed to the JNI code which calls the native library to process the bytes and I wonder if sessions should be acquired/released for these.

Never mind, I see that there are already acquireSession/releaseSession calls when the ByteBuffer objects are accessed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25324#discussion_r2103213937


More information about the nio-dev mailing list