Merge
authorasaha
Tue, 15 Jun 2010 08:12:51 -0700
changeset 6858 8d04722ed7d2
parent 6857 a8683faf14f4 (current diff)
parent 5788 50d4ad1a780f (diff)
child 6859 0b0cdd787307
Merge
--- a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris	Tue Jun 15 08:12:51 2010 -0700
@@ -86,7 +86,7 @@
         java.security.AccessController.doPrivileged(
         new java.security.PrivilegedAction<Void>() { public Void run() {
             if (std_fds[0] == -1)
-                stdin_stream = new ProcessBuilder.NullOutputStream();
+                stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
             else {
                 FileDescriptor stdin_fd = new FileDescriptor();
                 fdAccess.set(stdin_fd, std_fds[0]);
@@ -95,7 +95,7 @@
             }
 
             if (std_fds[1] == -1)
-                stdout_stream = new ProcessBuilder.NullInputStream();
+                stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
             else {
                 FileDescriptor stdout_fd = new FileDescriptor();
                 fdAccess.set(stdout_fd, std_fds[1]);
@@ -104,7 +104,7 @@
             }
 
             if (std_fds[2] == -1)
-                stderr_stream = new ProcessBuilder.NullInputStream();
+                stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
             else {
                 FileDescriptor stderr_fd = new FileDescriptor();
                 fdAccess.set(stderr_fd, std_fds[2]);
--- a/jdk/src/windows/classes/java/lang/ProcessImpl.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/src/windows/classes/java/lang/ProcessImpl.java	Tue Jun 15 08:12:51 2010 -0700
@@ -159,7 +159,7 @@
         new java.security.PrivilegedAction<Void>() {
         public Void run() {
             if (stdHandles[0] == -1L)
-                stdin_stream = new ProcessBuilder.NullOutputStream();
+                stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
             else {
                 FileDescriptor stdin_fd = new FileDescriptor();
                 fdAccess.setHandle(stdin_fd, stdHandles[0]);
@@ -168,7 +168,7 @@
             }
 
             if (stdHandles[1] == -1L)
-                stdout_stream = new ProcessBuilder.NullInputStream();
+                stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
             else {
                 FileDescriptor stdout_fd = new FileDescriptor();
                 fdAccess.setHandle(stdout_fd, stdHandles[1]);
@@ -177,7 +177,7 @@
             }
 
             if (stdHandles[2] == -1L)
-                stderr_stream = new ProcessBuilder.NullInputStream();
+                stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
             else {
                 FileDescriptor stderr_fd = new FileDescriptor();
                 fdAccess.setHandle(stderr_fd, stdHandles[2]);
--- a/jdk/test/ProblemList.txt	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/ProblemList.txt	Tue Jun 15 08:12:51 2010 -0700
@@ -752,18 +752,9 @@
 #    at SetLastModified.main(SetLastModified.java:107)
 java/io/File/SetLastModified.java                               generic-all
 
-# Fails on Solaris 10 x64, address already in use
-java/nio/channels/DatagramChannel/SRTest.java			generic-all
-
-# Fails on Solaris 10 x86, times out
-java/nio/channels/DatagramChannel/Sender.java			generic-all
-
 # Fails on Fedora 9 x86, address in use
 java/nio/channels/Selector/SelectWrite.java			generic-all
 
-# Fails on Fedora 9 32bit times out
-java/nio/channels/DatagramChannel/EmptyBuffer.java		generic-all
-
 # Fails on Windows 2000,  times out
 java/nio/channels/FileChannel/Transfer.java			generic-all
 
@@ -821,12 +812,6 @@
 java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
 java/nio/channels/Channels/Basic2.java			 	windows-5.0
 
-# Solaris sparc timeout
-java/nio/channels/DatagramChannel/Connect.java		 	generic-all
-
-# Solaris i586 timeouts
-java/nio/channels/DatagramChannel/EmptyBuffer.java	 	solaris-all
-
 # Failed loopback connection? On windows 32bit? 
 #   Considered a stress test, can consume all resources.
 java/nio/channels/Selector/LotsOfChannels.java		 	generic-all
--- a/jdk/test/java/nio/channels/DatagramChannel/Connect.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/java/nio/channels/DatagramChannel/Connect.java	Tue Jun 15 08:12:51 2010 -0700
@@ -42,15 +42,15 @@
     }
 
     static void test() throws Exception {
-        invoke(new Actor(), new Reactor());
+        Reactor r = new Reactor();
+        Actor a = new Actor(r.port());
+        invoke(a, r);
     }
 
     static void invoke(Sprintable reader, Sprintable writer) throws Exception {
 
         Thread writerThread = new Thread(writer);
         writerThread.start();
-        while (!writer.ready())
-            Thread.sleep(50);
 
         Thread readerThread = new Thread(reader);
         readerThread.start();
@@ -64,34 +64,31 @@
 
     public interface Sprintable extends Runnable {
         public void throwException() throws Exception;
-        public boolean ready();
     }
 
     public static class Actor implements Sprintable {
+        final int port;
         Exception e = null;
 
+        Actor(int port) {
+            this.port = port;
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
         }
 
-        private volatile boolean ready = false;
-
-        public boolean ready() {
-            return ready;
-        }
-
         public void run() {
             try {
                 DatagramChannel dc = DatagramChannel.open();
-                ready = true;
 
                 // Send a message
                 ByteBuffer bb = ByteBuffer.allocateDirect(256);
                 bb.put("hello".getBytes());
                 bb.flip();
                 InetAddress address = InetAddress.getLocalHost();
-                InetSocketAddress isa = new InetSocketAddress(address, 8888);
+                InetSocketAddress isa = new InetSocketAddress(address, port);
                 dc.connect(isa);
                 dc.write(bb);
 
@@ -123,26 +120,26 @@
     }
 
     public static class Reactor implements Sprintable {
+        final DatagramChannel dc;
         Exception e = null;
 
+        Reactor() throws IOException {
+            dc = DatagramChannel.open().bind(new InetSocketAddress(0));
+        }
+
+        int port() {
+            return dc.socket().getLocalPort();
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
         }
 
-        private volatile boolean ready = false;
-
-        public boolean ready() {
-            return ready;
-        }
-
         public void run() {
             try {
                 // Listen for a message
-                DatagramChannel dc = DatagramChannel.open();
-                dc.socket().bind(new InetSocketAddress(8888));
                 ByteBuffer bb = ByteBuffer.allocateDirect(100);
-                ready = true;
                 SocketAddress sa = dc.receive(bb);
                 bb.flip();
                 CharBuffer cb = Charset.forName("US-ASCII").
--- a/jdk/test/java/nio/channels/DatagramChannel/EmptyBuffer.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/java/nio/channels/DatagramChannel/EmptyBuffer.java	Tue Jun 15 08:12:51 2010 -0700
@@ -42,18 +42,16 @@
     }
 
     static void test() throws Exception {
-        Sprintable server = new Server();
+        Server server = new Server();
         Thread serverThread = new Thread(server);
         serverThread.start();
-        while (!server.ready())
-            Thread.sleep(50);
         DatagramChannel dc = DatagramChannel.open();
         ByteBuffer bb = ByteBuffer.allocateDirect(12);
         bb.order(ByteOrder.BIG_ENDIAN);
         bb.putInt(1).putLong(1);
         bb.flip();
         InetAddress address = InetAddress.getLocalHost();
-        InetSocketAddress isa = new InetSocketAddress(address, 8888);
+        InetSocketAddress isa = new InetSocketAddress(address, server.port());
         dc.connect(isa);
         dc.write(bb);
         bb.rewind();
@@ -65,24 +63,23 @@
         server.throwException();
     }
 
-    public interface Sprintable extends Runnable {
-        public void throwException() throws Exception;
-        public boolean ready();
-    }
+    public static class Server implements Runnable {
+        final DatagramChannel dc;
+        Exception e = null;
 
-    public static class Server implements Sprintable {
-        Exception e = null;
-        private volatile boolean ready = false;
+        Server() throws IOException {
+            this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
+        }
 
-        public void throwException() throws Exception {
+        int port() {
+            return dc.socket().getLocalPort();
+        }
+
+        void throwException() throws Exception {
             if (e != null)
                 throw e;
         }
 
-        public boolean ready() {
-            return ready;
-        }
-
         void showBuffer(String s, ByteBuffer bb) {
             log.println(s);
             bb.rewind();
@@ -97,9 +94,6 @@
             SocketAddress sa = null;
             int numberReceived = 0;
             try {
-                DatagramChannel dc = DatagramChannel.open();
-                dc.socket().bind(new InetSocketAddress(8888));
-                ready = true;
                 ByteBuffer bb = ByteBuffer.allocateDirect(12);
                 bb.clear();
                 // Only one clear. The buffer will be full after
--- a/jdk/test/java/nio/channels/DatagramChannel/NoSender.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/java/nio/channels/DatagramChannel/NoSender.java	Tue Jun 15 08:12:51 2010 -0700
@@ -33,7 +33,7 @@
 public class NoSender {
     public static void main(String argv[]) throws Exception {
         DatagramChannel dc = DatagramChannel.open();
-        dc.socket().bind(new InetSocketAddress(5441));
+        dc.socket().bind(new InetSocketAddress(0));
         dc.configureBlocking(false);
         ByteBuffer buf1 = ByteBuffer.allocateDirect(256);
         SocketAddress sa1 = dc.receive(buf1);
--- a/jdk/test/java/nio/channels/DatagramChannel/SRTest.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/java/nio/channels/DatagramChannel/SRTest.java	Tue Jun 15 08:12:51 2010 -0700
@@ -42,16 +42,23 @@
     }
 
     static void test() throws Exception {
-        invoke(new ClassicReader(), new ClassicWriter());
+        ClassicReader classicReader;
+        NioReader nioReader;
+
+        classicReader = new ClassicReader();
+        invoke(classicReader, new ClassicWriter(classicReader.port()));
         log.println("Classic RW: OK");
 
-        invoke(new ClassicReader(), new NioWriter());
+        classicReader = new ClassicReader();
+        invoke(classicReader, new NioWriter(classicReader.port()));
         log.println("Classic R, Nio W: OK");
 
-        invoke(new NioReader(), new ClassicWriter());
+        nioReader = new NioReader();
+        invoke(nioReader, new ClassicWriter(nioReader.port()));
         log.println("Classic W, Nio R: OK");
 
-        invoke(new NioReader(), new NioWriter());
+        nioReader = new NioReader();
+        invoke(nioReader, new NioWriter(nioReader.port()));
         log.println("Nio RW: OK");
     }
 
@@ -75,8 +82,13 @@
     }
 
     public static class ClassicWriter implements Sprintable {
+        final int port;
         Exception e = null;
 
+        ClassicWriter(int port) {
+            this.port = port;
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
@@ -89,7 +101,7 @@
                 byte[] data = dataString.getBytes();
                 InetAddress address = InetAddress.getLocalHost();
                 DatagramPacket dp = new DatagramPacket(data, data.length,
-                                                       address, 8888);
+                                                       address, port);
                 ds.send(dp);
                 Thread.sleep(50);
                 ds.send(dp);
@@ -100,8 +112,13 @@
     }
 
     public static class NioWriter implements Sprintable {
+        final int port;
         Exception e = null;
 
+        NioWriter(int port) {
+            this.port = port;
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
@@ -114,7 +131,7 @@
                 bb.put("hello".getBytes());
                 bb.flip();
                 InetAddress address = InetAddress.getLocalHost();
-                InetSocketAddress isa = new InetSocketAddress(address, 8888);
+                InetSocketAddress isa = new InetSocketAddress(address, port);
                 dc.send(bb, isa);
                 Thread.sleep(50);
                 dc.send(bb, isa);
@@ -125,8 +142,17 @@
     }
 
     public static class ClassicReader implements Sprintable {
+        final DatagramSocket ds;
         Exception e = null;
 
+        ClassicReader() throws IOException {
+            this.ds = new DatagramSocket();
+        }
+
+        int port() {
+            return ds.getLocalPort();
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
@@ -136,7 +162,6 @@
             try {
                 byte[] buf = new byte[256];
                 DatagramPacket dp = new DatagramPacket(buf, buf.length);
-                DatagramSocket ds = new DatagramSocket(8888);
                 ds.receive(dp);
                 String received = new String(dp.getData());
                 log.println(received);
@@ -148,8 +173,17 @@
     }
 
     public static class NioReader implements Sprintable {
+        final DatagramChannel dc;
         Exception e = null;
 
+        NioReader() throws IOException {
+            this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
+        }
+
+        int port() {
+            return dc.socket().getLocalPort();
+        }
+
         public void throwException() throws Exception {
             if (e != null)
                 throw e;
@@ -157,8 +191,6 @@
 
         public void run() {
             try {
-                DatagramChannel dc = DatagramChannel.open();
-                dc.socket().bind(new InetSocketAddress(8888));
                 ByteBuffer bb = ByteBuffer.allocateDirect(100);
                 SocketAddress sa = dc.receive(bb);
                 bb.flip();
--- a/jdk/test/java/nio/channels/DatagramChannel/Sender.java	Sun Jun 13 07:40:36 2010 -0700
+++ b/jdk/test/java/nio/channels/DatagramChannel/Sender.java	Tue Jun 15 08:12:51 2010 -0700
@@ -42,13 +42,11 @@
     }
 
     static void test() throws Exception {
-        Sprintable server = new Server();
-        Sprintable client = new Client();
+        Server server = new Server();
+        Client client = new Client(server.port());
 
         Thread serverThread = new Thread(server);
         serverThread.start();
-        while (!server.ready())
-            Thread.sleep(50);
 
         Thread clientThread = new Thread(client);
         clientThread.start();
@@ -60,23 +58,17 @@
         client.throwException();
     }
 
-    public interface Sprintable extends Runnable {
-        public void throwException() throws Exception;
-        public boolean ready();
-    }
-
-    public static class Client implements Sprintable {
+    public static class Client implements Runnable {
+        final int port;
         Exception e = null;
 
-        public void throwException() throws Exception {
-            if (e != null)
-                throw e;
+        Client(int port) {
+            this.port = port;
         }
 
-        private volatile boolean ready = false;
-
-        public boolean ready() {
-            return ready;
+        void throwException() throws Exception {
+            if (e != null)
+                throw e;
         }
 
         public void run() {
@@ -87,7 +79,7 @@
                 bb.putInt(1).putLong(1);
                 bb.flip();
                 InetAddress address = InetAddress.getLocalHost();
-                InetSocketAddress isa = new InetSocketAddress(address, 8888);
+                InetSocketAddress isa = new InetSocketAddress(address, port);
                 dc.connect(isa);
                 dc.write(bb);
             } catch (Exception ex) {
@@ -96,19 +88,23 @@
         }
     }
 
-    public static class Server implements Sprintable {
+    public static class Server implements Runnable {
+        final DatagramChannel dc;
         Exception e = null;
-        private volatile boolean ready = false;
+
+        Server() throws IOException {
+            dc = DatagramChannel.open().bind(new InetSocketAddress(0));
+        }
 
-        public void throwException() throws Exception {
+        int port() {
+            return dc.socket().getLocalPort();
+        }
+
+        void throwException() throws Exception {
             if (e != null)
                 throw e;
         }
 
-        public boolean ready() {
-            return ready;
-        }
-
         void showBuffer(String s, ByteBuffer bb) {
             log.println(s);
             bb.rewind();
@@ -123,13 +119,10 @@
             SocketAddress sa = null;
 
             try {
-                DatagramChannel dc = DatagramChannel.open();
-                dc.socket().bind(new InetSocketAddress(8888));
-                dc.configureBlocking(false);
-                ready = true;
                 ByteBuffer bb = ByteBuffer.allocateDirect(12);
                 bb.clear();
                 // Get the one valid datagram
+                dc.configureBlocking(false);
                 while (sa == null)
                     sa = dc.receive(bb);
                 sa = null;