8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
Reviewed-by: chegar
--- a/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java Wed Aug 28 15:50:03 2013 +0100
@@ -87,6 +87,7 @@
private int incomingInterruptFD;
static {
+ IOUtil.load();
initStructSizes();
String datamodel = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.arch.data.model")
--- a/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -246,9 +246,4 @@
}
return this;
}
-
-
- static {
- Util.load();
- }
}
--- a/jdk/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -193,9 +193,4 @@
if (!selch.isOpen() && !selch.isRegistered())
((SelChImpl)selch).kill();
}
-
- static {
- Util.load();
- }
-
}
--- a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -1138,7 +1138,7 @@
throws IOException;
static {
- Util.load();
+ IOUtil.load();
initIDs();
}
--- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -1162,7 +1162,7 @@
private static native long initIDs();
static {
- Util.load();
+ IOUtil.load();
allocationGranularity = initIDs();
}
--- a/jdk/src/share/classes/sun/nio/ch/IOUtil.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/IOUtil.java Wed Aug 28 15:50:03 2013 +0100
@@ -347,9 +347,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/jdk/src/share/classes/sun/nio/ch/Net.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/Net.java Wed Aug 28 15:50:03 2013 +0100
@@ -582,7 +582,7 @@
private static native void initIDs();
static {
- Util.load();
+ IOUtil.load();
initIDs();
}
--- a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -416,7 +416,7 @@
private static native void initIDs();
static {
- Util.load();
+ IOUtil.load();
initIDs();
nd = new SocketDispatcher();
}
--- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -1024,7 +1024,7 @@
throws IOException;
static {
- Util.load();
+ IOUtil.load();
nd = new SocketDispatcher();
}
--- a/jdk/src/share/classes/sun/nio/ch/Util.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/share/classes/sun/nio/ch/Util.java Wed Aug 28 15:50:03 2013 +0100
@@ -401,30 +401,4 @@
return bugLevel.equals(bl);
}
-
-
- // -- Initialization --
-
- private static boolean loaded = false;
-
- public static void load() {
- synchronized (Util.class) {
- if (loaded)
- return;
- loaded = true;
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<Void>() {
- public Void run() {
- System.loadLibrary("net");
- System.loadLibrary("nio");
- return null;
- }
- });
-
- // 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/jdk/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java Wed Aug 28 15:50:03 2013 +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/jdk/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java Wed Aug 28 15:50:03 2013 +0100
@@ -316,4 +316,8 @@
private native int poll0(long pollAddress, int numfds, long timeout,
int wfd);
private static native void interrupt(int fd);
+
+ static {
+ IOUtil.load();
+ }
}
--- a/jdk/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -196,9 +196,4 @@
}
return this;
}
-
- static {
- Util.load();
- }
-
}
--- a/jdk/src/solaris/classes/sun/nio/ch/EPoll.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPoll.java Wed Aug 28 15:50:03 2013 +0100
@@ -113,6 +113,6 @@
throws IOException;
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java Wed Aug 28 15:50:03 2013 +0100
@@ -318,6 +318,7 @@
}
static {
+ IOUtil.load();
init();
}
--- a/jdk/src/solaris/classes/sun/nio/ch/EPollPort.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPollPort.java Wed Aug 28 15:50:03 2013 +0100
@@ -318,6 +318,6 @@
private static native void close0(int fd);
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -196,8 +196,4 @@
}
return this;
}
-
- static {
- Util.load();
- }
}
--- a/jdk/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -31,7 +31,7 @@
{
static {
- Util.load();
+ IOUtil.load();
init();
}
--- a/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java Wed Aug 28 15:50:03 2013 +0100
@@ -235,6 +235,6 @@
private static native int peerPort0(int fd);
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/KQueue.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/KQueue.java Wed Aug 28 15:50:03 2013 +0100
@@ -115,6 +115,6 @@
throws IOException;
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/KQueuePort.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/KQueuePort.java Wed Aug 28 15:50:03 2013 +0100
@@ -326,6 +326,6 @@
private static native void close0(int fd);
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/NativeThread.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/NativeThread.java Wed Aug 28 15:50:03 2013 +0100
@@ -54,7 +54,7 @@
private static native void init();
static {
- Util.load();
+ IOUtil.load();
init();
}
--- a/jdk/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java Wed Aug 28 15:50:03 2013 +0100
@@ -126,4 +126,7 @@
private static native void interrupt(int fd);
+ static {
+ IOUtil.load();
+ }
}
--- a/jdk/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java Wed Aug 28 15:50:03 2013 +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/jdk/src/solaris/classes/sun/nio/ch/SolarisEventPort.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/SolarisEventPort.java Wed Aug 28 15:50:03 2013 +0100
@@ -260,6 +260,6 @@
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java Wed Aug 28 15:50:03 2013 +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/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -345,7 +345,7 @@
throws IOException;
static {
- Util.load();
+ IOUtil.load();
initIDs();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -748,6 +748,6 @@
private static native void checkConnect(int fdVal) throws IOException;
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -1106,7 +1106,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 java.security.PrivilegedAction<Void>() {
public Void run() {
--- a/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -995,7 +995,7 @@
}
static {
- Util.load(); /* loads nio & net native libraries */
+ IOUtil.load(); /* loads nio & net native libraries */
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
--- a/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -426,7 +426,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 java.security.PrivilegedAction<Void>() {
public Void run() {
--- a/jdk/src/windows/classes/sun/nio/ch/DatagramDispatcher.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/DatagramDispatcher.java Wed Aug 28 15:50:03 2013 +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/jdk/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -32,7 +32,7 @@
class FileDispatcherImpl extends FileDispatcher
{
static {
- Util.load();
+ IOUtil.load();
}
/**
--- a/jdk/src/windows/classes/sun/nio/ch/FileKey.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/FileKey.java Wed Aug 28 15:50:03 2013 +0100
@@ -73,6 +73,7 @@
private static native void initIDs();
static {
+ IOUtil.load();
initIDs();
}
}
--- a/jdk/src/windows/classes/sun/nio/ch/Iocp.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/Iocp.java Wed Aug 28 15:50:03 2013 +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/jdk/src/windows/classes/sun/nio/ch/PipeImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/PipeImpl.java Wed Aug 28 15:50:03 2013 +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/jdk/src/windows/classes/sun/nio/ch/SocketDispatcher.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/SocketDispatcher.java Wed Aug 28 15:50:03 2013 +0100
@@ -36,7 +36,7 @@
{
static {
- Util.load();
+ IOUtil.load();
}
int read(FileDescriptor fd, long address, int len) throws IOException {
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -750,6 +750,6 @@
private static native void close0(long handle);
static {
- Util.load();
+ IOUtil.load();
}
}
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -363,7 +363,7 @@
private static native void closesocket0(long socket) throws IOException;
static {
- Util.load();
+ IOUtil.load();
initIDs();
}
}
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -919,7 +919,7 @@
private static native void closesocket0(long socket) throws IOException;
static {
- Util.load();
+ IOUtil.load();
initIDs();
}
}
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java Wed Aug 28 14:07:30 2013 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java Wed Aug 28 15:50:03 2013 +0100
@@ -611,6 +611,6 @@
}
static {
- Util.load();
+ IOUtil.load();
}
}