diff --git a/jdk/make/com/Makefile b/jdk/make/com/Makefile index baf56b3ddb0..37472ea3f3a 100644 --- a/jdk/make/com/Makefile +++ b/jdk/make/com/Makefile @@ -31,7 +31,7 @@ BUILDDIR = .. PRODUCT = com include $(BUILDDIR)/common/Defs.gmk -SUBDIRS = sun +SUBDIRS = sun oracle include $(BUILDDIR)/common/Subdirs.gmk all build clean clobber:: diff --git a/jdk/make/com/oracle/Makefile b/jdk/make/com/oracle/Makefile new file mode 100644 index 00000000000..7c70dc78270 --- /dev/null +++ b/jdk/make/com/oracle/Makefile @@ -0,0 +1,34 @@ +# +# Copyright (c) 2010, 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. +# + +BUILDDIR = ../.. +PRODUCT = oracle +include $(BUILDDIR)/common/Defs.gmk + +SUBDIRS = net +include $(BUILDDIR)/common/Subdirs.gmk + +all build clean clobber:: + $(SUBDIRS-loop) diff --git a/jdk/make/com/oracle/net/Makefile b/jdk/make/com/oracle/net/Makefile new file mode 100644 index 00000000000..5fd30761699 --- /dev/null +++ b/jdk/make/com/oracle/net/Makefile @@ -0,0 +1,39 @@ +# +# Copyright (c) 2010, 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. +# + +BUILDDIR = ../../.. +PRODUCT = oracle +include $(BUILDDIR)/common/Defs.gmk + +# +# Files to compile +# +AUTO_FILES_JAVA_DIRS = com/oracle/net + +# +# Rules +# +include $(BUILDDIR)/common/Classes.gmk + diff --git a/jdk/make/docs/NON_CORE_PKGS.gmk b/jdk/make/docs/NON_CORE_PKGS.gmk index 6639eecf893..180241483c1 100644 --- a/jdk/make/docs/NON_CORE_PKGS.gmk +++ b/jdk/make/docs/NON_CORE_PKGS.gmk @@ -91,6 +91,8 @@ SCTPAPI_PKGS = com.sun.nio.sctp TRACING_PKGS = com.sun.tracing \ com.sun.tracing.dtrace +ORACLENET_PKGS = com.oracle.net + # non-core packages in rt.jar NON_CORE_PKGS = $(DOMAPI_PKGS) \ $(MGMT_PKGS) \ @@ -101,5 +103,6 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \ $(HTTPSERVER_PKGS) \ $(SMARTCARDIO_PKGS) \ $(TRACING_PKGS) \ - $(SCTPAPI_PKGS) + $(SCTPAPI_PKGS) \ + $(ORACLENET_PKGS) diff --git a/jdk/make/java/net/FILES_c.gmk b/jdk/make/java/net/FILES_c.gmk index 642244915af..29ce70a6e68 100644 --- a/jdk/make/java/net/FILES_c.gmk +++ b/jdk/make/java/net/FILES_c.gmk @@ -39,10 +39,6 @@ FILES_c = \ ResolverConfigurationImpl.c \ DefaultProxySelector.c -ifeq ($(PLATFORM), solaris) - FILES_c += SdpProvider.c -endif - ifeq ($(PLATFORM), linux) FILES_c += linux_close.c endif diff --git a/jdk/make/java/net/Makefile b/jdk/make/java/net/Makefile index 0021087cbcf..db034f2511e 100644 --- a/jdk/make/java/net/Makefile +++ b/jdk/make/java/net/Makefile @@ -44,6 +44,8 @@ ifeq ($(PLATFORM), windows) endif FILES_c += NTLMAuthSequence.c FILES_c += NetworkInterface_winXP.c +else + FILES_c += SdpSupport.c endif FILES_export = \ @@ -84,7 +86,8 @@ endif # # Find platform specific native code # -vpath %.c $(PLATFORM_SRC)/native/sun/net/dns $(PLATFORM_SRC)/native/sun/net/www/protocol/http/ntlm $(PLATFORM_SRC)/native/sun/net/spi +vpath %.c $(PLATFORM_SRC)/native/sun/net/dns $(PLATFORM_SRC)/native/sun/net/www/protocol/http/ntlm \ + $(PLATFORM_SRC)/native/sun/net/sdp $(PLATFORM_SRC)/native/sun/net/spi # # Include rules diff --git a/jdk/make/java/net/mapfile-vers b/jdk/make/java/net/mapfile-vers index fbcf905d173..0e9a46755d4 100644 --- a/jdk/make/java/net/mapfile-vers +++ b/jdk/make/java/net/mapfile-vers @@ -88,9 +88,10 @@ SUNWprivate_1.1 { Java_java_net_PlainDatagramSocketImpl_setTimeToLive; Java_sun_net_dns_ResolverConfigurationImpl_localDomain0; Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0; + Java_sun_net_sdp_SdpSupport_convert0; + Java_sun_net_sdp_SdpSupport_create0; Java_sun_net_spi_DefaultProxySelector_init; Java_sun_net_spi_DefaultProxySelector_getSystemProxy; - Java_sun_net_spi_SdpProvider_convert; NET_AllocSockaddr; NET_SockaddrToInetAddress; NET_SockaddrEqualsInetAddress; diff --git a/jdk/make/java/nio/FILES_java.gmk b/jdk/make/java/nio/FILES_java.gmk index 4ad955d87aa..4d89db04a49 100644 --- a/jdk/make/java/nio/FILES_java.gmk +++ b/jdk/make/java/nio/FILES_java.gmk @@ -199,6 +199,7 @@ FILES_src = \ sun/nio/ch/PipeImpl.java \ sun/nio/ch/PollArrayWrapper.java \ sun/nio/ch/Reflect.java \ + sun/nio/ch/Secrets.java \ sun/nio/ch/SelectionKeyImpl.java \ sun/nio/ch/SelectorImpl.java \ sun/nio/ch/SelectorProviderImpl.java \ diff --git a/jdk/make/sun/net/FILES_java.gmk b/jdk/make/sun/net/FILES_java.gmk index 3eba9b01a17..1fcec35f4e4 100644 --- a/jdk/make/sun/net/FILES_java.gmk +++ b/jdk/make/sun/net/FILES_java.gmk @@ -53,6 +53,7 @@ FILES_java = \ sun/net/ftp/FtpProtocolException.java \ sun/net/ftp/impl/FtpClient.java \ sun/net/ftp/impl/DefaultFtpClientProvider.java \ + sun/net/sdp/SdpSupport.java \ sun/net/spi/DefaultProxySelector.java \ sun/net/spi/nameservice/NameServiceDescriptor.java \ sun/net/spi/nameservice/NameService.java \ @@ -136,8 +137,6 @@ FILES_java = \ ifeq ($(PLATFORM), windows) FILES_java += sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java -endif - -ifeq ($(PLATFORM), solaris) - FILES_java += sun/net/spi/SdpProvider.java +else + FILES_java += sun/net/sdp/SdpProvider.java endif diff --git a/jdk/src/share/classes/com/oracle/net/Sdp.java b/jdk/src/share/classes/com/oracle/net/Sdp.java new file mode 100644 index 00000000000..32316073828 --- /dev/null +++ b/jdk/src/share/classes/com/oracle/net/Sdp.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2010, 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. + */ + +package com.oracle.net; + +import java.net.Socket; +import java.net.ServerSocket; +import java.net.SocketImpl; +import java.net.SocketImplFactory; +import java.net.SocketException; +import java.nio.channels.SocketChannel; +import java.nio.channels.ServerSocketChannel; +import java.io.IOException; +import java.io.FileDescriptor; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.lang.reflect.Constructor; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.InvocationTargetException; + +import sun.net.sdp.SdpSupport; + +/** + * This class consists exclusively of static methods that Sockets or Channels to + * sockets that support the InfiniBand Sockets Direct Protocol (SDP). + */ + +public final class Sdp { + private Sdp() { } + + /** + * The package-privage ServerSocket(SocketImpl) constructor + */ + private static final Constructor serverSocketCtor; + static { + try { + serverSocketCtor = (Constructor) + ServerSocket.class.getDeclaredConstructor(SocketImpl.class); + setAccessible(serverSocketCtor); + } catch (NoSuchMethodException e) { + throw new AssertionError(e); + } + } + + /** + * The package-private SdpSocketImpl() constructor + */ + private static final Constructor socketImplCtor; + static { + try { + Class cl = Class.forName("java.net.SdpSocketImpl", true, null); + socketImplCtor = (Constructor)cl.getDeclaredConstructor(); + setAccessible(socketImplCtor); + } catch (ClassNotFoundException e) { + throw new AssertionError(e); + } catch (NoSuchMethodException e) { + throw new AssertionError(e); + } + } + + private static void setAccessible(final AccessibleObject o) { + AccessController.doPrivileged(new PrivilegedAction() { + public Void run() { + o.setAccessible(true); + return null; + } + }); + } + + /** + * SDP enabled Socket. + */ + private static class SdpSocket extends Socket { + SdpSocket(SocketImpl impl) throws SocketException { + super(impl); + } + } + + /** + * Creates a SDP enabled SocketImpl + */ + private static SocketImpl createSocketImpl() { + try { + return socketImplCtor.newInstance(); + } catch (InstantiationException x) { + throw new AssertionError(x); + } catch (IllegalAccessException x) { + throw new AssertionError(x); + } catch (InvocationTargetException x) { + throw new AssertionError(x); + } + } + + /** + * Creates an unconnected and unbound SDP socket. The {@code Socket} is + * associated with a {@link java.net.SocketImpl} of the system-default type. + * + * @return a new Socket + * + * @throws UnsupportedOperationException + * If SDP is not supported + * @throws IOException + * If an I/O error occurs + */ + public static Socket openSocket() throws IOException { + SocketImpl impl = createSocketImpl(); + return new SdpSocket(impl); + } + + /** + * Creates an unbound SDP server socket. The {@code ServerSocket} is + * associated with a {@link java.net.SocketImpl} of the system-default type. + * + * @return a new ServerSocket + * + * @throws UnsupportedOperationException + * If SDP is not supported + * @throws IOException + * If an I/O error occurs + */ + public static ServerSocket openServerSocket() throws IOException { + // create ServerSocket via package-private constructor + SocketImpl impl = createSocketImpl(); + try { + return serverSocketCtor.newInstance(impl); + } catch (IllegalAccessException x) { + throw new AssertionError(x); + } catch (InstantiationException x) { + throw new AssertionError(x); + } catch (InvocationTargetException x) { + Throwable cause = x.getCause(); + if (cause instanceof IOException) + throw (IOException)cause; + if (cause instanceof RuntimeException) + throw (RuntimeException)cause; + throw new RuntimeException(x); + } + } + + /** + * Opens a socket channel to a SDP socket. + * + *

The channel will be associated with the system-wide default + * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}. + * + * @return a new SocketChannel + * + * @throws UnsupportedOperationException + * If SDP is not supported or not supported by the default selector + * provider + * @throws IOException + * If an I/O error occurs. + */ + public static SocketChannel openSocketChannel() throws IOException { + FileDescriptor fd = SdpSupport.createSocket(); + return sun.nio.ch.Secrets.newSocketChannel(fd); + } + + /** + * Opens a socket channel to a SDP socket. + * + *

The channel will be associated with the system-wide default + * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}. + * + * @return a new ServerSocketChannel + * + * @throws UnsupportedOperationException + * If SDP is not supported or not supported by the default selector + * provider + * @throws IOException + * If an I/O error occurs + */ + public static ServerSocketChannel openServerSocketChannel() + throws IOException + { + FileDescriptor fd = SdpSupport.createSocket(); + return sun.nio.ch.Secrets.newServerSocketChannel(fd); + } +} diff --git a/jdk/src/share/classes/java/net/SdpSocketImpl.java b/jdk/src/share/classes/java/net/SdpSocketImpl.java new file mode 100644 index 00000000000..b5b023e2433 --- /dev/null +++ b/jdk/src/share/classes/java/net/SdpSocketImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 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. + */ + +package java.net; + +import java.io.IOException; +import java.io.FileDescriptor; + +import sun.net.sdp.SdpSupport; + +/** + * SocketImpl that supports the SDP protocol + */ +class SdpSocketImpl extends PlainSocketImpl { + SdpSocketImpl() { } + + @Override + protected void create(boolean stream) throws IOException { + if (!stream) + throw new UnsupportedOperationException("Must be a stream socket"); + fd = SdpSupport.createSocket(); + if (socket != null) + socket.setCreated(); + if (serverSocket != null) + serverSocket.setCreated(); + } +} diff --git a/jdk/src/share/classes/java/net/ServerSocket.java b/jdk/src/share/classes/java/net/ServerSocket.java index 8189d8aa4f0..d4b44e4ccb2 100644 --- a/jdk/src/share/classes/java/net/ServerSocket.java +++ b/jdk/src/share/classes/java/net/ServerSocket.java @@ -68,6 +68,15 @@ class ServerSocket implements java.io.Closeable { */ private boolean oldImpl = false; + /** + * Package-private constructor to create a ServerSocket associated with + * the given SocketImpl. + */ + ServerSocket(SocketImpl impl) { + this.impl = impl; + impl.setServerSocket(this); + } + /** * Creates an unbound server socket. * diff --git a/jdk/src/share/classes/sun/net/sdp/SdpSupport.java b/jdk/src/share/classes/sun/net/sdp/SdpSupport.java new file mode 100644 index 00000000000..5baca6e4925 --- /dev/null +++ b/jdk/src/share/classes/sun/net/sdp/SdpSupport.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2010, 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. + */ + +package sun.net.sdp; + +import java.io.IOException; +import java.io.FileDescriptor; +import java.security.AccessController; + +import sun.misc.SharedSecrets; +import sun.misc.JavaIOFileDescriptorAccess; + + +/** + * This class defines methods for creating SDP sockets or "converting" existing + * file descriptors, referencing (unbound) TCP sockets, to SDP. + */ + +public final class SdpSupport { + private static final String os = AccessController + .doPrivileged(new sun.security.action.GetPropertyAction("os.name")); + private static final boolean isSupported = (os.equals("SunOS") || (os.equals("Linux"))); + private static final JavaIOFileDescriptorAccess fdAccess = + SharedSecrets.getJavaIOFileDescriptorAccess(); + + private SdpSupport() { } + + /** + * Creates a SDP socket, returning file descriptor referencing the socket. + */ + public static FileDescriptor createSocket() throws IOException { + if (!isSupported) + throw new UnsupportedOperationException("SDP not supported on this platform"); + int fdVal = create0(); + FileDescriptor fd = new FileDescriptor(); + fdAccess.set(fd, fdVal); + return fd; + } + + /** + * Converts an existing file descriptor, that references an unbound TCP socket, + * to SDP. + */ + public static void convertSocket(FileDescriptor fd) throws IOException { + if (!isSupported) + throw new UnsupportedOperationException("SDP not supported on this platform"); + int fdVal = fdAccess.get(fd); + convert0(fdVal); + } + + private static native int create0() throws IOException; + + private static native void convert0(int fd) throws IOException; + + static { + AccessController.doPrivileged( + new sun.security.action.LoadLibraryAction("net")); + } +} diff --git a/jdk/src/share/classes/sun/nio/ch/Secrets.java b/jdk/src/share/classes/sun/nio/ch/Secrets.java new file mode 100644 index 00000000000..f76ab1d75a0 --- /dev/null +++ b/jdk/src/share/classes/sun/nio/ch/Secrets.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010, 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. + */ + +package sun.nio.ch; + +import java.nio.channels.SocketChannel; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.spi.SelectorProvider; +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * Provides access to implementation private constructors and methods. + */ + +public final class Secrets { + private Secrets() { } + + private static SelectorProvider provider() { + SelectorProvider p = SelectorProvider.provider(); + if (!(p instanceof SelectorProviderImpl)) + throw new UnsupportedOperationException(); + return p; + } + + public static SocketChannel newSocketChannel(FileDescriptor fd) { + try { + return new SocketChannelImpl(provider(), fd, false); + } catch (IOException ioe) { + throw new AssertionError(ioe); + } + } + + public static ServerSocketChannel newServerSocketChannel(FileDescriptor fd) { + try { + return new ServerSocketChannelImpl(provider(), fd, false); + } catch (IOException ioe) { + throw new AssertionError(ioe); + } + } +} diff --git a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java index 8df9ae4ca4a..3685d3a7c68 100644 --- a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java @@ -80,21 +80,24 @@ class ServerSocketChannelImpl // -- End of fields protected by stateLock - public ServerSocketChannelImpl(SelectorProvider sp) throws IOException { + ServerSocketChannelImpl(SelectorProvider sp) throws IOException { super(sp); this.fd = Net.serverSocket(true); this.fdVal = IOUtil.fdVal(fd); this.state = ST_INUSE; } - public ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd) + ServerSocketChannelImpl(SelectorProvider sp, + FileDescriptor fd, + boolean bound) throws IOException { super(sp); this.fd = fd; this.fdVal = IOUtil.fdVal(fd); this.state = ST_INUSE; - localAddress = Net.localAddress(fd); + if (bound) + localAddress = Net.localAddress(fd); } public ServerSocket socket() { diff --git a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java index 7d42d7d0096..c8b93b7c6f7 100644 --- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -103,6 +103,19 @@ class SocketChannelImpl this.state = ST_UNCONNECTED; } + SocketChannelImpl(SelectorProvider sp, + FileDescriptor fd, + boolean bound) + throws IOException + { + super(sp); + this.fd = fd; + this.fdVal = IOUtil.fdVal(fd); + this.state = ST_UNCONNECTED; + if (bound) + this.localAddress = Net.localAddress(fd); + } + // Constructor for sockets obtained from server sockets // SocketChannelImpl(SelectorProvider sp, diff --git a/jdk/src/solaris/classes/sun/net/NetHooks.java b/jdk/src/solaris/classes/sun/net/NetHooks.java index 06a11e54264..bc4a60b72eb 100644 --- a/jdk/src/solaris/classes/sun/net/NetHooks.java +++ b/jdk/src/solaris/classes/sun/net/NetHooks.java @@ -73,28 +73,7 @@ public final class NetHooks { * be changed to use the ServiceLoader facility to allow the deployment of * other providers. */ - private static Provider loadProvider(final String cn) { - return AccessController - .doPrivileged(new PrivilegedAction() { - @Override public Provider run() { - Class c; - try { - c = (Class)Class.forName(cn, true, null); - } catch (ClassNotFoundException x) { - return null; - } - try { - return c.newInstance(); - } catch (IllegalAccessException x) { - throw new AssertionError(x); - } catch (InstantiationException x) { - throw new AssertionError(x); - } - }}); - } - private static final Provider provider = AccessController - .doPrivileged(new GetPropertyAction("os.name")).equals("SunOS") ? - loadProvider("sun.net.spi.SdpProvider") : null; + private static final Provider provider = new sun.net.sdp.SdpProvider(); /** * Invoke prior to binding a TCP socket. @@ -104,8 +83,7 @@ public final class NetHooks { int port) throws IOException { - if (provider != null) - provider.implBeforeTcpBind(fdObj, address, port); + provider.implBeforeTcpBind(fdObj, address, port); } /** @@ -116,7 +94,6 @@ public final class NetHooks { int port) throws IOException { - if (provider != null) - provider.implBeforeTcpConnect(fdObj, address, port); + provider.implBeforeTcpConnect(fdObj, address, port); } } diff --git a/jdk/src/solaris/classes/sun/net/spi/SdpProvider.java b/jdk/src/solaris/classes/sun/net/sdp/SdpProvider.java similarity index 95% rename from jdk/src/solaris/classes/sun/net/spi/SdpProvider.java rename to jdk/src/solaris/classes/sun/net/sdp/SdpProvider.java index b2e7a0f591b..0fcec598726 100644 --- a/jdk/src/solaris/classes/sun/net/spi/SdpProvider.java +++ b/jdk/src/solaris/classes/sun/net/sdp/SdpProvider.java @@ -23,7 +23,7 @@ * questions. */ -package sun.net.spi; +package sun.net.sdp; import sun.net.NetHooks; import java.net.InetAddress; @@ -34,9 +34,10 @@ import java.io.File; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintStream; +import java.security.AccessController; -import sun.misc.SharedSecrets; -import sun.misc.JavaIOFileDescriptorAccess; +import sun.net.sdp.SdpSupport; +import sun.security.action.GetPropertyAction; /** * A NetHooks provider that converts sockets from the TCP to SDP protocol prior @@ -44,9 +45,6 @@ import sun.misc.JavaIOFileDescriptorAccess; */ public class SdpProvider extends NetHooks.Provider { - private static final JavaIOFileDescriptorAccess fdAccess = - SharedSecrets.getJavaIOFileDescriptorAccess(); - // maximum port private static final int MAX_PORT = 65535; @@ -59,7 +57,8 @@ public class SdpProvider extends NetHooks.Provider { public SdpProvider() { // if this property is not defined then there is nothing to do. - String file = System.getProperty("com.sun.sdp.conf"); + String file = AccessController.doPrivileged( + new GetPropertyAction("com.sun.sdp.conf")); if (file == null) { this.enabled = false; this.rules = null; @@ -78,7 +77,8 @@ public class SdpProvider extends NetHooks.Provider { // check if debugging is enabled PrintStream out = null; - String logfile = System.getProperty("com.sun.sdp.debug"); + String logfile = AccessController.doPrivileged( + new GetPropertyAction("com.sun.sdp.debug")); if (logfile != null) { out = System.out; if (logfile.length() > 0) { @@ -297,8 +297,7 @@ public class SdpProvider extends NetHooks.Provider { boolean matched = false; for (Rule rule: rules) { if (rule.match(action, address, port)) { - int fd = fdAccess.get(fdObj); - convert(fd); + SdpSupport.convertSocket(fdObj); matched = true; break; } @@ -333,7 +332,4 @@ public class SdpProvider extends NetHooks.Provider { if (enabled) convertTcpToSdpIfMatch(fdObj, Action.CONNECT, address, port); } - - // -- native methods -- - private static native void convert(int fd) throws IOException; } diff --git a/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java b/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java index a834f6f31df..ff51aa052ca 100644 --- a/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java +++ b/jdk/src/solaris/classes/sun/nio/ch/InheritedChannel.java @@ -96,7 +96,7 @@ class InheritedChannel { FileDescriptor fd) throws IOException { - super(sp, fd); + super(sp, fd, true); } protected void implCloseSelectableChannel() throws IOException { diff --git a/jdk/src/solaris/native/sun/net/spi/SdpProvider.c b/jdk/src/solaris/native/sun/net/sdp/SdpSupport.c similarity index 66% rename from jdk/src/solaris/native/sun/net/spi/SdpProvider.c rename to jdk/src/solaris/native/sun/net/sdp/SdpSupport.c index 5b927404606..dd2750be5f7 100644 --- a/jdk/src/solaris/native/sun/net/spi/SdpProvider.c +++ b/jdk/src/solaris/native/sun/net/sdp/SdpSupport.c @@ -25,9 +25,16 @@ #include #include +#include -#if defined(__solaris__) && !defined(PROTO_SDP) -#define PROTO_SDP 257 +#if defined(__solaris__) + #if !defined(PROTO_SDP) + #define PROTO_SDP 257 + #endif +#elif defined(__linux__) + #if !defined(AF_INET_SDP) + #define AF_INET_SDP 27 + #endif #endif #include "jni.h" @@ -40,20 +47,61 @@ } while((_result == -1) && (errno == EINTR)); \ } while(0) -JNIEXPORT void JNICALL -Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd) + +/** + * Creates a SDP socket. + */ +static int create(JNIEnv* env) { -#ifdef PROTO_SDP -#ifdef AF_INET6 + int s; + +#if defined(__solaris__) + #ifdef AF_INET6 int domain = ipv6_available() ? AF_INET6 : AF_INET; -#else + #else int domain = AF_INET; + #endif + s = socket(domain, SOCK_STREAM, PROTO_SDP); +#elif defined(__linux__) + /** + * IPv6 not supported by SDP on Linux + */ + if (ipv6_available()) { + JNU_ThrowIOException(env, "IPv6 not supported"); + return; + } + s = socket(AF_INET_SDP, SOCK_STREAM, 0); +#else + /* not supported on other platforms at this time */ + s = -1; + errno = EPROTONOSUPPORT; #endif - int s = socket(domain, SOCK_STREAM, PROTO_SDP); - if (s < 0) { + + if (s < 0) JNU_ThrowIOExceptionWithLastError(env, "socket"); - } else { - int arg, len, res; + return s; +} + +/** + * Creates a SDP socket, returning file descriptor referencing the socket. + */ +JNIEXPORT jint JNICALL +Java_sun_net_sdp_SdpSupport_create0(JNIEnv *env, jclass cls) +{ + return create(env); +} + +/** + * Converts an existing file descriptor, that references an unbound TCP socket, + * to SDP. + */ +JNIEXPORT void JNICALL +Java_sun_net_sdp_SdpSupport_convert0(JNIEnv *env, jclass cls, int fd) +{ + int s = create(env); + if (s >= 0) { + socklen_t len; + int arg, res; struct linger linger; /* copy socket options that are relevant to SDP */ @@ -72,7 +120,4 @@ Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd) JNU_ThrowIOExceptionWithLastError(env, "dup2"); RESTARTABLE(close(s), res); } -#else - JNU_ThrowInternalError(env, "should not reach here"); -#endif } diff --git a/jdk/test/com/oracle/net/Sanity.java b/jdk/test/com/oracle/net/Sanity.java new file mode 100644 index 00000000000..c4c97152779 --- /dev/null +++ b/jdk/test/com/oracle/net/Sanity.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2010, 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. + */ + +import com.oracle.net.Sdp; + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.*; + +/** + * Exercise com.oracle.net.Sdp with each IP address plumbed to InfiniBand + * interfaces listed in a given file. + */ + +public class Sanity { + public static void main(String[] args) throws Exception { + // The file is a list of interfaces to test. + Scanner s = new Scanner(new File(args[0])); + try { + while (s.hasNextLine()) { + String link = s.nextLine(); + NetworkInterface ni = NetworkInterface.getByName(link); + if (ni != null) { + Enumeration addrs = ni.getInetAddresses(); + while (addrs.hasMoreElements()) { + InetAddress addr = addrs.nextElement(); + System.out.format("Testing %s: %s\n", link, addr.getHostAddress()); + test(addr); + } + } + } + } finally { + s.close(); + } + } + + static void test(InetAddress addr) throws Exception { + // Test SocketChannel and ServerSocketChannel + ServerSocketChannel ssc = Sdp.openServerSocketChannel(); + try { + ssc.socket().bind(new InetSocketAddress(addr, 0)); + int port = ssc.socket().getLocalPort(); + + // SocketChannel.connect (implicit bind) + SocketChannel client = Sdp.openSocketChannel(); + try { + client.connect(new InetSocketAddress(addr, port)); + SocketChannel peer = ssc.accept(); + try { + testConnection(Channels.newOutputStream(client), + Channels.newInputStream(peer)); + } finally { + peer.close(); + } + } finally { + client.close(); + } + + // SocketChannel.connect (explicit bind) + client = Sdp.openSocketChannel(); + try { + client.socket().bind(new InetSocketAddress(addr, 0)); + client.connect(new InetSocketAddress(addr, port)); + ssc.accept().close(); + } finally { + client.close(); + } + } finally { + ssc.close(); + } + + // Test Socket and ServerSocket + ServerSocket ss = Sdp.openServerSocket(); + try { + ss.bind(new InetSocketAddress(addr, 0)); + int port = ss.getLocalPort(); + + // Socket.connect (implicit bind) + Socket s = Sdp.openSocket(); + try { + s.connect(new InetSocketAddress(addr, port)); + Socket peer = ss.accept(); + try { + testConnection(s.getOutputStream(), peer.getInputStream()); + } finally { + peer.close(); + } + } finally { + s.close(); + } + + // Socket.connect (explicit bind) + s = Sdp.openSocket(); + try { + s.bind(new InetSocketAddress(addr, 0)); + s.connect(new InetSocketAddress(addr, port)); + ss.accept().close(); + } finally { + s.close(); + } + } finally { + ss.close(); + } + } + + static void testConnection(OutputStream out, InputStream in) + throws IOException + { + byte[] msg = "hello".getBytes(); + out.write(msg); + + byte[] ba = new byte[100]; + int nread = 0; + while (nread < msg.length) { + int n = in.read(ba); + if (n < 0) + throw new IOException("EOF not expected!"); + nread += n; + } + } +} diff --git a/jdk/test/com/oracle/net/sanity.sh b/jdk/test/com/oracle/net/sanity.sh new file mode 100644 index 00000000000..b54d866b4fa --- /dev/null +++ b/jdk/test/com/oracle/net/sanity.sh @@ -0,0 +1,66 @@ +# +# Copyright (c) 2010, 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 6965072 +# @summary Unit test for SDP support +# @build Sanity +# @run shell sanity.sh + +IB_LINKS=ib.links + +OS=`uname -s` +case "$OS" in + SunOS ) + /usr/sbin/dladm show-part -o LINK -p > ${IB_LINKS} + if [ $? != 0 ]; then + echo "Unable to get InfiniBand parition link information" + exit 0 + fi + ;; + Linux ) + if [ ! -f /proc/net/sdp ]; then + echo "InfiniBand SDP module not installed" + exit 0 + fi + egrep "^[ \t]+ib" /proc/net/dev|cut -d':' -f1|tr -d '\t ' > ${IB_LINKS} + ;; + * ) + echo "This test only runs on Solaris or Linux" + exit 0 + ;; +esac + +if [ -z "$TESTJAVA" ]; then + JAVA=java + TESTCLASSES=. + TESTSRC=. +else + JAVA="${TESTJAVA}/bin/java" +fi + +CLASSPATH=${TESTCLASSES}:${TESTSRC} +export CLASSPATH + +# Run sanity test (IPv4-only for now) +$JAVA -Djava.net.preferIPv4Stack=true Sanity ${IB_LINKS} diff --git a/jdk/test/sun/net/sdp/ProbeIB.java b/jdk/test/sun/net/sdp/ProbeIB.java index 34244b84b0d..0f1535fce14 100644 --- a/jdk/test/sun/net/sdp/ProbeIB.java +++ b/jdk/test/sun/net/sdp/ProbeIB.java @@ -34,21 +34,16 @@ import java.util.Enumeration; public class ProbeIB { public static void main(String[] args) throws IOException { - Scanner s = new Scanner(new File("/etc/path_to_inst")); + Scanner s = new Scanner(new File(args[0])); try { while (s.hasNextLine()) { - String line = s.nextLine(); - if (line.startsWith("#")) - continue; - String[] fields = line.split("\\s+"); - if (!fields[2].equals("\"ibd\"")) - continue; - String name = fields[2].substring(1, fields[2].length()-1) + fields[1]; - NetworkInterface ni = NetworkInterface.getByName(name); + String link = s.nextLine(); + NetworkInterface ni = NetworkInterface.getByName(link); if (ni != null) { Enumeration addrs = ni.getInetAddresses(); while (addrs.hasMoreElements()) { - System.out.println(addrs.nextElement().getHostAddress()); + InetAddress addr = addrs.nextElement(); + System.out.println(addr.getHostAddress()); } } } diff --git a/jdk/test/sun/net/sdp/sanity.sh b/jdk/test/sun/net/sdp/sanity.sh index e1a209ba347..f35425b46f2 100644 --- a/jdk/test/sun/net/sdp/sanity.sh +++ b/jdk/test/sun/net/sdp/sanity.sh @@ -33,14 +33,15 @@ if [ "$OS" != "SunOS" ]; then echo "This is a Solaris-only test" exit 0 fi -SDPADM=/usr/sbin/sdpadm -if [ ! -f ${SDPADM} ]; then - echo "SDP not available" - exit 0 -fi -${SDPADM} status|grep Enabled -if [ $? != 0 ]; then - echo "SDP not enabled" + +IB_LINKS=ib.links +IB_ADDRS=ib.addrs + +# Display IB partition link information +# (requires Solaris 11, will fail on Solaris 10) +/usr/sbin/dladm show-part -o LINK -p > ${IB_LINKS} +if [ $? != 0 ]; then + echo "Unable to get IB parition link information" exit 0 fi @@ -56,13 +57,13 @@ CLASSPATH=${TESTCLASSES}:${TESTSRC} export CLASSPATH # Probe for IP addresses plumbed to IB interfaces -$JAVA -Djava.net.preferIPv4Stack=true ProbeIB > ib_addrs +$JAVA -Djava.net.preferIPv4Stack=true ProbeIB ${IB_LINKS} > ${IB_ADDRS} # Create sdp.conf SDPCONF=sdp.conf rm ${SDPCONF} touch ${SDPCONF} -cat ib_addrs | while read ADDR +cat ${IB_ADDRS} | while read ADDR do echo "bind ${ADDR} *" > ${SDPCONF} echo "connect ${ADDR} *" >> ${SDPCONF}