8072466: Deadlock when initializing MulticastSocket and DatagramSocket
Reviewed-by: chegar
This commit is contained in:
parent
b259dd24ea
commit
50aa8839d5
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -28,8 +28,7 @@
|
|||||||
SUNWprivate_1.1 {
|
SUNWprivate_1.1 {
|
||||||
global:
|
global:
|
||||||
JNI_OnLoad;
|
JNI_OnLoad;
|
||||||
Java_java_net_AbstractPlainDatagramSocketImpl_init;
|
Java_java_net_PlainDatagramSocketImpl_dataAvailable;
|
||||||
Java_java_net_AbstractPlainDatagramSocketImpl_dataAvailable;
|
|
||||||
Java_java_net_PlainSocketImpl_socketListen;
|
Java_java_net_PlainSocketImpl_socketListen;
|
||||||
Java_java_net_PlainDatagramSocketImpl_getTTL;
|
Java_java_net_PlainDatagramSocketImpl_getTTL;
|
||||||
Java_java_net_PlainDatagramSocketImpl_init;
|
Java_java_net_PlainDatagramSocketImpl_init;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -68,7 +68,6 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,6 +363,5 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
|||||||
return connectDisabled;
|
return connectDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
native int dataAvailable();
|
abstract int dataAvailable();
|
||||||
private static native void init();
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007,2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -130,6 +130,8 @@ class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
|
|||||||
|
|
||||||
protected native void disconnect0(int family);
|
protected native void disconnect0(int family);
|
||||||
|
|
||||||
|
native int dataAvailable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform class load-time initializations.
|
* Perform class load-time initializations.
|
||||||
*/
|
*/
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __solaris__
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stropts.h>
|
|
||||||
|
|
||||||
#ifndef BSD_COMP
|
|
||||||
#define BSD_COMP
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
|
|
||||||
#include "jvm.h"
|
|
||||||
#include "jni_util.h"
|
|
||||||
#include "net_util.h"
|
|
||||||
|
|
||||||
#include "java_net_AbstractPlainDatagramSocketImpl.h"
|
|
||||||
|
|
||||||
static jfieldID IO_fd_fdID;
|
|
||||||
|
|
||||||
static jfieldID apdsi_fdID;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: java_net_AbstractPlainDatagramSocketImpl
|
|
||||||
* Method: init
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_java_net_AbstractPlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
|
|
||||||
|
|
||||||
apdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
|
|
||||||
"Ljava/io/FileDescriptor;");
|
|
||||||
CHECK_NULL(apdsi_fdID);
|
|
||||||
|
|
||||||
IO_fd_fdID = NET_GetFileDescriptorID(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: java_net_AbstractPlainDatagramSocketImpl
|
|
||||||
* Method: dataAvailable
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_java_net_AbstractPlainDatagramSocketImpl_dataAvailable
|
|
||||||
(JNIEnv *env, jobject this) {
|
|
||||||
int fd, retval;
|
|
||||||
|
|
||||||
jobject fdObj = (*env)->GetObjectField(env, this, apdsi_fdID);
|
|
||||||
|
|
||||||
if (IS_NULL(fdObj)) {
|
|
||||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
|
||||||
"Socket closed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
|
||||||
|
|
||||||
if (ioctl(fd, FIONREAD, &retval) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -32,6 +32,12 @@
|
|||||||
|
|
||||||
#ifdef __solaris__
|
#ifdef __solaris__
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stropts.h>
|
||||||
|
|
||||||
|
#ifndef BSD_COMP
|
||||||
|
#define BSD_COMP
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -52,6 +58,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#ifndef IPTOS_TOS_MASK
|
#ifndef IPTOS_TOS_MASK
|
||||||
#define IPTOS_TOS_MASK 0x1e
|
#define IPTOS_TOS_MASK 0x1e
|
||||||
#endif
|
#endif
|
||||||
@ -2240,3 +2248,28 @@ Java_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this,
|
|||||||
{
|
{
|
||||||
mcast_join_leave(env, this, iaObj, niObj, JNI_FALSE);
|
mcast_join_leave(env, this, iaObj, niObj, JNI_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: java_net_PlainDatagramSocketImpl
|
||||||
|
* Method: dataAvailable
|
||||||
|
* Signature: ()I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL
|
||||||
|
Java_java_net_PlainDatagramSocketImpl_dataAvailable(JNIEnv *env, jobject this)
|
||||||
|
{
|
||||||
|
int fd, retval;
|
||||||
|
|
||||||
|
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||||
|
|
||||||
|
if (IS_NULL(fdObj)) {
|
||||||
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||||
|
"Socket closed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
||||||
|
|
||||||
|
if (ioctl(fd, FIONREAD, &retval) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -45,7 +45,7 @@ import java.security.PrivilegedAction;
|
|||||||
|
|
||||||
class DefaultDatagramSocketImplFactory
|
class DefaultDatagramSocketImplFactory
|
||||||
{
|
{
|
||||||
static Class<?> prefixImplClass = null;
|
private final static Class<?> prefixImplClass;
|
||||||
|
|
||||||
/* the windows version. */
|
/* the windows version. */
|
||||||
private static float version;
|
private static float version;
|
||||||
@ -54,16 +54,19 @@ class DefaultDatagramSocketImplFactory
|
|||||||
private static boolean preferIPv4Stack = false;
|
private static boolean preferIPv4Stack = false;
|
||||||
|
|
||||||
/* If the version supports a dual stack TCP implementation */
|
/* If the version supports a dual stack TCP implementation */
|
||||||
private static boolean useDualStackImpl = false;
|
private final static boolean useDualStackImpl;
|
||||||
|
|
||||||
/* sun.net.useExclusiveBind */
|
/* sun.net.useExclusiveBind */
|
||||||
private static String exclBindProp;
|
private static String exclBindProp;
|
||||||
|
|
||||||
/* True if exclusive binding is on for Windows */
|
/* True if exclusive binding is on for Windows */
|
||||||
private static boolean exclusiveBind = true;
|
private final static boolean exclusiveBind;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
Class<?> prefixImplClassLocal = null;
|
||||||
|
boolean useDualStackImplLocal = false;
|
||||||
|
boolean exclusiveBindLocal = true;
|
||||||
|
|
||||||
// Determine Windows Version.
|
// Determine Windows Version.
|
||||||
java.security.AccessController.doPrivileged(
|
java.security.AccessController.doPrivileged(
|
||||||
new PrivilegedAction<Object>() {
|
new PrivilegedAction<Object>() {
|
||||||
@ -78,7 +81,7 @@ class DefaultDatagramSocketImplFactory
|
|||||||
"java.net.preferIPv4Stack"));
|
"java.net.preferIPv4Stack"));
|
||||||
exclBindProp = System.getProperty(
|
exclBindProp = System.getProperty(
|
||||||
"sun.net.useExclusiveBind");
|
"sun.net.useExclusiveBind");
|
||||||
} catch (NumberFormatException e ) {
|
} catch (NumberFormatException e) {
|
||||||
assert false : e;
|
assert false : e;
|
||||||
}
|
}
|
||||||
return null; // nothing to return
|
return null; // nothing to return
|
||||||
@ -87,14 +90,14 @@ class DefaultDatagramSocketImplFactory
|
|||||||
|
|
||||||
// (version >= 6.0) implies Vista or greater.
|
// (version >= 6.0) implies Vista or greater.
|
||||||
if (version >= 6.0 && !preferIPv4Stack) {
|
if (version >= 6.0 && !preferIPv4Stack) {
|
||||||
useDualStackImpl = true;
|
useDualStackImplLocal = true;
|
||||||
}
|
}
|
||||||
if (exclBindProp != null) {
|
if (exclBindProp != null) {
|
||||||
// sun.net.useExclusiveBind is true
|
// sun.net.useExclusiveBind is true
|
||||||
exclusiveBind = exclBindProp.length() == 0 ? true
|
exclusiveBindLocal = exclBindProp.length() == 0 ? true
|
||||||
: Boolean.parseBoolean(exclBindProp);
|
: Boolean.parseBoolean(exclBindProp);
|
||||||
} else if (version < 6.0) {
|
} else if (version < 6.0) {
|
||||||
exclusiveBind = false;
|
exclusiveBindLocal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl.prefix
|
// impl.prefix
|
||||||
@ -103,12 +106,16 @@ class DefaultDatagramSocketImplFactory
|
|||||||
prefix = AccessController.doPrivileged(
|
prefix = AccessController.doPrivileged(
|
||||||
new sun.security.action.GetPropertyAction("impl.prefix", null));
|
new sun.security.action.GetPropertyAction("impl.prefix", null));
|
||||||
if (prefix != null)
|
if (prefix != null)
|
||||||
prefixImplClass = Class.forName("java.net."+prefix+"DatagramSocketImpl");
|
prefixImplClassLocal = Class.forName("java.net."+prefix+"DatagramSocketImpl");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Can't find class: java.net." +
|
System.err.println("Can't find class: java.net." +
|
||||||
prefix +
|
prefix +
|
||||||
"DatagramSocketImpl: check impl.prefix property");
|
"DatagramSocketImpl: check impl.prefix property");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefixImplClass = prefixImplClassLocal;
|
||||||
|
useDualStackImpl = useDualStackImplLocal;
|
||||||
|
exclusiveBind = exclusiveBindLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,12 +133,10 @@ class DefaultDatagramSocketImplFactory
|
|||||||
throw new SocketException("can't instantiate DatagramSocketImpl");
|
throw new SocketException("can't instantiate DatagramSocketImpl");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isMulticast)
|
|
||||||
exclusiveBind = false;
|
|
||||||
if (useDualStackImpl && !isMulticast)
|
if (useDualStackImpl && !isMulticast)
|
||||||
return new DualStackPlainDatagramSocketImpl(exclusiveBind);
|
return new DualStackPlainDatagramSocketImpl(exclusiveBind);
|
||||||
else
|
else
|
||||||
return new TwoStacksPlainDatagramSocketImpl(exclusiveBind);
|
return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -292,4 +292,6 @@ class DualStackPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
|
|||||||
int optionValue) throws SocketException;
|
int optionValue) throws SocketException;
|
||||||
|
|
||||||
private static native int socketGetIntOption(int fd, int cmd) throws SocketException;
|
private static native int socketGetIntOption(int fd, int cmd) throws SocketException;
|
||||||
|
|
||||||
|
native int dataAvailable();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -207,6 +207,8 @@ class TwoStacksPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
|
|||||||
|
|
||||||
protected native void disconnect0(int family);
|
protected native void disconnect0(int family);
|
||||||
|
|
||||||
|
native int dataAvailable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform class load-time initializations.
|
* Perform class load-time initializations.
|
||||||
*/
|
*/
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <winsock2.h>
|
|
||||||
|
|
||||||
#include "jvm.h"
|
|
||||||
#include "jni_util.h"
|
|
||||||
#include "net_util.h"
|
|
||||||
|
|
||||||
#include "java_net_AbstractPlainDatagramSocketImpl.h"
|
|
||||||
|
|
||||||
static jfieldID IO_fd_fdID = NULL;
|
|
||||||
static jfieldID apdsi_fdID = NULL;
|
|
||||||
|
|
||||||
static jfieldID apdsi_fd1ID = NULL;
|
|
||||||
static jclass two_stacks_clazz = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: java_net_AbstractPlainDatagramSocketImpl
|
|
||||||
* Method: init
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_java_net_AbstractPlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
|
|
||||||
|
|
||||||
apdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
|
|
||||||
"Ljava/io/FileDescriptor;");
|
|
||||||
CHECK_NULL(apdsi_fdID);
|
|
||||||
IO_fd_fdID = NET_GetFileDescriptorID(env);
|
|
||||||
CHECK_NULL(IO_fd_fdID);
|
|
||||||
|
|
||||||
two_stacks_clazz = (*env)->FindClass(env, "java/net/TwoStacksPlainDatagramSocketImpl");
|
|
||||||
CHECK_NULL(two_stacks_clazz);
|
|
||||||
|
|
||||||
/* Handle both TwoStacks and DualStack here */
|
|
||||||
|
|
||||||
if (JNU_Equals(env, cls, two_stacks_clazz)) {
|
|
||||||
/* fd1 present only in TwoStack.. */
|
|
||||||
apdsi_fd1ID = (*env)->GetFieldID(env, cls, "fd1",
|
|
||||||
"Ljava/io/FileDescriptor;");
|
|
||||||
CHECK_NULL(apdsi_fd1ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
JNU_CHECK_EXCEPTION(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: java_net_AbstractPlainDatagramSocketImpl
|
|
||||||
* Method: dataAvailable
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_java_net_AbstractPlainDatagramSocketImpl_dataAvailable
|
|
||||||
(JNIEnv *env, jobject this) {
|
|
||||||
SOCKET fd;
|
|
||||||
SOCKET fd1;
|
|
||||||
int rv = -1, rv1 = -1;
|
|
||||||
jobject fdObj = (*env)->GetObjectField(env, this, apdsi_fdID);
|
|
||||||
|
|
||||||
if (!IS_NULL(fdObj)) {
|
|
||||||
int retval = 0;
|
|
||||||
fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
|
||||||
rv = ioctlsocket(fd, FIONREAD, &retval);
|
|
||||||
if (retval > 0) {
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IS_NULL(apdsi_fd1ID)) {
|
|
||||||
/* TwoStacks */
|
|
||||||
jobject fd1Obj = (*env)->GetObjectField(env, this, apdsi_fd1ID);
|
|
||||||
if (!IS_NULL(fd1Obj)) {
|
|
||||||
int retval = 0;
|
|
||||||
fd1 = (SOCKET)(*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
|
|
||||||
rv1 = ioctlsocket(fd1, FIONREAD, &retval);
|
|
||||||
if (retval > 0) {
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rv < 0 && rv1 < 0) {
|
|
||||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
|
||||||
"Socket closed");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -70,6 +70,9 @@ static jboolean purgeOutstandingICMP(JNIEnv *env, jint fd)
|
|||||||
return got_icmp;
|
return got_icmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jfieldID IO_fd_fdID = NULL;
|
||||||
|
static jfieldID pdsi_fdID = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: java_net_DualStackPlainDatagramSocketImpl
|
* Class: java_net_DualStackPlainDatagramSocketImpl
|
||||||
* Method: initIDs
|
* Method: initIDs
|
||||||
@ -78,6 +81,13 @@ static jboolean purgeOutstandingICMP(JNIEnv *env, jint fd)
|
|||||||
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_initIDs
|
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_initIDs
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
|
pdsi_fdID = (*env)->GetFieldID(env, clazz, "fd",
|
||||||
|
"Ljava/io/FileDescriptor;");
|
||||||
|
CHECK_NULL(pdsi_fdID);
|
||||||
|
IO_fd_fdID = NET_GetFileDescriptorID(env);
|
||||||
|
CHECK_NULL(IO_fd_fdID);
|
||||||
|
JNU_CHECK_EXCEPTION(env);
|
||||||
|
|
||||||
initInetAddressIDs(env);
|
initInetAddressIDs(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,3 +513,32 @@ JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketGetI
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: java_net_DualStackPlainDatagramSocketImpl
|
||||||
|
* Method: dataAvailable
|
||||||
|
* Signature: ()I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_dataAvailable
|
||||||
|
(JNIEnv *env, jobject this) {
|
||||||
|
SOCKET fd;
|
||||||
|
int rv = -1;
|
||||||
|
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||||
|
|
||||||
|
if (!IS_NULL(fdObj)) {
|
||||||
|
int retval = 0;
|
||||||
|
fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
||||||
|
rv = ioctlsocket(fd, FIONREAD, &retval);
|
||||||
|
if (retval > 0) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rv < 0) {
|
||||||
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||||
|
"Socket closed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -2563,3 +2563,44 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_leave(JNIEnv *env, jobject this,
|
|||||||
{
|
{
|
||||||
mcast_join_leave (env, this, iaObj, niObj, JNI_FALSE);
|
mcast_join_leave (env, this, iaObj, niObj, JNI_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: java_net_TwoStacksPlainDatagramSocketImpl
|
||||||
|
* Method: dataAvailable
|
||||||
|
* Signature: ()I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_java_net_TwoStacksPlainDatagramSocketImpl_dataAvailable
|
||||||
|
(JNIEnv *env, jobject this) {
|
||||||
|
SOCKET fd;
|
||||||
|
SOCKET fd1;
|
||||||
|
int rv = -1, rv1 = -1;
|
||||||
|
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||||
|
jobject fd1Obj;
|
||||||
|
|
||||||
|
if (!IS_NULL(fdObj)) {
|
||||||
|
int retval = 0;
|
||||||
|
fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
||||||
|
rv = ioctlsocket(fd, FIONREAD, &retval);
|
||||||
|
if (retval > 0) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
|
||||||
|
if (!IS_NULL(fd1Obj)) {
|
||||||
|
int retval = 0;
|
||||||
|
fd1 = (SOCKET)(*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
|
||||||
|
rv1 = ioctlsocket(fd1, FIONREAD, &retval);
|
||||||
|
if (retval > 0) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rv < 0 && rv1 < 0) {
|
||||||
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||||
|
"Socket closed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
114
jdk/test/java/net/MulticastSocket/MultiDead.java
Normal file
114
jdk/test/java/net/MulticastSocket/MultiDead.java
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 8072466
|
||||||
|
* @summary Deadlock when initializing MulticastSocket and DatagramSocket
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build jdk.testlibrary.*
|
||||||
|
* @run main/othervm MultiDead
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.MulticastSocket;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import jdk.testlibrary.JDKToolLauncher;
|
||||||
|
|
||||||
|
public class MultiDead {
|
||||||
|
private static final int THREAD_PAIR_COUNT = 4;
|
||||||
|
private static final int CHILDREN_COUNT = 20;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Throwable {
|
||||||
|
if (args.length == 0 || args[0].equals("parent")) {
|
||||||
|
parentProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length > 0 && args[0].equals("child")) {
|
||||||
|
childProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void parentProcess() throws Throwable {
|
||||||
|
JDKToolLauncher launcher = JDKToolLauncher
|
||||||
|
.createUsingTestJDK("java")
|
||||||
|
.addToolArg("MultiDead")
|
||||||
|
.addToolArg("child");
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(launcher.getCommand());
|
||||||
|
|
||||||
|
AtomicReference<Process> child = new AtomicReference<>();
|
||||||
|
AtomicBoolean stopFlag = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
Thread th = new Thread(() -> {
|
||||||
|
for (int i = 0; i < CHILDREN_COUNT; ++i) {
|
||||||
|
System.out.println("child #" + (i + 1) + " of " +
|
||||||
|
CHILDREN_COUNT);
|
||||||
|
try {
|
||||||
|
child.set(pb.start());
|
||||||
|
child.get().waitFor();
|
||||||
|
if (stopFlag.get()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
th.start();
|
||||||
|
th.join(CHILDREN_COUNT * 1000); // 1 sec for a child to complete
|
||||||
|
stopFlag.set(true);
|
||||||
|
if (th.isAlive()) {
|
||||||
|
if (child.get() != null) {
|
||||||
|
child.get().destroyForcibly();
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Failed to complete on time.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void childProcess() {
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
for (int i = 0; i < THREAD_PAIR_COUNT; ++i) {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
try (MulticastSocket a = new MulticastSocket(6000)) {
|
||||||
|
}
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
try (DatagramSocket b = new DatagramSocket(6000)) {
|
||||||
|
}
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user