src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java

Print this page

        

*** 74,90 **** static final int NUM_POLLFDS = Math.min(OPEN_MAX-1, 8192); // Base address of the native pollArray private long pollArrayAddress; // Maximum number of POLL_FD structs to update at once ! private int MAX_UPDATE_SIZE = 10000; DevPollArrayWrapper() { int allocationSize = NUM_POLLFDS * SIZE_POLLFD; pollArray = new AllocatedNativeObject(allocationSize, true); pollArrayAddress = pollArray.address(); wfd = init(); for (int i=0; i<NUM_POLLFDS; i++) { putDescriptor(i, 0); putEventOps(i, 0); --- 74,95 ---- static final int NUM_POLLFDS = Math.min(OPEN_MAX-1, 8192); // Base address of the native pollArray private long pollArrayAddress; + // Array of pollfd structs used for driver updates + private AllocatedNativeObject updatePollArray; + // Maximum number of POLL_FD structs to update at once ! private int MAX_UPDATE_SIZE = Math.min(OPEN_MAX, 10000); DevPollArrayWrapper() { int allocationSize = NUM_POLLFDS * SIZE_POLLFD; pollArray = new AllocatedNativeObject(allocationSize, true); pollArrayAddress = pollArray.address(); + allocationSize = MAX_UPDATE_SIZE * SIZE_POLLFD; + updatePollArray = new AllocatedNativeObject(allocationSize, true); wfd = init(); for (int i=0; i<NUM_POLLFDS; i++) { putDescriptor(i, 0); putEventOps(i, 0);
*** 172,184 **** } void closeDevPollFD() throws IOException { FileDispatcherImpl.closeIntFD(wfd); pollArray.free(); } ! int poll(long timeout) { updateRegistrations(); updated = poll0(pollArrayAddress, NUM_POLLFDS, timeout, wfd); for (int i=0; i<updated; i++) { if (getDescriptor(i) == incomingInterruptFD) { interruptedIndex = i; --- 177,190 ---- } void closeDevPollFD() throws IOException { FileDispatcherImpl.closeIntFD(wfd); pollArray.free(); + updatePollArray.free(); } ! int poll(long timeout) throws IOException { updateRegistrations(); updated = poll0(pollArrayAddress, NUM_POLLFDS, timeout, wfd); for (int i=0; i<updated; i++) { if (getDescriptor(i) == incomingInterruptFD) { interruptedIndex = i;
*** 187,216 **** } } return updated; } ! void updateRegistrations() { ! // take snapshot of the updateList size to see if there are ! // any registrations to update ! int updateSize; synchronized (updateList) { - updateSize = updateList.size(); - } - if (updateSize > 0) { - // Construct a pollfd array with updated masks; we may overallocate - // by some amount because if the events are already POLLREMOVE - // then the second pollfd of that pair will not be needed. The - // number of entries is limited to a reasonable number to avoid - // allocating a lot of memory. - int maxUpdates = Math.min(updateSize * 2, MAX_UPDATE_SIZE); - int allocationSize = maxUpdates * SIZE_POLLFD; - AllocatedNativeObject updatePollArray = - new AllocatedNativeObject(allocationSize, true); - - try { - synchronized (updateList) { while (updateList.size() > 0) { // We have to insert a dummy node in between each // real update to use POLLREMOVE on the fd first because // otherwise the changes are simply OR'd together int index = 0; --- 193,205 ---- } } return updated; } ! void updateRegistrations() throws IOException { ! // Populate pollfd array with updated masks synchronized (updateList) { while (updateList.size() > 0) { // We have to insert a dummy node in between each // real update to use POLLREMOVE on the fd first because // otherwise the changes are simply OR'd together int index = 0;
*** 219,252 **** // First add pollfd struct to clear out this fd putPollFD(updatePollArray, index, u.fd, POLLREMOVE); index++; // Now add pollfd to update this fd, if necessary if (u.mask != POLLREMOVE) { ! putPollFD(updatePollArray, index, u.fd, ! (short)u.mask); index++; } ! // Check against the max allocation size; these are // all we will process. Valid index ranges from 0 to ! // (maxUpdates - 1) and we can use up to 2 per loop ! if (index > maxUpdates - 2) break; } // Register the changes with /dev/poll registerMultiple(wfd, updatePollArray.address(), index); } } - } finally { - // Free the native array - updatePollArray.free(); - // BUG: If an exception was thrown then the selector now believes - // that the last set of changes was updated but it probably - // was not. This should not be a likely occurrence. } - } - } private void putPollFD(AllocatedNativeObject array, int index, int fd, short event) { int structIndex = SIZE_POLLFD * index; --- 208,232 ---- // First add pollfd struct to clear out this fd putPollFD(updatePollArray, index, u.fd, POLLREMOVE); index++; // Now add pollfd to update this fd, if necessary if (u.mask != POLLREMOVE) { ! putPollFD(updatePollArray, index, u.fd, (short)u.mask); index++; } ! // Check against the max update size; these are // all we will process. Valid index ranges from 0 to ! // (MAX_UPDATE_SIZE - 1) and we can use up to 2 per loop ! if (index > MAX_UPDATE_SIZE - 2) break; } // Register the changes with /dev/poll registerMultiple(wfd, updatePollArray.address(), index); } } } private void putPollFD(AllocatedNativeObject array, int index, int fd, short event) { int structIndex = SIZE_POLLFD * index;
*** 273,283 **** interrupted = false; } private native int init(); private native void register(int wfd, int fd, int mask); ! private native void registerMultiple(int wfd, long address, int len); private native int poll0(long pollAddress, int numfds, long timeout, int wfd); private static native void interrupt(int fd); private static native int fdLimit(); --- 253,264 ---- interrupted = false; } private native int init(); private native void register(int wfd, int fd, int mask); ! private native void registerMultiple(int wfd, long address, int len) ! throws IOException; private native int poll0(long pollAddress, int numfds, long timeout, int wfd); private static native void interrupt(int fd); private static native int fdLimit();