RFR: 8358537: (bf) JavaNioAccess::getBufferAddress bypasses direct buffer MemorySession state check

Jorn Vernee jvernee at openjdk.org
Wed Jun 4 00:00:17 UTC 2025


On Tue, 3 Jun 2025 22:32:37 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> test/jdk/java/nio/channels/etc/MemorySegments.java line 61:
>> 
>>> 59:      */
>>> 60:     static Stream<Supplier<Arena>> arenaSuppliers() {
>>> 61:         return Stream.of(Arena::global, Arena::ofAuto, Arena::ofConfined);
>> 
>> Why is using a shared arena causing the UOE to be thrown? I'd think that would be triggered by the use of heap buffers, but shared arena is for off-heap memory.
>
> I thin it's running into this method in DirectBufferX:
> 
>     public long address() {
>         MemorySessionImpl session = session();
>         if (session != null) {
>             if (session.ownerThread() == null && session.isCloseable()) {
>                 throw new UnsupportedOperationException("ByteBuffer derived from closeable shared sessions not supported");
>             }

Oh, I see. IIRC this is why the shared secrets are bypassing the `address()` method. For shared arenas the caller is supposed to do an acquire/release, and then use shared secrets to get the buffer address, bypassing this check.

@minborg recently did some work to change over uses of `DirectBuffer::address` in https://github.com/openjdk/jdk/pull/25324 and https://github.com/openjdk/jdk/pull/25321

If ByteBuffers derived from segments with shared arenas no longer work with this patch, that seems like a regression to me.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25631#discussion_r2125140322


More information about the nio-dev mailing list