RFR: 8323612: IOVecWrapper should be changed to be TerminatingThreadLocal

Brian Burkhalter bpb at openjdk.org
Tue Jan 16 22:35:49 UTC 2024


On Thu, 11 Jan 2024 19:36:59 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> Scatter/gather ops use a native iovec structure that is cached in a thread-local and registered with a Cleaner so it may be freed sometime after the thread has terminated. The change proposed here is to change it to a TerminatingThreadLocal so that it is freed when the thread terminates. In addition, to allow a virtual thread be preempted while it has a reference to iovec structure, IOVecWrapper.get is changed to "remove" the iovec from the cache, a new release method will re-add it to the cache. The changes mean this cache is consistent with the cache of direct buffers. The original plan was to also change IOVecWrapper but it somehow got forgotten.
> 
> (The changes proposed here have been in the loom repo for some time. In the loom repo, preemption is possible when doing scatter/gather ops where the array of buffers includes heap buffers. More specifically, the iovec is obtained before substitution of heap buffers so it's possible that direct memory is exhausted and the thread has to wait for reference processing.)

Looks okay to me.

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

Marked as reviewed by bpb (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/17379#pullrequestreview-1825459476


More information about the nio-dev mailing list