changeset 8456:a8cd02b9d957

8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil Reviewed-by: chegar
author alanb
date Wed, 13 Jul 2016 18:19:14 +0100
parents be4e524be4e1
children 3dcefeb4d257
files src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java src/share/classes/sun/nio/ch/DatagramChannelImpl.java src/share/classes/sun/nio/ch/FileChannelImpl.java src/share/classes/sun/nio/ch/IOUtil.java src/share/classes/sun/nio/ch/Net.java src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java src/share/classes/sun/nio/ch/SocketChannelImpl.java src/share/classes/sun/nio/ch/Util.java src/solaris/classes/sun/nio/ch/DatagramDispatcher.java src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java src/solaris/classes/sun/nio/ch/EPoll.java src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java src/solaris/classes/sun/nio/ch/EPollPort.java src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java src/solaris/classes/sun/nio/ch/InheritedChannel.java src/solaris/classes/sun/nio/ch/KQueue.java src/solaris/classes/sun/nio/ch/KQueuePort.java src/solaris/classes/sun/nio/ch/NativeThread.java src/solaris/classes/sun/nio/ch/PollArrayWrapper.java src/solaris/classes/sun/nio/ch/SctpChannelImpl.java src/solaris/classes/sun/nio/ch/SctpMultiChannelImpl.java src/solaris/classes/sun/nio/ch/SctpServerChannelImpl.java src/solaris/classes/sun/nio/ch/SinkChannelImpl.java src/solaris/classes/sun/nio/ch/SolarisEventPort.java src/solaris/classes/sun/nio/ch/SourceChannelImpl.java src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java src/windows/classes/sun/nio/ch/DatagramDispatcher.java src/windows/classes/sun/nio/ch/FileDispatcherImpl.java src/windows/classes/sun/nio/ch/FileKey.java src/windows/classes/sun/nio/ch/Iocp.java src/windows/classes/sun/nio/ch/PipeImpl.java src/windows/classes/sun/nio/ch/SocketDispatcher.java src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java
diffstat 41 files changed, 55 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java	Wed Jul 13 18:19:14 2016 +0100
@@ -87,6 +87,7 @@
     private int incomingInterruptFD;
 
     static {
+        IOUtil.load();
         initStructSizes();
         String datamodel = (String) java.security.AccessController.doPrivileged(
         new sun.security.action.GetPropertyAction("sun.arch.data.model"));
--- a/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -246,9 +246,4 @@
         }
         return this;
     }
-
-
-    static {
-        Util.load();
-    }
 }
--- a/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -193,9 +193,4 @@
         if (!selch.isOpen() && !selch.isRegistered())
             ((SelChImpl)selch).kill();
     }
-
-    static {
-        Util.load();
-    }
-
 }
--- a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -1125,7 +1125,7 @@
         throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
     }
 
--- a/src/share/classes/sun/nio/ch/FileChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/FileChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -1200,7 +1200,7 @@
     private static native long initIDs();
 
     static {
-        Util.load();
+        IOUtil.load();
         allocationGranularity = initIDs();
     }
 
--- a/src/share/classes/sun/nio/ch/IOUtil.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/IOUtil.java	Wed Jul 13 18:19:14 2016 +0100
@@ -346,9 +346,23 @@
 
     static native void initIDs();
 
+    /**
+     * Used to trigger loading of native libraries
+     */
+    public static void load() { }
+
     static {
-        // Note that IOUtil.initIDs is called from within Util.load.
-        Util.load();
+        java.security.AccessController.doPrivileged(
+                new java.security.PrivilegedAction<Void>() {
+                    public Void run() {
+                        System.loadLibrary("net");
+                        System.loadLibrary("nio");
+                        return null;
+                    }
+                });
+
+        initIDs();
+
         IOV_MAX = iovMax();
     }
 
--- a/src/share/classes/sun/nio/ch/Net.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/Net.java	Wed Jul 13 18:19:14 2016 +0100
@@ -628,7 +628,7 @@
     private static native void initIDs();
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
     }
 
--- a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -403,7 +403,7 @@
     private static native void initIDs();
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
         nd = new SocketDispatcher();
     }
--- a/src/share/classes/sun/nio/ch/SocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/SocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -1038,7 +1038,7 @@
         throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
         nd = new SocketDispatcher();
     }
 
--- a/src/share/classes/sun/nio/ch/Util.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/share/classes/sun/nio/ch/Util.java	Wed Jul 13 18:19:14 2016 +0100
@@ -471,25 +471,4 @@
         return bugLevel.equals(bl);
     }
 
-
-
-    // -- Initialization --
-
-    private static boolean loaded = false;
-
-    static void load() {
-        synchronized (Util.class) {
-            if (loaded)
-                return;
-            loaded = true;
-            java.security.AccessController
-                .doPrivileged(new sun.security.action.LoadLibraryAction("net"));
-            java.security.AccessController
-                .doPrivileged(new sun.security.action.LoadLibraryAction("nio"));
-            // IOUtil must be initialized; Its native methods are called from
-            // other places in native nio code so they must be set up.
-            IOUtil.initIDs();
-        }
-    }
-
 }
--- a/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java	Wed Jul 13 18:19:14 2016 +0100
@@ -36,7 +36,7 @@
 class DatagramDispatcher extends NativeDispatcher
 {
     static {
-        Util.load();
+        IOUtil.load();
     }
 
     int read(FileDescriptor fd, long address, int len) throws IOException {
--- a/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java	Wed Jul 13 18:19:14 2016 +0100
@@ -319,4 +319,8 @@
     private native int poll0(long pollAddress, int numfds, long timeout,
                              int wfd);
     private static native void interrupt(int fd);
+
+    static {
+        IOUtil.load();
+    }
 }
--- a/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -196,9 +196,4 @@
         }
         return this;
     }
-
-    static {
-        Util.load();
-    }
-
 }
--- a/src/solaris/classes/sun/nio/ch/EPoll.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/EPoll.java	Wed Jul 13 18:19:14 2016 +0100
@@ -113,6 +113,6 @@
         throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java	Wed Jul 13 18:19:14 2016 +0100
@@ -330,6 +330,7 @@
     }
 
     static {
+        IOUtil.load();
         init();
     }
 
--- a/src/solaris/classes/sun/nio/ch/EPollPort.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/EPollPort.java	Wed Jul 13 18:19:14 2016 +0100
@@ -318,6 +318,6 @@
     private static native void close0(int fd);
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -196,8 +196,4 @@
         }
         return this;
     }
-
-    static {
-        Util.load();
-    }
 }
--- a/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -31,7 +31,7 @@
 class FileDispatcherImpl extends FileDispatcher {
 
     static {
-        Util.load();
+        IOUtil.load();
         init();
     }
 
--- a/src/solaris/classes/sun/nio/ch/InheritedChannel.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/InheritedChannel.java	Wed Jul 13 18:19:14 2016 +0100
@@ -235,6 +235,6 @@
     private static native int peerPort0(int fd);
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/KQueue.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/KQueue.java	Wed Jul 13 18:19:14 2016 +0100
@@ -115,6 +115,6 @@
         throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/KQueuePort.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/KQueuePort.java	Wed Jul 13 18:19:14 2016 +0100
@@ -326,6 +326,6 @@
     private static native void close0(int fd);
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/NativeThread.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/NativeThread.java	Wed Jul 13 18:19:14 2016 +0100
@@ -54,7 +54,7 @@
     static native void init();
 
     static {
-        Util.load();
+        IOUtil.load();
         init();
     }
 
--- a/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java	Wed Jul 13 18:19:14 2016 +0100
@@ -126,4 +126,7 @@
 
     private static native void interrupt(int fd);
 
+    static {
+        IOUtil.load();
+    }
 }
--- a/src/solaris/classes/sun/nio/ch/SctpChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SctpChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -1103,7 +1103,7 @@
             boolean ready) throws IOException;
 
     static {
-        Util.load();   /* loads nio & net native libraries */
+        IOUtil.load();   /* loads nio & net native libraries */
         java.security.AccessController.doPrivileged(
                 new sun.security.action.LoadLibraryAction("sctp"));
         initIDs();
--- a/src/solaris/classes/sun/nio/ch/SctpMultiChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SctpMultiChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -986,7 +986,7 @@
     }
 
     static {
-        Util.load();   /* loads nio & net native libraries */
+        IOUtil.load();   /* loads nio & net native libraries */
         java.security.AccessController.doPrivileged(
                 new sun.security.action.LoadLibraryAction("sctp"));
     }
--- a/src/solaris/classes/sun/nio/ch/SctpServerChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SctpServerChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -416,7 +416,7 @@
         FileDescriptor newfd, InetSocketAddress[] isaa) throws IOException;
 
     static {
-        Util.load();   // loads nio & net native libraries
+        IOUtil.load();   // loads nio & net native libraries
         java.security.AccessController.doPrivileged(
                 new sun.security.action.LoadLibraryAction("sctp"));
         initIDs();
--- a/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -37,7 +37,7 @@
 {
 
     // Used to make native read and write calls
-    private static NativeDispatcher nd;
+    private static final NativeDispatcher nd = new FileDispatcherImpl();
 
     // The file descriptor associated with this channel
     FileDescriptor fd;
@@ -206,10 +206,4 @@
            throw new IndexOutOfBoundsException();
         return write(Util.subsequence(srcs, offset, length));
     }
-
-    static {
-        Util.load();
-        nd = new FileDispatcherImpl();
-    }
-
 }
--- a/src/solaris/classes/sun/nio/ch/SolarisEventPort.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SolarisEventPort.java	Wed Jul 13 18:19:14 2016 +0100
@@ -260,6 +260,6 @@
 
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -37,7 +37,7 @@
 {
 
     // Used to make native read and write calls
-    private static NativeDispatcher nd;
+    private static final NativeDispatcher nd = new FileDispatcherImpl();
 
     // The file descriptor associated with this channel
     FileDescriptor fd;
@@ -206,10 +206,4 @@
             }
         }
     }
-
-    static {
-        Util.load();
-        nd = new FileDispatcherImpl();
-    }
-
 }
--- a/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -345,7 +345,7 @@
         throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
     }
 }
--- a/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -748,6 +748,6 @@
     private static native void checkConnect(int fdVal) throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/windows/classes/sun/nio/ch/DatagramDispatcher.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/DatagramDispatcher.java	Wed Jul 13 18:19:14 2016 +0100
@@ -36,7 +36,7 @@
 class DatagramDispatcher extends NativeDispatcher
 {
     static {
-        Util.load();
+        IOUtil.load();
     }
 
     int read(FileDescriptor fd, long address, int len) throws IOException {
--- a/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -147,7 +147,7 @@
     }
 
     static {
-        Util.load();
+        IOUtil.load();
         fastFileTransfer = isFastFileTransferRequested();
     }
 
--- a/src/windows/classes/sun/nio/ch/FileKey.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/FileKey.java	Wed Jul 13 18:19:14 2016 +0100
@@ -73,6 +73,7 @@
     private static native void initIDs();
 
     static {
+        IOUtil.load();
         initIDs();
     }
 }
--- a/src/windows/classes/sun/nio/ch/Iocp.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/Iocp.java	Wed Jul 13 18:19:14 2016 +0100
@@ -443,7 +443,7 @@
     private static native String getErrorMessage(int error);
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
 
         // thread agnostic I/O on Vista/2008 or newer
--- a/src/windows/classes/sun/nio/ch/PipeImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/PipeImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -56,7 +56,6 @@
     private static final Random rnd;
 
     static {
-        Util.load();
         byte[] someBytes = new byte[8];
         boolean resultOK = IOUtil.randomBytes(someBytes);
         if (resultOK) {
--- a/src/windows/classes/sun/nio/ch/SocketDispatcher.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/SocketDispatcher.java	Wed Jul 13 18:19:14 2016 +0100
@@ -36,7 +36,7 @@
 {
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 
     int read(FileDescriptor fd, long address, int len) throws IOException {
--- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -754,6 +754,6 @@
     private static native void close0(long handle);
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }
--- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -363,7 +363,7 @@
     private static native void closesocket0(long socket) throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
     }
 }
--- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -938,7 +938,7 @@
     private static native void closesocket0(long socket) throws IOException;
 
     static {
-        Util.load();
+        IOUtil.load();
         initIDs();
     }
 }
--- a/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Tue Apr 26 20:31:54 2016 +0300
+++ b/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Wed Jul 13 18:19:14 2016 +0100
@@ -611,6 +611,6 @@
     }
 
     static {
-        Util.load();
+        IOUtil.load();
     }
 }