JDK-7155963 : Deadlock in SystemFlavorMap.getFlavorsForNative and SunToolkit.awtLock
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_2.6
  • CPU: x86
  • Submitted: 2012-03-22
  • Updated: 2015-09-29
  • Resolved: 2014-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b45Fixed
Related Reports
Relates :  
Description
I am observing a deadlock inside of AWT clipboard infrastructure when running NetBeans tests:

Found one Java-level deadlock:
=============================
"Test Watch Dog: testNodeAddingAndRemoving":
  waiting to lock monitor 0x00007f65f009fb68 (object 0x00000000fd2f5698, a java.awt.Component$AWTTreeLock),
  which is held by "AWT-EventQueue-0"
"AWT-EventQueue-0":
  waiting for ownable synchronizer 0x00000000fd334ed0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
  which is held by "AWT-XAWT"
"AWT-XAWT":
  waiting to lock monitor 0x00007f65e8003750 (object 0x00000000fd35cc68, a java.awt.datatransfer.SystemFlavorMap),
  which is held by "System clipboard synchronizer"
"System clipboard synchronizer":
  waiting for ownable synchronizer 0x00000000fd334ed0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
  which is held by "AWT-XAWT"

Java stack information for the threads listed above:
===================================================
"Test Watch Dog: testNodeAddingAndRemoving":
        at java.awt.Component.setFont(Component.java:1799)
        - waiting to lock <0x00000000fd2f5698> (a java.awt.Component$AWTTreeLock)
        at java.awt.Container.setFont(Container.java:1552)
        at javax.swing.JComponent.setFont(JComponent.java:2723)
        at javax.swing.LookAndFeel.installColorsAndFont(LookAndFeel.java:191)
        at javax.swing.plaf.basic.BasicViewportUI.installDefaults(BasicViewportUI.java:47)
        at javax.swing.plaf.basic.BasicViewportUI.installUI(BasicViewportUI.java:38)
        at javax.swing.JComponent.setUI(JComponent.java:662)
        at javax.swing.JViewport.setUI(JViewport.java:285)
        at javax.swing.JViewport.updateUI(JViewport.java:295)
        at javax.swing.JViewport.<init>(JViewport.java:255)
        at javax.swing.JScrollPane.createViewport(JScrollPane.java:905)
        at javax.swing.JScrollPane.<init>(JScrollPane.java:280)
        at javax.swing.JScrollPane.<init>(JScrollPane.java:333)
        at org.openide.explorer.view.ListView.<init>(ListView.java:219)
        at org.openide.explorer.view.ListViewTest$PListView.<init>(ListViewTest.java:299)
        at org.openide.explorer.view.ListViewTest$PListView.<init>(ListViewTest.java:299)
        at org.openide.explorer.view.ListViewTest.testNodeAddingAndRemoving(ListViewTest.java:257)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:99)
        at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:405)
        at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:331)
        at java.lang.Thread.run(Thread.java:662)
"AWT-EventQueue-0":
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000fd334ed0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178)
        at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
        at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
        at sun.awt.SunToolkit.awtLock(SunToolkit.java:234)
        at sun.awt.X11.XInputMethod.createXICNative(Native Method)
        at sun.awt.X11.XInputMethod.createXIC(XInputMethod.java:53)
        at sun.awt.X11InputMethod.activate(X11InputMethod.java:315)
        - locked <0x00000000fd35a510> (a sun.awt.X11.XInputMethod)
        at sun.awt.im.InputContext.activateInputMethod(InputContext.java:376)
        at sun.awt.im.InputContext.focusGained(InputContext.java:320)
        - locked <0x00000000fd35a488> (a sun.awt.im.InputMethodContext)
        - locked <0x00000000fd2f5698> (a java.awt.Component$AWTTreeLock)
        at sun.awt.im.InputContext.dispatchEvent(InputContext.java:227)
        at sun.awt.im.InputMethodContext.dispatchEvent(InputMethodContext.java:180)
        at java.awt.Component.dispatchEventImpl(Component.java:4587)
        at java.awt.Container.dispatchEventImpl(Container.java:2097)
        at java.awt.Component.dispatchEvent(Component.java:4481)
        at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1836)
        at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:901)
        at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:513)
        at java.awt.Component.dispatchEventImpl(Component.java:4525)
        at java.awt.Container.dispatchEventImpl(Container.java:2097)
        at java.awt.Component.dispatchEvent(Component.java:4481)
        at sun.awt.X11.XWindow$1.run(XWindow.java:380)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
        at java.awt.EventQueue.access$000(EventQueue.java:84)
        at java.awt.EventQueue$1.run(EventQueue.java:607)
        at java.awt.EventQueue$1.run(EventQueue.java:605)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
"AWT-XAWT":
        at java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative(SystemFlavorMap.java:792)
        - waiting to lock <0x00000000fd35cc68> (a java.awt.datatransfer.SystemFlavorMap)
        at sun.awt.datatransfer.DataTransferer.getFlavorsForFormatsAsSet(DataTransferer.java:846)
        at sun.awt.datatransfer.SunClipboard.formatArrayAsDataFlavorSet(SunClipboard.java:333)
        at sun.awt.datatransfer.SunClipboard.checkChange(SunClipboard.java:408)
        at sun.awt.X11.XClipboard.checkChange(XClipboard.java:104)
        at sun.awt.X11.XSelection.checkChange(XSelection.java:754)
        at sun.awt.X11.XSelection.access$200(XSelection.java:30)
        at sun.awt.X11.XSelection$SelectionEventHandler.dispatchEvent(XSelection.java:764)
        at sun.awt.X11.XToolkit.dispatchEvent(XToolkit.java:527)
        at sun.awt.X11.XToolkit.run(XToolkit.java:619)
        at sun.awt.X11.XToolkit.run(XToolkit.java:543)
        at java.lang.Thread.run(Thread.java:662)
"System clipboard synchronizer":
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000fd334ed0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178)
        at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
        at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
        at sun.awt.SunToolkit.awtLock(SunToolkit.java:234)
        at sun.awt.X11.XAtom.<init>(XAtom.java:252)
        at sun.awt.X11.XAtom.<init>(XAtom.java:219)
        at sun.awt.X11.XAtom.get(XAtom.java:161)
        at sun.awt.X11.XDataTransferer.getFormatForNativeAsLong(XDataTransferer.java:107)
        at sun.awt.datatransfer.DataTransferer.registerTextFlavorProperties(DataTransferer.java:560)
        at java.awt.datatransfer.SystemFlavorMap.parseAndStoreReader(SystemFlavorMap.java:378)
        at java.awt.datatransfer.SystemFlavorMap.initSystemFlavorMap(SystemFlavorMap.java:251)
        at java.awt.datatransfer.SystemFlavorMap.getNativeToFlavor(SystemFlavorMap.java:115)
        at java.awt.datatransfer.SystemFlavorMap.nativeToFlavorLookup(SystemFlavorMap.java:521)
        at java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative(SystemFlavorMap.java:821)
        - locked <0x00000000fd35cc68> (a java.awt.datatransfer.SystemFlavorMap)
        at sun.awt.datatransfer.DataTransferer.getFlavorsForFormats(DataTransferer.java:770)
        at sun.awt.datatransfer.ClipboardTransferable.<init>(ClipboardTransferable.java:72)
        at sun.awt.X11.XClipboard.getContents(XClipboard.java:84)
        - locked <0x00000000fd333b30> (a sun.awt.X11.XClipboard)
        at org.netbeans.NbClipboard.run(NbClipboard.java:315)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452)
        at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)

Found 1 deadlock.

Comments
That was line of business clarification: We are at RDP2 now and should only be considering release stoppers. So we are not considering to add this fix to 8u40. Please push to 8u-dev (8u60), I have open the back port
17-12-2014

8u40-critical-request justification: Issue impact: XToolkit deadlock, multiple reports from netbeans users Fix risk: low, only linux and solaris affected Webrev: http://cr.openjdk.java.net/~azvegint/jdk/9/7155963/00/ Review: http://mail.openjdk.java.net/pipermail/awt-dev/2014-December/008770.html JPRT: http://sthjprt.se.oracle.com/archives/2014/12/2014-12-16-142932.azvegint.jdk8u-dev/bundles/ Suggested testing: DnD and Clipboard tests on Linux and Solaris
16-12-2014

Yes, it is allowed to call Clipboard.getContents() outside the EDT. I see SelectionNotifyHandler usage in provided stacktrace [1]. sun.awt.X11.XClipboard$SelectionNotifyHandler.dispatchEvent(XClipboard.java:204) This handler is set only in SunClipboard.registerClipboardViewerChecked() which is called by SunClipboard.addFlavorListener() [2]. But at this point initSystemFlavorMap() should be already called by formatArrayAsDataFlavorSet() (called just before registerClipboardViewerChecked). at java.awt.datatransfer.SystemFlavorMap.initSystemFlavorMap(SystemFlavorMap.java:214) at java.awt.datatransfer.SystemFlavorMap.getNativeToFlavor(SystemFlavorMap.java:131) at java.awt.datatransfer.SystemFlavorMap.nativeToFlavorLookup(SystemFlavorMap.java:542) at java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative(SystemFlavorMap.java:840) at sun.awt.datatransfer.DataTransferer.getFlavorsForFormatsAsSet(DataTransferer.java:886) at sun.awt.datatransfer.SunClipboard.formatArrayAsDataFlavorSet(SunClipboard.java:352) at sun.awt.datatransfer.SunClipboard.addFlavorListener(SunClipboard.java:378) As I can see it can fail only in one case: if we pass a zero-length formats array to formatArrayAsDataFlavorSet() [3]. This may happen on some WM (I've managed to get zero-length array only once on XFCE). So the fix will be to temporarily release awtLock for SunClipboard.checkChange() call.
11-12-2014

We are still hitting this problem in NetBeans 8.0 (on Linux with JDK 8). Can you please confirm that it is allowed to call Clipboard.getContents() outside the EDT? And if it it isn't allow then please suggest a recommended way to access system clipboard without blocking EDT when large amount of data is in the system clipboard, thanks.
24-07-2014

jdk8b132, jdk9b16
09-06-2014

Alexander, please provide exact release build number (8? 9?) where are not reproduced.
09-06-2014

Cannot reproduce. Please provide steps to reproduce.
09-06-2014

Release team: Approved for deferral.
04-02-2014

Sergey, it seems deferral case, please proceed
04-02-2014

The same deadlock has been reported in NetBeans running on the latest dev build of JDK 8, please see here: https://netbeans.org/bugzilla/show_bug.cgi?id=240847 The deadlocked threads are listed here: https://netbeans.org/bugzilla/attachment.cgi?id=144584 Please re-evaluate, thanks.
04-02-2014

8-defer-request: not a regression, not a jck. Not a stopper for jdk8, should be fixed in 8u20.
04-02-2014

This issue is not applicable to jdk7 and jdk8 releases. The next revision http://hg.openjdk.java.net/jdk7u/jdk7u-dev-gate/jdk/rev/176e1fe7dead for fix JDK-6538066. Technically, this problem can still exists but for another stack trace. this part of the stack does not exist for now because of the decoupling. at sun.awt.datatransfer.SunClipboard.checkChange(SunClipboard.java:408) at sun.awt.X11.XClipboard.checkChange(XClipboard.java:104) I am transferring the issue to the sustaining team as a problem for jdk 6.
28-01-2013

WORK AROUND I will probably need to to workaround this on NetBeans side, but it is not easy. There is no NetBeans code on the stack of "AWT-XAWT" thread (to obtain SystemFlavorMap.class lock sooner than the sun.awt.SunToolkit.awtLock one. The calls in "System clibpoard synchronizer" are initialized from NbClipboard, but they cannot easily access sun.awt.SunToolkit.awtLock as it is not public and moreover it is platform dependent. As a result of the above, it would be the best to fix the deadlock in the JDK itself.
22-03-2012

PUBLIC COMMENTS java.awt.datatransfer.SystemFlavorMap.initSystemFlavorMap is a static synchronized method and it calls into sun.awt.X11.XAtom which tries to acquire sun.awt.SunToolkit.awtLock. However this lock can be hold by "AWT-XAWT" while it tries to call java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative as well.
22-03-2012