8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx)
authoralanb
Wed, 18 Sep 2013 14:10:24 +0100
changeset 20176 59b7a49e7f8b
parent 20175 a65ad0a49e3c
child 20177 8ea486a4f36e
8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx) Reviewed-by: alanb, coffeys Contributed-by: nmaurer@redhat.com, alan.bateman@oracle.com
jdk/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java
jdk/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java
jdk/src/solaris/classes/sun/nio/ch/EventPortWrapper.java
jdk/test/java/nio/channels/Selector/LotsOfChannels.java
jdk/test/java/nio/channels/Selector/SelectorLimit.java
--- a/jdk/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java	Wed Sep 18 18:22:49 2013 +0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java	Wed Sep 18 14:10:24 2013 +0100
@@ -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 @@
     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;
--- a/jdk/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java	Wed Sep 18 18:22:49 2013 +0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java	Wed Sep 18 14:10:24 2013 +0100
@@ -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 @@
     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;
@@ -164,6 +166,16 @@
     }
 
     /**
+     * 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,
      * unless {@code force} is {@code true}.
@@ -175,7 +187,7 @@
             }
         } else {
             Integer key = Integer.valueOf(fd);
-            if ((eventsHigh.get(key) != KILLED) || force) {
+            if (!isEventsHighKilled(key) || force) {
                 eventsHigh.put(key, Byte.valueOf(events));
             }
         }
--- a/jdk/src/solaris/classes/sun/nio/ch/EventPortWrapper.java	Wed Sep 18 18:22:49 2013 +0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/EventPortWrapper.java	Wed Sep 18 14:10:24 2013 +0100
@@ -25,9 +25,14 @@
 
 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.misc.Unsafe;
-import java.io.IOException;
-import java.util.*;
+import sun.security.action.GetIntegerAction;
 import static sun.nio.ch.SolarisEventPort.*;
 
 /**
@@ -49,7 +54,8 @@
     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;
--- a/jdk/test/java/nio/channels/Selector/LotsOfChannels.java	Wed Sep 18 18:22:49 2013 +0800
+++ b/jdk/test/java/nio/channels/Selector/LotsOfChannels.java	Wed Sep 18 14:10:24 2013 +0100
@@ -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
  */
 
--- a/jdk/test/java/nio/channels/Selector/SelectorLimit.java	Wed Sep 18 18:22:49 2013 +0800
+++ b/jdk/test/java/nio/channels/Selector/SelectorLimit.java	Wed Sep 18 14:10:24 2013 +0100
@@ -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.*;