提交 aa86257a 编写于 作者: A alanb

8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx)

Reviewed-by: alanb, coffeys
Contributed-by: nmaurer@redhat.com, alan.bateman@oracle.com
上级 3781604c
......@@ -26,9 +26,11 @@
package sun.nio.ch;
import java.io.IOException;
import java.security.AccessController;
import java.util.BitSet;
import java.util.Map;
import java.util.HashMap;
import sun.security.action.GetIntegerAction;
/**
......@@ -78,10 +80,11 @@ class DevPollArrayWrapper {
static final int NUM_POLLFDS = Math.min(OPEN_MAX-1, 8192);
// Initial size of arrays for fd registration changes
private final int INITIAL_PENDING_UPDATE_SIZE = 64;
private static final int INITIAL_PENDING_UPDATE_SIZE = 64;
// maximum size of updatesLow
private final int MAX_UPDATE_ARRAY_SIZE = Math.min(OPEN_MAX, 64*1024);
private static final int MAX_UPDATE_ARRAY_SIZE = AccessController.doPrivileged(
new GetIntegerAction("sun.nio.ch.maxUpdateArraySize", Math.min(OPEN_MAX, 64*1024)));
// The pollfd array for results from devpoll driver
private final AllocatedNativeObject pollArray;
......
......@@ -26,9 +26,11 @@
package sun.nio.ch;
import java.io.IOException;
import java.security.AccessController;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import sun.security.action.GetIntegerAction;
/**
* Manipulates a native array of epoll_event structs on Linux:
......@@ -78,8 +80,8 @@ class EPollArrayWrapper {
private static final int INITIAL_PENDING_UPDATE_SIZE = 64;
// maximum size of updatesLow
private static final int MAX_UPDATE_ARRAY_SIZE = Math.min(OPEN_MAX, 64*1024);
private static final int MAX_UPDATE_ARRAY_SIZE = AccessController.doPrivileged(
new GetIntegerAction("sun.nio.ch.maxUpdateArraySize", Math.min(OPEN_MAX, 64*1024)));
// The fd of the epoll driver
private final int epfd;
......@@ -163,6 +165,16 @@ class EPollArrayWrapper {
return pollArray.getInt(offset);
}
/**
* Returns {@code true} if updates for the given key (file
* descriptor) are killed.
*/
private boolean isEventsHighKilled(Integer key) {
assert key >= MAX_UPDATE_ARRAY_SIZE;
Byte value = eventsHigh.get(key);
return (value != null && value == KILLED);
}
/**
* Sets the pending update events for the given file descriptor. This
* method has no effect if the update events is already set to KILLED,
......@@ -175,7 +187,7 @@ class EPollArrayWrapper {
}
} else {
Integer key = Integer.valueOf(fd);
if ((eventsHigh.get(key) != KILLED) || force) {
if (!isEventsHighKilled(key) || force) {
eventsHigh.put(key, Byte.valueOf(events));
}
}
......
......@@ -25,9 +25,14 @@
package sun.nio.ch;
import sun.misc.Unsafe;
import java.io.IOException;
import java.util.*;
import java.security.AccessController;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import sun.misc.Unsafe;
import sun.security.action.GetIntegerAction;
import static sun.nio.ch.SolarisEventPort.*;
/**
......@@ -49,7 +54,8 @@ class EventPortWrapper {
private final int INITIAL_PENDING_UPDATE_SIZE = 256;
// maximum size of updateArray
private final int MAX_UPDATE_ARRAY_SIZE = Math.min(OPEN_MAX, 64*1024);
private static final int MAX_UPDATE_ARRAY_SIZE = AccessController.doPrivileged(
new GetIntegerAction("sun.nio.ch.maxUpdateArraySize", Math.min(OPEN_MAX, 64*1024)));
// special update status to indicate that it should be ignored
private static final byte IGNORE = -1;
......
......@@ -22,9 +22,10 @@
*/
/* @test
* @bug 4503092
* @bug 4503092 8024883
* @summary Tests that Windows Selector can use more than 63 channels
* @run main/timeout=300 LotsOfChannels
* @run main LotsOfChannels
* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=64 LotsOfChannels
* @author kladko
*/
......
......@@ -22,12 +22,13 @@
*/
/* @test
* @bug 4777504
* @bug 4777504 8024883
* @summary Ensure that a Selector can return at least 100 selected keys
* @author Mark Reinhold
* @library ..
* @build SelectorLimit
* @run main/othervm SelectorLimit
* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=128 SelectorLimit
*/
import java.io.*;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册