# HG changeset patch # User anashaty # Date 1433420670 -10800 # Node ID 0647b79041f25af6b152e5fe357932cea91b03a1 # Parent 3b8f5ca8938f296870650dae1ab5bce483339bf7 8078606: Deadlock in awt clipboard Reviewed-by: azvegint, bae diff -r 3b8f5ca8938f -r 0647b79041f2 jdk/src/java.desktop/unix/classes/sun/awt/X11/XClipboard.java --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XClipboard.java Wed Jun 03 18:26:06 2015 -0700 +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XClipboard.java Thu Jun 04 15:24:30 2015 +0300 @@ -156,19 +156,24 @@ isSelectionNotifyProcessed = true; boolean mustSchedule = false; - synchronized (XClipboard.classLock) { - if (targetsAtom2Clipboard == null) { - targetsAtom2Clipboard = new HashMap(2); + XToolkit.awtLock(); + try { + synchronized (XClipboard.classLock) { + if (targetsAtom2Clipboard == null) { + targetsAtom2Clipboard = new HashMap(2); + } + mustSchedule = targetsAtom2Clipboard.isEmpty(); + targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this); + if (mustSchedule) { + XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), + new SelectionNotifyHandler()); + } } - mustSchedule = targetsAtom2Clipboard.isEmpty(); - targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this); if (mustSchedule) { - XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), - new SelectionNotifyHandler()); + XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval()); } - } - if (mustSchedule) { - XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval()); + } finally { + XToolkit.awtUnlock(); } } diff -r 3b8f5ca8938f -r 0647b79041f2 jdk/src/java.desktop/unix/classes/sun/awt/X11/XRootWindow.java --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XRootWindow.java Wed Jun 03 18:26:06 2015 -0700 +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XRootWindow.java Thu Jun 04 15:24:30 2015 +0300 @@ -31,18 +31,22 @@ * common logical ancestor */ class XRootWindow extends XBaseWindow { - private static XRootWindow xawtRootWindow = null; - static XRootWindow getInstance() { - XToolkit.awtLock(); - try { - if (xawtRootWindow == null) { + private static class LazyHolder { + private static final XRootWindow xawtRootWindow; + + static { + XToolkit.awtLock(); + try { xawtRootWindow = new XRootWindow(); xawtRootWindow.init(xawtRootWindow.getDelayedParams().delete(DELAYED)); + } finally { + XToolkit.awtUnlock(); } - return xawtRootWindow; - } finally { - XToolkit.awtUnlock(); } + + } + static XRootWindow getInstance() { + return LazyHolder.xawtRootWindow; } private XRootWindow() {