changeset 6586:d89c33d27e86

8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx) Reviewed-by: alanb, coffeys Contributed-by: nmaurer@redhat.com, alan.bateman@oracle.com
author alanb
date Wed, 18 Sep 2013 14:10:24 +0100
parents 9251ab32bcc4
children 0ca8d6d46b74
files src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java src/solaris/classes/sun/nio/ch/EventPortWrapper.java test/java/nio/channels/Selector/LotsOfChannels.java test/java/nio/channels/Selector/SelectorLimit.java
diffstat 5 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java	Mon Sep 23 11:08:30 2013 +0100
+++ b/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/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java	Mon Sep 23 11:08:30 2013 +0100
+++ b/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/src/solaris/classes/sun/nio/ch/EventPortWrapper.java	Mon Sep 23 11:08:30 2013 +0100
+++ b/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/test/java/nio/channels/Selector/LotsOfChannels.java	Mon Sep 23 11:08:30 2013 +0100
+++ b/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/test/java/nio/channels/Selector/SelectorLimit.java	Mon Sep 23 11:08:30 2013 +0100
+++ b/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.*;