Small cleanup/improvement to epoll creation

David Lloyd david.lloyd at
Mon Apr 6 16:50:48 UTC 2020

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).  It's more useful than passing in an ignored integer at any

Here's the suggested change:

diff --git a/src/java.base/linux/native/libnio/ch/EPoll.c
index 2100de5f215..4959a573e96 100644
--- a/src/java.base/linux/native/libnio/ch/EPoll.c
+++ b/src/java.base/linux/native/libnio/ch/EPoll.c
@@ -57,8 +57,7 @@ Java_sun_nio_ch_EPoll_dataOffset(JNIEnv* env, jclass clazz)

 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");


More information about the nio-dev mailing list