RFR: 8351458: (ch) Move preClose to UnixDispatcher

Jaikiran Pai jpai at openjdk.org
Tue Mar 11 08:16:56 UTC 2025


On Tue, 11 Mar 2025 07:31:05 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/sun/nio/ch/NativeDispatcher.java line 83:
>> 
>>> 81:     final void preClose(FileDescriptor fd, long reader, long writer) throws IOException {
>>> 82:         if (NativeThread.isVirtualThread(reader) || NativeThread.isVirtualThread(writer)) {
>>> 83:             int fdVal = JIOFDA.get(fd);
>> 
>> Hello Alan, previously, in the case of `DatagramChannelImpl`, the `fdVal` was a `final` that was determined when the channel was constructed. Now, that `fdVal` gets determined as and when needed and I see that `FileDescriptor` allows this underlying value to be changed/reset. Is there anything practical to consider here in context of a `fdVal` that has been reset in the `FileDescriptor`?
>
> repairSocket doesn't change fd/fdVal, instead they will be connected to a new socket if the method succeeds (or the old socket if it fails).

It was the `FileDescriptor.set(int fd)` method which I had in mind. But I now looked at its references and I see that there aren't any in the code paths that this PR deals with. So I believe the proposed change looks good.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23956#discussion_r1988653010


More information about the nio-dev mailing list