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