JDK-6756825 : java.nio EPollArray implementation assumes target os structure layout
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_2.6
  • CPU: arm
  • Submitted: 2008-10-07
  • Updated: 2010-04-02
  • Resolved: 2008-10-07
Related Reports
Duplicate :  
Description
The J2SE solaris/sun/nio/ch/EPollArrayWrapper implementation hardcodes the structure offsets for the system epoll_event structure.   This doesn't work on ARM EABI systems where the int64 item in the structure must be naturally aligned (which is different from the x86/Solaris packing.  

The Hotspot Embedded team has developed a fix for this that involes having the native code compute the structure offsets.  See the 'suggested fix' for patches that the embedded hotspot team developed for the ARM port.

Comments
EVALUATION See 6728542.
07-10-2008

SUGGESTED FIX sccs diffs -r 1.3 EPollArrayWrapper.java ------- EPollArrayWrapper.java ------- 2c2 < * %W% %E% --- > * @(#)EPollArrayWrapper.java 1.4 08/09/30 53,54c53,57 < // Miscellaneous constants < static final short SIZE_EPOLLEVENT = 12; --- > // Miscellaneous constants, > // values will be set obtained from the native init() > static final short SIZE_EPOLLEVENT; > static final short DATA_OFFSET; > static final short FD_OFFSET; 56,58c59 < static final short DATA_OFFSET = 4; < static final short FD_OFFSET = 4; < static final int NUM_EPOLLEVENTS = Math.min(fdLimit(), 8192); --- > static final int NUM_EPOLLEVENTS = Math.min(fdLimit(), 8192); 69d69 < 258c258,267 < init(); --- > int structOffs = init(); > > // structOffs contains the size of the native epoll_event > // and the offset of the data member. The two short values > // are packed into an int to avoid more native call overhead > > SIZE_EPOLLEVENT = (short)(structOffs >> 16); > DATA_OFFSET = (short)(structOffs & 0xffff); > > FD_OFFSET = DATA_OFFSET; 267c276 < private static native void init(); --- > private static native int init(); ---------------- sccs diffs -r 1.7 EPollArrayWrapper.c ------- EPollArrayWrapper.c ------- 2c2 < * %W% %E% --- > * @(#)EPollArrayWrapper.c 1.8 08/09/30 19a20,23 > #ifndef offsetof > #define offsetof(type, field)((long) &((type *)0)->field) > #endif /* offsetof */ > 23a28,36 > /* > * ARM EABI does NOT pack structures that contain 64 bit values > */ > #if (__ARM_EABI__) > #define TARGET_PACKING > #else > #define TARGET_PACKING __attribute__ ((packed)) > #endif > 36c49 < } __attribute__ ((__packed__)); --- > } TARGET_PACKING; 91,92c104,105 < JNIEXPORT void JNICALL < Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv *env, jclass this) --- > JNIEXPORT jint JNICALL > Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv *env, jclass this) 101a115,120 > > /* > * The Java code needs to know the size of the epoll_event structure and the offset of the > * second item in it so it can make and parse epoll_events. > */ > return (jint)((sizeof(struct epoll_event) << 16) + offsetof(struct epoll_event, data));
07-10-2008