Small cleanup/improvement to epoll creation
Thomas Stüfe
thomas.stuefe at gmail.com
Wed Apr 8 04:46:17 UTC 2020
Looks good to me too.
Thanks, Thomas
On Tue, Apr 7, 2020 at 10:41 PM David Lloyd <david.lloyd at redhat.com> wrote:
> On Tue, Apr 7, 2020 at 2:27 PM Alan Bateman <Alan.Bateman at oracle.com>
> wrote:
> >
> > On 06/04/2020 17:50, David Lloyd wrote:
> > > Since glibc 2.9 (released at the end of 2008), there has been an
> > > improved function for EPoll creation. I would suggest the following
> > > cleanup, which uses the "epoll_create1" function to set the FD to
> > > close-on-exec (which is generally just good practice AFAICT, even if
> > > it's not exactly one that has been universally adopted by OpenJDK thus
> > > far).
> > This looks okay, just need to update the exception message too.
>
> Ah yes, I missed that.
>
> > You are right that we don't use CLOEXEC consistently. The JDK gets away
> due to
> > heroics in Process code to ensure that file descriptors are closed.
>
> I seem to recall quite a lot of discussion on this... heroics is
> exactly the right word :)
>
> diff --git a/src/java.base/linux/native/libnio/ch/EPoll.c
> b/src/java.base/linux/native/libnio/ch/EPoll.c
> index 2100de5f215..f41fb49c405 100644
> --- a/src/java.base/linux/native/libnio/ch/EPoll.c
> +++ b/src/java.base/linux/native/libnio/ch/EPoll.c
> @@ -57,10 +57,9 @@ Java_sun_nio_ch_EPoll_dataOffset(JNIEnv* env, jclass
> clazz)
>
> JNIEXPORT jint JNICALL
> Java_sun_nio_ch_EPoll_create(JNIEnv *env, jclass clazz) {
> - /* size hint not used in modern kernels */
> - int epfd = epoll_create(256);
> + int epfd = epoll_create1(EPOLL_CLOEXEC);
> if (epfd < 0) {
> - JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed");
> + JNU_ThrowIOExceptionWithLastError(env, "epoll_create1 failed");
> }
> return epfd;
> }
>
>
> --
> - DML
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200408/4dc47ebb/attachment.htm>
More information about the nio-dev
mailing list