From d7586529e5309a09b697a679fa53165c55a0d17b Mon Sep 17 00:00:00 2001 From: alanb Date: Tue, 26 Aug 2008 09:23:12 +0100 Subject: [PATCH] 6728542: (se) epoll based SelectorProvider should be portable to platforms other than x86 and x64 Reviewed-by: sherman --- make/java/nio/mapfile-linux | 2 ++ .../classes/sun/nio/ch/EPollArrayWrapper.java | 12 +++++----- .../native/sun/nio/ch/EPollArrayWrapper.c | 22 ++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/make/java/nio/mapfile-linux b/make/java/nio/mapfile-linux index dc2044c9d..2eba69d17 100644 --- a/make/java/nio/mapfile-linux +++ b/make/java/nio/mapfile-linux @@ -18,6 +18,8 @@ SUNWprivate_1.1 { Java_sun_nio_ch_EPollArrayWrapper_fdLimit; Java_sun_nio_ch_EPollArrayWrapper_init; Java_sun_nio_ch_EPollArrayWrapper_interrupt; + Java_sun_nio_ch_EPollArrayWrapper_offsetofData; + Java_sun_nio_ch_EPollArrayWrapper_sizeofEPollEvent; Java_sun_nio_ch_FileChannelImpl_close0; Java_sun_nio_ch_FileChannelImpl_force0; Java_sun_nio_ch_FileChannelImpl_initIDs; diff --git a/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java b/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java index 4ee5e0617..8ebb0c223 100644 --- a/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java +++ b/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java @@ -69,11 +69,11 @@ class EPollArrayWrapper { static final int EPOLL_CTL_MOD = 3; // Miscellaneous constants - static final short SIZE_EPOLLEVENT = 12; - static final short EVENT_OFFSET = 0; - static final short DATA_OFFSET = 4; - static final short FD_OFFSET = 4; - static final int NUM_EPOLLEVENTS = Math.min(fdLimit(), 8192); + static final int SIZE_EPOLLEVENT = sizeofEPollEvent(); + static final int EVENT_OFFSET = 0; + static final int DATA_OFFSET = offsetofData(); + static final int FD_OFFSET = DATA_OFFSET; + static final int NUM_EPOLLEVENTS = Math.min(fdLimit(), 8192); // Base address of the native pollArray private final long pollArrayAddress; @@ -280,6 +280,8 @@ class EPollArrayWrapper { private native void epollCtl(int epfd, int opcode, int fd, int events); private native int epollWait(long pollAddress, int numfds, long timeout, int epfd) throws IOException; + private static native int sizeofEPollEvent(); + private static native int offsetofData(); private static native int fdLimit(); private static native void interrupt(int fd); private static native void init(); diff --git a/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c b/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c index ad9237b2e..7b4a4e738 100644 --- a/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c +++ b/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c @@ -48,10 +48,18 @@ typedef union epoll_data { __uint64_t u64; } epoll_data_t; + +/* x86-64 has same alignment as 32-bit */ +#ifdef __x86_64__ +#define EPOLL_PACKED __attribute__((packed)) +#else +#define EPOLL_PACKED +#endif + struct epoll_event { __uint32_t events; /* Epoll events */ epoll_data_t data; /* User data variable */ -} __attribute__ ((__packed__)); +} EPOLL_PACKED; #ifdef __cplusplus } @@ -143,6 +151,18 @@ Java_sun_nio_ch_EPollArrayWrapper_fdLimit(JNIEnv *env, jclass this) return (jint)rlp.rlim_max; } +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPollArrayWrapper_sizeofEPollEvent(JNIEnv* env, jclass this) +{ + return sizeof(struct epoll_event); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPollArrayWrapper_offsetofData(JNIEnv* env, jclass this) +{ + return offsetof(struct epoll_event, data); +} + JNIEXPORT void JNICALL Java_sun_nio_ch_EPollArrayWrapper_epollCtl(JNIEnv *env, jobject this, jint epfd, jint opcode, jint fd, jint events) -- GitLab