RFR: 8358958: (aio) AsynchronousByteChannel.read/write should throw IAE if buffer is thread-confined [v3]

Alan Bateman alanb at openjdk.org
Thu Jun 12 06:37:23 UTC 2025


> It's nonsensical to invoke read/write methods defined by the AsynchronousXXX channels with buffers that are views of memory segments allocated from a thread-confined arena.
> 
> For AsynchronousSocketChannel, the current behavior is for the read/write methods to initiate an I/O operation that completes with an IOException and an IllegalStateException as cause. For AsynchronousFileChannel, the current behavior is for the read/write methods to initiate an I/O operation that never completes (a thread in the channel groups terminates with a WrongThreadException).
> 
> The proposal is that the read/write methods reject, with IllegalArgumentException, any attempt to initiate as async I/O operation with a buffer from a thread-confined arena. IAE is already declared to be thrown for read-only buffers or attempting a positional read/write with a negative file position.
> 
> The java/nio/channels/etc/MemorySegments.java test is updated to test AsynchronousSocketChannel and AsynchronousFileChannel with buffers from all arena kinds. The tests include attempts to close a shared arena while an I/O operation is in progress. For now, the testAsyncFileChannelXXX tests are disabled until they meet up with the changes in JDK-8357847 (pr/25531).

Alan Bateman has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:

 - Update copyright header
 - Merge branch 'master' into JDK-8358958
 - Missing update to TestAsyncSocketChannels
 - Merge branch 'master' into JDK-8358958
 - Drop links to problematic operations from asByteBuffer method description
 - Disable testAsyncFileChannelReadWrite on Windows for now
 - Add test for async close of arena
 - Initial commit

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/25691/files
  - new: https://git.openjdk.org/jdk/pull/25691/files/4a66c604..60658f18

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=25691&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=25691&range=01-02

  Stats: 3440 lines in 76 files changed: 1704 ins; 1418 del; 318 mod
  Patch: https://git.openjdk.org/jdk/pull/25691.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/25691/head:pull/25691

PR: https://git.openjdk.org/jdk/pull/25691


More information about the nio-dev mailing list