8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil

Reviewed-by: chegar
This commit is contained in:
Alan Bateman 2013-08-28 15:50:03 +01:00
parent ce3943d27d
commit 188f6e49f5
41 changed files with 55 additions and 89 deletions

View File

@ -87,6 +87,7 @@ class KQueueArrayWrapper {
private int incomingInterruptFD;
static {
IOUtil.load();
initStructSizes();
String datamodel = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.arch.data.model")

View File

@ -246,9 +246,4 @@ class KQueueSelectorImpl
}
return this;
}
static {
Util.load();
}
}

View File

@ -193,9 +193,4 @@ abstract class AbstractPollSelectorImpl
if (!selch.isOpen() && !selch.isRegistered())
((SelChImpl)selch).kill();
}
static {
Util.load();
}
}

View File

@ -1138,7 +1138,7 @@ class DatagramChannelImpl
throws IOException;
static {
Util.load();
IOUtil.load();
initIDs();
}

View File

@ -1162,7 +1162,7 @@ public class FileChannelImpl
private static native long initIDs();
static {
Util.load();
IOUtil.load();
allocationGranularity = initIDs();
}

View File

@ -347,9 +347,23 @@ public class IOUtil {
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();
}

View File

@ -582,7 +582,7 @@ public class Net {
private static native void initIDs();
static {
Util.load();
IOUtil.load();
initIDs();
}

View File

@ -416,7 +416,7 @@ class ServerSocketChannelImpl
private static native void initIDs();
static {
Util.load();
IOUtil.load();
initIDs();
nd = new SocketDispatcher();
}

View File

@ -1024,7 +1024,7 @@ class SocketChannelImpl
throws IOException;
static {
Util.load();
IOUtil.load();
nd = new SocketDispatcher();
}

View File

@ -401,30 +401,4 @@ public class Util {
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();
}
}
}

View File

@ -36,7 +36,7 @@ import java.net.*;
class DatagramDispatcher extends NativeDispatcher
{
static {
Util.load();
IOUtil.load();
}
int read(FileDescriptor fd, long address, int len) throws IOException {

View File

@ -316,4 +316,8 @@ class DevPollArrayWrapper {
private native int poll0(long pollAddress, int numfds, long timeout,
int wfd);
private static native void interrupt(int fd);
static {
IOUtil.load();
}
}

View File

@ -196,9 +196,4 @@ class DevPollSelectorImpl
}
return this;
}
static {
Util.load();
}
}

View File

@ -113,6 +113,6 @@ class EPoll {
throws IOException;
static {
Util.load();
IOUtil.load();
}
}

View File

@ -318,6 +318,7 @@ class EPollArrayWrapper {
}
static {
IOUtil.load();
init();
}

View File

@ -318,6 +318,6 @@ final class EPollPort
private static native void close0(int fd);
static {
Util.load();
IOUtil.load();
}
}

View File

@ -196,8 +196,4 @@ class EPollSelectorImpl
}
return this;
}
static {
Util.load();
}
}

View File

@ -31,7 +31,7 @@ class FileDispatcherImpl extends FileDispatcher
{
static {
Util.load();
IOUtil.load();
init();
}

View File

@ -235,6 +235,6 @@ class InheritedChannel {
private static native int peerPort0(int fd);
static {
Util.load();
IOUtil.load();
}
}

View File

@ -115,6 +115,6 @@ class KQueue {
throws IOException;
static {
Util.load();
IOUtil.load();
}
}

View File

@ -326,6 +326,6 @@ final class KQueuePort
private static native void close0(int fd);
static {
Util.load();
IOUtil.load();
}
}

View File

@ -54,7 +54,7 @@ public class NativeThread {
private static native void init();
static {
Util.load();
IOUtil.load();
init();
}

View File

@ -126,4 +126,7 @@ public class PollArrayWrapper extends AbstractPollArrayWrapper {
private static native void interrupt(int fd);
static {
IOUtil.load();
}
}

View File

@ -37,7 +37,7 @@ class SinkChannelImpl
{
// 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 @@ class SinkChannelImpl
throw new IndexOutOfBoundsException();
return write(Util.subsequence(srcs, offset, length));
}
static {
Util.load();
nd = new FileDispatcherImpl();
}
}

View File

@ -260,6 +260,6 @@ class SolarisEventPort
static {
Util.load();
IOUtil.load();
}
}

View File

@ -37,7 +37,7 @@ class SourceChannelImpl
{
// 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 @@ class SourceChannelImpl
}
}
}
static {
Util.load();
nd = new FileDispatcherImpl();
}
}

View File

@ -345,7 +345,7 @@ class UnixAsynchronousServerSocketChannelImpl
throws IOException;
static {
Util.load();
IOUtil.load();
initIDs();
}
}

View File

@ -748,6 +748,6 @@ class UnixAsynchronousSocketChannelImpl
private static native void checkConnect(int fdVal) throws IOException;
static {
Util.load();
IOUtil.load();
}
}

View File

@ -1106,7 +1106,7 @@ public class SctpChannelImpl extends SctpChannel
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() {

View File

@ -995,7 +995,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
}
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() {

View File

@ -426,7 +426,7 @@ public class SctpServerChannelImpl extends SctpServerChannel
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() {

View File

@ -36,7 +36,7 @@ import java.net.*;
class DatagramDispatcher extends NativeDispatcher
{
static {
Util.load();
IOUtil.load();
}
int read(FileDescriptor fd, long address, int len) throws IOException {

View File

@ -32,7 +32,7 @@ import sun.misc.JavaIOFileDescriptorAccess;
class FileDispatcherImpl extends FileDispatcher
{
static {
Util.load();
IOUtil.load();
}
/**

View File

@ -73,6 +73,7 @@ public class FileKey {
private static native void initIDs();
static {
IOUtil.load();
initIDs();
}
}

View File

@ -443,7 +443,7 @@ class Iocp extends AsynchronousChannelGroupImpl {
private static native String getErrorMessage(int error);
static {
Util.load();
IOUtil.load();
initIDs();
// thread agnostic I/O on Vista/2008 or newer

View File

@ -56,7 +56,6 @@ class PipeImpl
private static final Random rnd;
static {
Util.load();
byte[] someBytes = new byte[8];
boolean resultOK = IOUtil.randomBytes(someBytes);
if (resultOK) {

View File

@ -36,7 +36,7 @@ class SocketDispatcher extends NativeDispatcher
{
static {
Util.load();
IOUtil.load();
}
int read(FileDescriptor fd, long address, int len) throws IOException {

View File

@ -750,6 +750,6 @@ public class WindowsAsynchronousFileChannelImpl
private static native void close0(long handle);
static {
Util.load();
IOUtil.load();
}
}

View File

@ -363,7 +363,7 @@ class WindowsAsynchronousServerSocketChannelImpl
private static native void closesocket0(long socket) throws IOException;
static {
Util.load();
IOUtil.load();
initIDs();
}
}

View File

@ -919,7 +919,7 @@ class WindowsAsynchronousSocketChannelImpl
private static native void closesocket0(long socket) throws IOException;
static {
Util.load();
IOUtil.load();
initIDs();
}
}

View File

@ -611,6 +611,6 @@ final class WindowsSelectorImpl extends SelectorImpl {
}
static {
Util.load();
IOUtil.load();
}
}