7039186: (ch) EPoll based asynchronous I/O implementation should be portable to linux-arm and linux-ppc
authoralanb
Wed, 27 Apr 2011 13:46:22 +0100
changeset 9523 b7c69ba6b563
parent 9522 38e96027251b
child 9525 c10270d770cc
7039186: (ch) EPoll based asynchronous I/O implementation should be portable to linux-arm and linux-ppc Reviewed-by: dholmes
jdk/make/java/nio/mapfile-linux
jdk/src/solaris/classes/sun/nio/ch/EPoll.java
jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java
jdk/src/solaris/native/sun/nio/ch/EPoll.c
jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c
--- a/jdk/make/java/nio/mapfile-linux	Wed Apr 27 17:11:06 2011 +0800
+++ b/jdk/make/java/nio/mapfile-linux	Wed Apr 27 13:46:22 2011 +0100
@@ -44,7 +44,6 @@
 		Java_sun_nio_ch_EPollArrayWrapper_interrupt;
 		Java_sun_nio_ch_EPollArrayWrapper_offsetofData;
 		Java_sun_nio_ch_EPollArrayWrapper_sizeofEPollEvent;
-		Java_sun_nio_ch_EPoll_init;
 		Java_sun_nio_ch_EPoll_eventSize;
 		Java_sun_nio_ch_EPoll_eventsOffset;
 		Java_sun_nio_ch_EPoll_dataOffset;
@@ -129,7 +128,6 @@
 		Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio;
 		Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs;
 		Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs;
-		Java_sun_nio_fs_LinuxWatchService_init;
 		Java_sun_nio_fs_LinuxWatchService_eventSize;
 		Java_sun_nio_fs_LinuxWatchService_eventOffsets;
 		Java_sun_nio_fs_LinuxWatchService_inotifyInit;
--- a/jdk/src/solaris/classes/sun/nio/ch/EPoll.java	Wed Apr 27 17:11:06 2011 +0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPoll.java	Wed Apr 27 13:46:22 2011 +0100
@@ -99,8 +99,6 @@
 
     // -- Native methods --
 
-    private static native void init();
-
     private static native int eventSize();
 
     private static native int eventsOffset();
@@ -116,6 +114,5 @@
 
     static {
         Util.load();
-        init();
     }
 }
--- a/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java	Wed Apr 27 17:11:06 2011 +0800
+++ b/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java	Wed Apr 27 13:46:22 2011 +0100
@@ -432,8 +432,6 @@
 
     // -- native methods --
 
-    private static native void init();
-
     // sizeof inotify_event
     private static native int eventSize();
 
@@ -461,6 +459,5 @@
                 System.loadLibrary("nio");
                 return null;
         }});
-        init();
     }
 }
--- a/jdk/src/solaris/native/sun/nio/ch/EPoll.c	Wed Apr 27 17:11:06 2011 +0800
+++ b/jdk/src/solaris/native/sun/nio/ch/EPoll.c	Wed Apr 27 13:46:22 2011 +0100
@@ -34,55 +34,7 @@
 #include <dlfcn.h>
 #include <unistd.h>
 #include <sys/types.h>
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* epoll_wait(2) man page */
-
-typedef union epoll_data {
-    void *ptr;
-    int fd;
-    __uint32_t u32;
-    __uint64_t u64;
-} epoll_data_t;
-
-struct epoll_event {
-    __uint32_t events;  /* Epoll events */
-    epoll_data_t data;  /* User data variable */
-} __attribute__ ((__packed__));
-
-#ifdef  __cplusplus
-}
-#endif
-
-/*
- * epoll event notification is new in 2.6 kernel. As the offical build
- * platform for the JDK is on a 2.4-based distribution then we must
- * obtain the addresses of the epoll functions dynamically.
- */
-typedef int (*epoll_create_t)(int size);
-typedef int (*epoll_ctl_t)   (int epfd, int op, int fd, struct epoll_event *event);
-typedef int (*epoll_wait_t)  (int epfd, struct epoll_event *events, int maxevents, int timeout);
-
-static epoll_create_t epoll_create_func;
-static epoll_ctl_t    epoll_ctl_func;
-static epoll_wait_t   epoll_wait_func;
-
-
-JNIEXPORT void JNICALL
-Java_sun_nio_ch_EPoll_init(JNIEnv *env, jclass this)
-{
-    epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create");
-    epoll_ctl_func    = (epoll_ctl_t)    dlsym(RTLD_DEFAULT, "epoll_ctl");
-    epoll_wait_func   = (epoll_wait_t)   dlsym(RTLD_DEFAULT, "epoll_wait");
-
-    if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) ||
-        (epoll_wait_func == NULL)) {
-        JNU_ThrowInternalError(env, "unable to get address of epoll functions, pre-2.6 kernel?");
-    }
-}
+#include <sys/epoll.h>
 
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_EPoll_eventSize(JNIEnv* env, jclass this)
@@ -108,7 +60,7 @@
      * epoll_create expects a size as a hint to the kernel about how to
      * dimension internal structures. We can't predict the size in advance.
      */
-    int epfd = (*epoll_create_func)(256);
+    int epfd = epoll_create(256);
     if (epfd < 0) {
        JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed");
     }
@@ -125,7 +77,7 @@
     event.events = events;
     event.data.fd = fd;
 
-    RESTARTABLE((*epoll_ctl_func)(epfd, (int)opcode, (int)fd, &event), res);
+    RESTARTABLE(epoll_ctl(epfd, (int)opcode, (int)fd, &event), res);
 
     return (res == 0) ? 0 : errno;
 }
@@ -137,7 +89,7 @@
     struct epoll_event *events = jlong_to_ptr(address);
     int res;
 
-    RESTARTABLE((*epoll_wait_func)(epfd, events, numfds, -1), res);
+    RESTARTABLE(epoll_wait(epfd, events, numfds, -1), res);
     if (res < 0) {
         JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed");
     }
--- a/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c	Wed Apr 27 17:11:06 2011 +0800
+++ b/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c	Wed Apr 27 13:46:22 2011 +0100
@@ -33,33 +33,10 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/poll.h>
+#include <sys/inotify.h>
 
 #include "sun_nio_fs_LinuxWatchService.h"
 
-/* inotify.h may not be available at build time */
-#ifdef  __cplusplus
-extern "C" {
-#endif
-struct inotify_event
-{
-  int wd;
-  uint32_t mask;
-  uint32_t cookie;
-  uint32_t len;
-  char name __flexarr;
-};
-#ifdef  __cplusplus
-}
-#endif
-
-typedef int inotify_init_func(void);
-typedef int inotify_add_watch_func(int fd, const char* path, uint32_t mask);
-typedef int inotify_rm_watch_func(int fd, uint32_t wd);
-
-inotify_init_func* my_inotify_init_func = NULL;
-inotify_add_watch_func* my_inotify_add_watch_func = NULL;
-inotify_rm_watch_func* my_inotify_rm_watch_func = NULL;
-
 static void throwUnixException(JNIEnv* env, int errnum) {
     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
         "(I)V", errnum);
@@ -68,22 +45,6 @@
     }
 }
 
-JNIEXPORT void JNICALL
-Java_sun_nio_fs_LinuxWatchService_init(JNIEnv *env, jclass clazz)
-{
-    my_inotify_init_func = (inotify_init_func*)
-        dlsym(RTLD_DEFAULT, "inotify_init");
-    my_inotify_add_watch_func =
-        (inotify_add_watch_func*) dlsym(RTLD_DEFAULT, "inotify_add_watch");
-    my_inotify_rm_watch_func =
-        (inotify_rm_watch_func*) dlsym(RTLD_DEFAULT, "inotify_rm_watch");
-
-    if ((my_inotify_init_func == NULL) || (my_inotify_add_watch_func == NULL) ||
-        (my_inotify_rm_watch_func == NULL)) {
-        JNU_ThrowInternalError(env, "unable to get address of inotify functions");
-    }
-}
-
 JNIEXPORT jint JNICALL
 Java_sun_nio_fs_LinuxWatchService_eventSize(JNIEnv *env, jclass clazz)
 {
@@ -111,7 +72,7 @@
 Java_sun_nio_fs_LinuxWatchService_inotifyInit
     (JNIEnv* env, jclass clazz)
 {
-    int ifd = (*my_inotify_init_func)();
+    int ifd = inotify_init();
     if (ifd == -1) {
         throwUnixException(env, errno);
     }
@@ -125,7 +86,7 @@
     int wfd = -1;
     const char* path = (const char*)jlong_to_ptr(address);
 
-    wfd = (*my_inotify_add_watch_func)((int)fd, path, mask);
+    wfd = inotify_add_watch((int)fd, path, mask);
     if (wfd == -1) {
         throwUnixException(env, errno);
     }
@@ -136,7 +97,7 @@
 Java_sun_nio_fs_LinuxWatchService_inotifyRmWatch
     (JNIEnv* env, jclass clazz, jint fd, jint wd)
 {
-    int err = (*my_inotify_rm_watch_func)((int)fd, (int)wd);
+    int err = inotify_rm_watch((int)fd, (int)wd);
     if (err == -1)
         throwUnixException(env, errno);
 }
@@ -166,7 +127,6 @@
         res[1] = (jint)sp[1];
         (*env)->SetIntArrayRegion(env, sv, 0, 2, &res[0]);
     }
-
 }
 
 JNIEXPORT jint JNICALL
@@ -190,6 +150,4 @@
         }
      }
     return (jint)n;
-
-
 }