From bbadc1bb04c299aa5a6a7d94f615069c532b0a41 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Wed, 27 Apr 2011 13:46:22 +0100 Subject: [PATCH] 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 | 2 - jdk/src/solaris/classes/sun/nio/ch/EPoll.java | 3 - .../classes/sun/nio/fs/LinuxWatchService.java | 3 - jdk/src/solaris/native/sun/nio/ch/EPoll.c | 56 ++----------------- .../native/sun/nio/fs/LinuxWatchService.c | 50 ++--------------- 5 files changed, 8 insertions(+), 106 deletions(-) diff --git a/jdk/make/java/nio/mapfile-linux b/jdk/make/java/nio/mapfile-linux index 7af5388de96..d72244170b9 100644 --- a/jdk/make/java/nio/mapfile-linux +++ b/jdk/make/java/nio/mapfile-linux @@ -44,7 +44,6 @@ SUNWprivate_1.1 { 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 @@ SUNWprivate_1.1 { 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; diff --git a/jdk/src/solaris/classes/sun/nio/ch/EPoll.java b/jdk/src/solaris/classes/sun/nio/ch/EPoll.java index 8af24f8c793..78bc83c8549 100644 --- a/jdk/src/solaris/classes/sun/nio/ch/EPoll.java +++ b/jdk/src/solaris/classes/sun/nio/ch/EPoll.java @@ -99,8 +99,6 @@ class EPoll { // -- Native methods -- - private static native void init(); - private static native int eventSize(); private static native int eventsOffset(); @@ -116,6 +114,5 @@ class EPoll { static { Util.load(); - init(); } } diff --git a/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java b/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java index 31d3bf0770f..5726fe317ab 100644 --- a/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java +++ b/jdk/src/solaris/classes/sun/nio/fs/LinuxWatchService.java @@ -432,8 +432,6 @@ class LinuxWatchService // -- native methods -- - private static native void init(); - // sizeof inotify_event private static native int eventSize(); @@ -461,6 +459,5 @@ class LinuxWatchService System.loadLibrary("nio"); return null; }}); - init(); } } diff --git a/jdk/src/solaris/native/sun/nio/ch/EPoll.c b/jdk/src/solaris/native/sun/nio/ch/EPoll.c index 43efe372ad0..667270491c4 100644 --- a/jdk/src/solaris/native/sun/nio/ch/EPoll.c +++ b/jdk/src/solaris/native/sun/nio/ch/EPoll.c @@ -34,55 +34,7 @@ #include #include #include - -#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 JNIEXPORT jint JNICALL Java_sun_nio_ch_EPoll_eventSize(JNIEnv* env, jclass this) @@ -108,7 +60,7 @@ Java_sun_nio_ch_EPoll_epollCreate(JNIEnv *env, jclass c) { * 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 @@ Java_sun_nio_ch_EPoll_epollCtl(JNIEnv *env, jclass c, jint epfd, 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 @@ Java_sun_nio_ch_EPoll_epollWait(JNIEnv *env, jclass c, 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"); } diff --git a/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c b/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c index 0b48180cd70..ca4ce5e6f62 100644 --- a/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c +++ b/jdk/src/solaris/native/sun/nio/fs/LinuxWatchService.c @@ -33,33 +33,10 @@ #include #include #include +#include #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 @@ static void throwUnixException(JNIEnv* env, int errnum) { } } -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 @@ JNIEXPORT jint JNICALL 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 @@ Java_sun_nio_fs_LinuxWatchService_inotifyAddWatch 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 @@ JNIEXPORT void JNICALL 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 @@ Java_sun_nio_fs_LinuxWatchService_socketpair res[1] = (jint)sp[1]; (*env)->SetIntArrayRegion(env, sv, 0, 2, &res[0]); } - } JNIEXPORT jint JNICALL @@ -190,6 +150,4 @@ Java_sun_nio_fs_LinuxWatchService_poll } } return (jint)n; - - }