changeset 7421:1a90de8005e3 jdk7u60-b12

Merge
author lana
date Wed, 19 Mar 2014 10:41:46 -0700
parents b35c3fd4d5cf (current diff) 244159d35014 (diff)
children 06f771c9a7b7 79ed8f597afa 90077564c80e 476179253f0a
files
diffstat 9 files changed, 333 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/Toolkit.java	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/share/classes/java/awt/Toolkit.java	Wed Mar 19 10:41:46 2014 -0700
@@ -2559,30 +2559,26 @@
         public void firePropertyChange(final PropertyChangeEvent evt) {
             Object oldValue = evt.getOldValue();
             Object newValue = evt.getNewValue();
-            String propertyName = evt.getPropertyName();
             if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
                 return;
             }
-            Runnable updater = new Runnable() {
-                public void run() {
-                    PropertyChangeSupport pcs = (PropertyChangeSupport)
-                            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
-                    if (null != pcs) {
-                        pcs.firePropertyChange(evt);
-                    }
-                }
-            };
-            final AppContext currentAppContext = AppContext.getAppContext();
             for (AppContext appContext : AppContext.getAppContexts()) {
                 if (null == appContext || appContext.isDisposed()) {
                     continue;
                 }
-                if (currentAppContext == appContext) {
-                    updater.run();
-                } else {
-                    final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
-                    SunToolkit.postEvent(appContext, e);
-                }
+                final PeerEvent e = new PeerEvent(source,
+                        new Runnable() {
+                            @Override
+                            public void run() {
+                                PropertyChangeSupport pcs = (PropertyChangeSupport)
+                                        AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
+                                if (null != pcs) {
+                                    pcs.firePropertyChange(evt);
+                                }
+                            }
+                        },
+                        PeerEvent.ULTIMATE_PRIORITY_EVENT);
+                SunToolkit.postEvent(appContext, e);
             }
         }
     }
--- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Wed Mar 19 10:41:46 2014 -0700
@@ -574,6 +574,8 @@
         } else if (ret == JVM_IO_ERR) {
             if (errno == EBADF) {
                  JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else if (errno == ENOMEM) {
+                 JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
             } else {
                  NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed");
             }
@@ -674,15 +676,18 @@
                             "Receive timed out");
             return -1;
         } else if (ret == JVM_IO_ERR) {
+            if (errno == ENOMEM) {
+                JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
 #ifdef __linux__
-            if (errno == EBADF) {
+            } else if (errno == EBADF) {
                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
             } else {
                 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+#else
+            } else {
+                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+#endif
             }
-#else
-            JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
-#endif
             return -1;
         } else if (ret == JVM_IO_INTR) {
             JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
@@ -910,15 +915,18 @@
                     JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
                                     "Receive timed out");
                 } else if (ret == JVM_IO_ERR) {
+                     if (errno == ENOMEM) {
+                        JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
 #ifdef __linux__
-                    if (errno == EBADF) {
+                     } else if (errno == EBADF) {
                          JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
                      } else {
                          NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
+#else
+                     } else {
+                         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+#endif
                      }
-#else
-                     JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
-#endif
                 } else if (ret == JVM_IO_INTR) {
                     JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
                                     "operation interrupted");
--- a/src/solaris/native/java/net/PlainSocketImpl.c	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/solaris/native/java/net/PlainSocketImpl.c	Wed Mar 19 10:41:46 2014 -0700
@@ -708,7 +708,6 @@
         } else {
             ret = NET_Timeout(fd, timeout);
         }
-
         if (ret == 0) {
             JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
                             "Accept timed out");
@@ -716,6 +715,8 @@
         } else if (ret == JVM_IO_ERR) {
             if (errno == EBADF) {
                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+            } else if (errno == ENOMEM) {
+               JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
             } else {
                NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
             }
--- a/src/solaris/native/java/net/SocketInputStream.c	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/solaris/native/java/net/SocketInputStream.c	Wed Mar 19 10:41:46 2014 -0700
@@ -108,6 +108,8 @@
             } else if (nread == JVM_IO_ERR) {
                 if (errno == EBADF) {
                      JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+                 } else if (errno == ENOMEM) {
+                     JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
                  } else {
                      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                                                   "select/poll failed");
--- a/src/solaris/native/java/net/bsd_close.c	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/solaris/native/java/net/bsd_close.c	Wed Mar 19 10:41:46 2014 -0700
@@ -25,6 +25,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/param.h>
 #include <signal.h>
 #include <pthread.h>
 #include <sys/types.h>
@@ -35,7 +36,6 @@
 #include <sys/uio.h>
 #include <unistd.h>
 #include <errno.h>
-
 #include <sys/poll.h>
 
 /*
@@ -347,6 +347,10 @@
 int NET_Timeout(int s, long timeout) {
     long prevtime = 0, newtime;
     struct timeval t, *tp = &t;
+    fd_set fds;
+    fd_set* fdsp = NULL;
+    int allocated = 0;
+    threadEntry_t self;
     fdEntry_t *fdEntry = getFdEntry(s);
 
     /*
@@ -376,20 +380,29 @@
         t.tv_usec = 0;
     }
 
+    if (s < FD_SETSIZE) {
+        fdsp = &fds;
+        FD_ZERO(fdsp);
+    } else {
+        int length = (howmany(s+1, NFDBITS)) * sizeof(int);
+        fdsp = (fd_set *) calloc(1, length);
+        if (fdsp == NULL) {
+            return -1;   // errno will be set to ENOMEM
+        }
+        allocated = 1;
+    }
+    FD_SET(s, fdsp);
+
     for(;;) {
-        fd_set rfds;
         int rv;
-        threadEntry_t self;
 
         /*
          * call select on the fd. If interrupted by our wakeup signal
          * errno will be set to EBADF.
          */
-        FD_ZERO(&rfds);
-        FD_SET(s, &rfds);
 
         startOp(fdEntry, &self);
-        rv = select(s+1, &rfds, 0, 0, tp);
+        rv = select(s+1, fdsp, 0, 0, tp);
         endOp(fdEntry, &self);
 
         /*
@@ -403,6 +416,8 @@
                 newtime = now.tv_sec * 1000  +  now.tv_usec / 1000;
                 timeout -= newtime - prevtime;
                 if (timeout <= 0) {
+                    if (allocated != 0)
+                        free(fdsp);
                     return 0;
                 }
                 prevtime = newtime;
@@ -410,6 +425,8 @@
                 t.tv_usec = (timeout % 1000) * 1000;
             }
         } else {
+            if (allocated != 0)
+                free(fdsp);
             return rv;
         }
 
--- a/src/solaris/native/java/net/linux_close.c	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/solaris/native/java/net/linux_close.c	Wed Mar 19 10:41:46 2014 -0700
@@ -34,7 +34,6 @@
 #include <sys/uio.h>
 #include <unistd.h>
 #include <errno.h>
-
 #include <sys/poll.h>
 
 /*
--- a/src/windows/classes/sun/awt/windows/WToolkit.java	Wed Mar 19 10:04:23 2014 -0700
+++ b/src/windows/classes/sun/awt/windows/WToolkit.java	Wed Mar 19 10:41:46 2014 -0700
@@ -855,11 +855,7 @@
      * Windows doesn't always send WM_SETTINGCHANGE when it should.
      */
     private void windowsSettingChange() {
-        EventQueue.invokeLater(new Runnable() {
-            public void run() {
-                updateProperties();
-            }
-        });
+        updateProperties();
     }
 
     private synchronized void updateProperties() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Toolkit/ToolkitPropertyTest/NoAppContextTest.java	Wed Mar 19 10:41:46 2014 -0700
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ *
+ * 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 8032960
+ * @summary checks that desktop properties work if Toolkit thread has no AppContext
+ * @author Petr Pchelko
+ */
+
+import sun.awt.OSInfo;
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import java.awt.*;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class NoAppContextTest {
+
+    private static final ThreadGroup stubGroup = new ThreadGroup("stub");
+    private static final ThreadGroup awtGroup = new ThreadGroup("AWT");
+    private static final AtomicBoolean propertyChangeFired = new AtomicBoolean(false);
+    private static Frame frame;
+
+    private static final Object LOCK = new Object();
+
+    public static void main(String[] args) throws Exception {
+
+        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+            // The test is for Windows platform only
+            return;
+        }
+
+        createStubContext();
+
+        Thread awtThread = new Thread(awtGroup, new Runnable() {
+            @Override
+            public void run() {
+                SunToolkit.createNewAppContext();
+                SwingUtilities.invokeLater(new Runnable() {
+                    @Override
+                    public void run() {
+                        synchronized (LOCK) {
+                            frame = new Frame();
+                            frame.setBounds(100, 100, 100, 100);
+                            frame.setVisible(true);
+                            Toolkit.getDefaultToolkit().addPropertyChangeListener("win.propNames", new PropertyChangeListener() {
+                                @Override
+                                public void propertyChange(PropertyChangeEvent ev) {
+                                    propertyChangeFired.set(true);
+                                }
+                            });
+                        }
+                    }
+                });
+            }
+        });
+        awtThread.start();
+        awtThread.join();
+        sync();
+
+        final GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice();
+
+        final AtomicReference<DisplayMode> originalRef = new AtomicReference<>();
+        try {
+            final AtomicBoolean isSupported = new AtomicBoolean(true);
+            invokeInAWT(new Runnable() {
+                @Override
+                public void run() {
+                    if (device.isFullScreenSupported()) {
+                        device.setFullScreenWindow(frame);
+                    } else {
+                        isSupported.set(false);
+                    }
+                }
+            });
+            if (!isSupported.get()) {
+                return;
+            }
+            invokeInAWT(new Runnable() {
+                @Override
+                public void run() {
+                    if (device.isDisplayChangeSupported()) {
+                        DisplayMode original = device.getDisplayMode();
+                        originalRef.set(original);
+                        try {
+                            DisplayMode[] modes = device.getDisplayModes();
+                            for (DisplayMode mode : modes) {
+                                if (!mode.equals(original)) {
+                                    device.setDisplayMode(mode);
+                                    break;
+                                }
+                            }
+                        } finally {
+                            device.setDisplayMode(original);
+                        }
+                    } else {
+                        isSupported.set(false);
+                    }
+                }
+            });
+            if (!isSupported.get()) {
+                return;
+            }
+        } finally {
+            invokeInAWT(new Runnable() {
+                @Override
+                public void run() {
+                    device.setDisplayMode(originalRef.get());
+                    frame.dispose();
+                }
+            });
+        }
+
+        if (!propertyChangeFired.get()) {
+            throw new RuntimeException("Failed: PropertyChange did not fire");
+        }
+    }
+
+    private static void invokeInAWT(final Runnable r) throws InterruptedException {
+        Thread awtThread = new Thread(awtGroup, new Runnable() {
+            @Override
+            public void run() {
+                SwingUtilities.invokeLater(new Runnable() {
+                    @Override
+                    public void run() {
+                        synchronized (LOCK) {
+                            r.run();
+                        }
+                    }
+                });
+            }
+        });
+        awtThread.start();
+        awtThread.join();
+        sync();
+    }
+
+    private static void createStubContext() throws InterruptedException {
+        Thread stub = new Thread(stubGroup, new Runnable() {
+            @Override
+            public void run() {
+                SunToolkit.createNewAppContext();
+            }
+        });
+        stub.start();
+        stub.join();
+    }
+
+    /**
+     * Runs realSync on a thread with an AppContext and waits for it to finish
+     */
+    private static void sync() throws InterruptedException {
+        final AtomicReference<InterruptedException> exc = new AtomicReference<>(null);
+
+        Thread syncThread = new Thread(awtGroup, new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+                    Thread.sleep(2000);
+                } catch (InterruptedException e) {
+                    exc.set(e);
+                }
+            }
+        });
+        syncThread.start();
+        syncThread.join();
+        if (exc.get() != null) {
+            throw exc.get();
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/net/ServerSocket/AnotherSelectFdsLimit.java	Wed Mar 19 10:41:46 2014 -0700
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ *
+ * 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 8035897
+ * @summary FD_SETSIZE should be set on macosx
+ * @run main/othervm AnotherSelectFdsLimit 1023
+ * @run main/othervm AnotherSelectFdsLimit 1024
+ * @run main/othervm AnotherSelectFdsLimit 1025
+ * @run main/othervm AnotherSelectFdsLimit 1600
+ */
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AnotherSelectFdsLimit {
+    static final int DEFAULT_FDS_TO_USE = 1600;
+
+    public static void main(String [] args) throws Exception {
+        if (!System.getProperty("os.name").contains("OS X")) {
+            System.out.println("Test only run on MAC. Exiting.");
+            return;
+        }
+
+        int fdsToUse = DEFAULT_FDS_TO_USE;
+        if (args.length == 1)
+            fdsToUse = Integer.parseInt(args[0]);
+
+        System.out.println("Using " + fdsToUse + " fds.");
+
+        List<Thread> threads = new ArrayList<>();
+        for (int i=0; i<fdsToUse; i++)
+            threads.add(new WorkerThread());
+
+        for (Thread t : threads)
+            t.start();
+
+        for (Thread t : threads)
+            t.join();
+    }
+
+    static class WorkerThread extends Thread {
+        public void run() {
+            try (ServerSocket ss = new ServerSocket(0)) {
+                ss.setSoTimeout(2000);
+                ss.accept();
+            } catch (SocketTimeoutException x) {
+                // expected
+            } catch (IOException x) {
+                throw new RuntimeException(x);
+            }
+        }
+    }
+}