-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8351458: (ch) Move preClose to UnixDispatcher #23956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -27,13 +27,16 @@ | |
|
||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import jdk.internal.access.JavaIOFileDescriptorAccess; | ||
import jdk.internal.access.SharedSecrets; | ||
|
||
/** | ||
* Allows different platforms to call different native methods | ||
* for read and write operations. | ||
*/ | ||
|
||
abstract class NativeDispatcher { | ||
private static final JavaIOFileDescriptorAccess JIOFDA = SharedSecrets.getJavaIOFileDescriptorAccess(); | ||
|
||
abstract int read(FileDescriptor fd, long address, int len) | ||
throws IOException; | ||
|
@@ -69,11 +72,28 @@ abstract long writev(FileDescriptor fd, long address, int len) | |
|
||
abstract void close(FileDescriptor fd) throws IOException; | ||
|
||
// Prepare the given fd for closing by duping it to a known internal fd | ||
// that's already closed. This is necessary on some operating systems | ||
// (Solaris and Linux) to prevent fd recycling. | ||
// | ||
void preClose(FileDescriptor fd) throws IOException { | ||
/** | ||
* Prepare the given file descriptor for closing. If a virtual thread is blocked | ||
* on the file descriptor then it is unparked so that it stops polling. On Unix systems, | ||
* if a platform thread is blocked on the file descriptor then the file descriptor is | ||
* dup'ed to a special fd and the thread signalled so that the syscall fails with EINTR. | ||
*/ | ||
final void preClose(FileDescriptor fd, long reader, long writer) throws IOException { | ||
if (NativeThread.isVirtualThread(reader) || NativeThread.isVirtualThread(writer)) { | ||
int fdVal = JIOFDA.get(fd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello Alan, previously, in the case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was the |
||
Poller.stopPoll(fdVal); | ||
} | ||
if (NativeThread.isNativeThread(reader) || NativeThread.isNativeThread(writer)) { | ||
implPreClose(fd, reader, writer); | ||
} | ||
} | ||
|
||
/** | ||
* This method does nothing by default. On Unix systems the file descriptor is dup'ed | ||
* to a special fd and native threads signalled. | ||
*/ | ||
|
||
void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException { | ||
// Do nothing by default; this is only needed on Unix | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There used to be a
if (reader != 0 || writer != 0) {...}
check before doing any of this pre-close work, inDatagramChannelImpl
. Is that no longer needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of
NativeThread.isNativeThread()
andNativeThread.isVirtualThread()
, it already implicitly takes into account the!= 0
check, so I guess the previous explicit checks before calling those methods was redundant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, there are a several places where check for != 0 would be redundant.