changeset 414:06c4c56e8f3f

6429289: (se) sun.nio.ch.SelectorImpl.processDeregisterQueue creates excessive garbage Summary: Check if the cancelledKeys is empty or not before creating iterator Reviewed-by: alanb
author sherman
date Wed, 16 Jul 2008 15:24:15 -0700
parents fb3e3e1316b9
children 4fbfb33929c3
files src/share/classes/sun/nio/ch/SelectorImpl.java
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/nio/ch/SelectorImpl.java	Wed Jul 16 15:09:24 2008 -0700
+++ b/src/share/classes/sun/nio/ch/SelectorImpl.java	Wed Jul 16 15:24:15 2008 -0700
@@ -142,18 +142,20 @@
         // Precondition: Synchronized on this, keys, and selectedKeys
         Set cks = cancelledKeys();
         synchronized (cks) {
-            Iterator i = cks.iterator();
-            while (i.hasNext()) {
-                SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
-                try {
-                    implDereg(ski);
-                } catch (SocketException se) {
-                    IOException ioe = new IOException(
-                        "Error deregistering key");
-                    ioe.initCause(se);
-                    throw ioe;
-                } finally {
-                    i.remove();
+            if (!cks.isEmpty()) {
+                Iterator i = cks.iterator();
+                while (i.hasNext()) {
+                    SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
+                    try {
+                        implDereg(ski);
+                    } catch (SocketException se) {
+                        IOException ioe = new IOException(
+                            "Error deregistering key");
+                        ioe.initCause(se);
+                        throw ioe;
+                    } finally {
+                        i.remove();
+                    }
                 }
             }
         }