Swing app deadlocking

If I let my app run for a while the thing always locks up. It doesn’t happen in a predictable manor. I am just looping through the same code with no external input.

This is the thread dump for 1.4:


Full thread dump JFluid Client VM (based on Java HotSpot(TM) VM) (JF 1.3 mixed m
ode):

"DestroyJavaVM" prio=5 tid=0x008f0d10 nid=0x2d8 waiting on condition [0..6fb08]
Thread state: _thread_blocked
Thread: 0x008f0d10  [0x2d8] State: _at_safepoint  pc: 0x00000000

"Thread-1" prio=5 tid=0x183d2260 nid=0x300 runnable [3d8f000..3d8fdb4]
Thread state: _thread_blocked
Thread: 0x183d2260  [0x300] State: _call_back  pc: 0x00000000
        at javax.swing.RepaintManager.addDirtyRegion(RepaintManager.java:234)
        - waiting to lock <0x1051c7f8> (a javax.swing.RepaintManager)
        at javax.swing.JComponent.repaint(JComponent.java:4341)
        at java.awt.Component.repaint(Component.java:2408)
        at net.java.games.jogl.GLJPanel.display(GLJPanel.java:102)
        at net.java.games.jogl.Animator$1.run(Animator.java:104)
        at java.lang.Thread.run(Thread.java:534)

"Java2D Disposer" daemon prio=10 tid=0x183cbc40 nid=0x484 in Object.wait() [1a7af000..1a7afdb4]
Thread state: _thread_blocked
Thread: 0x183cbc40  [0x484] State: _at_safepoint  pc: 0x00000000
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105307b0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
        - locked <0x105307b0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
        at sun.java2d.Disposer.run(Disposer.java:100)
        at java.lang.Thread.run(Thread.java:534)

"AWT-EventQueue-0" prio=7 tid=0x183c9670 nid=0x48c runnable [1a76f000..1a76fdb4]

Thread state: _thread_blocked
Thread: 0x183c9670  [0x48c] State: _at_safepoint  pc: 0x00000000
        at sun.java2d.loops.Blit.Blit(Native Method)
        at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:640)
        at sun.java2d.pipe.DrawImage.renderSurfaceData(DrawImage.java:346)
        at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:66)
        at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:752)
        at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:154)
        at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:2692)
        at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2721)
        at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2678)
        at net.java.games.jogl.GLJPanel.paintComponent(GLJPanel.java:109)
        - locked <0x10521138> (a java.lang.Object)
        at javax.swing.JComponent.paint(JComponent.java:808)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4795)

        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4748)
        at javax.swing.JComponent._paintImmediately(JComponent.java:4692)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4495)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)

        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:117)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

"AWT-Shutdown" prio=7 tid=0x009df620 nid=0x434 in Object.wait() [1a72f000..1a72fdb4]
Thread state: _thread_blocked
Thread: 0x009df620  [0x434] State: _at_safepoint  pc: 0x00000000
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1050d000> (a java.lang.Object)
        at java.lang.Object.wait(Object.java:429)
        at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
        - locked <0x1050d000> (a java.lang.Object)
        at java.lang.Thread.run(Thread.java:534)

"AWT-Windows" daemon prio=7 tid=0x183bb9c8 nid=0x2cc runnable [1a62f000..1a62fdb4]
Thread state: _thread_in_native
Thread: 0x183bb9c8  [0x2cc] State: _at_safepoint  pc: 0x00000000
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(WToolkit.java:262)
        at java.lang.Thread.run(Thread.java:534)

"CompilerThread0" daemon prio=5 tid=0x0023d100 nid=0x23c waiting on condition [0..1822f9e4]
Thread state: _thread_blocked
Thread: 0x0023d100  [0x23c] State: _at_safepoint  pc: 0x00000000

"Signal Dispatcher" daemon prio=10 tid=0x00940e40 nid=0x128 waiting on condition
 [0..0]
Thread state: _thread_blocked
Thread: 0x00940e40  [0x128] State: _at_safepoint  pc: 0x00000000

"Finalizer" daemon prio=9 tid=0x0093d890 nid=0x3d8 in Object.wait() [1816f000..1816fdb4]
Thread state: _thread_blocked
Thread: 0x0093d890  [0x3d8] State: _at_safepoint  pc: 0x00000000
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1050d0e0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
        - locked <0x1050d0e0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x0093c3b0 nid=0x340 in Object.wait() [1812f000..1812fdb4]
Thread state: _thread_blocked
Thread: 0x0093c3b0  [0x340] State: _at_safepoint  pc: 0x00000000
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1050d148> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:429)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
        - locked <0x1050d148> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=5 tid=0x00991248 nid=0x2e0 runnable

"VM Periodic Task Thread" prio=10 tid=0x0023edb8 nid=0x4a0 waiting on condition


"Suspend Checker Thread" prio=10 tid=0x009404b0 nid=0x2d0 runnable

Compiler thread printing unimplemented.
JFluid: current dir is D:\java\jdk-windows\bin

Same app with jre 1.5.0

Thread dump for jre1.5.0


Full thread dump Java HotSpot(TM) Client VM (1.5.0-beta-b32c mixed mode):

"DestroyJavaVM" prio=5 tid=0x00236068 nid=0x2e0 waiting on condition [0x00000000..0x0006fae8]

"Thread-2" prio=5 tid=0x0351f730 nid=0x300 waiting for monitor entry [0x05b1f000..0x05b1fb64]
        at sun.awt.AppContext.get(Unknown Source)
        - waiting to lock <0x6e27f110> (a java.util.HashMap)
        at javax.swing.SwingUtilities.appContextGet(Unknown Source)
        at javax.swing.RepaintManager.currentManager(Unknown Source)
        at javax.swing.RepaintManager.currentManager(Unknown Source)
        at javax.swing.JComponent.repaint(Unknown Source)
        at java.awt.Component.repaint(Unknown Source)
        at net.java.games.jogl.GLJPanel.display(GLJPanel.java:102)
        at net.java.games.jogl.Animator$1.run(Animator.java:104)
        at java.lang.Thread.run(Unknown Source)

"AWT-EventQueue-0" prio=7 tid=0x00a4fea0 nid=0x434 waiting for monitor entry [0x0398f000..0x0398fbe4]
        at sun.awt.AppContext.get(Unknown Source)
        - waiting to lock <0x6e27f110> (a java.util.HashMap)
        at javax.swing.SwingUtilities.appContextGet(Unknown Source)
        at javax.swing.RepaintManager.currentManager(Unknown Source)
        at javax.swing.RepaintManager.currentManager(Unknown Source)
        at javax.swing.JComponent._paintImmediately(Unknown Source)
        at javax.swing.JComponent.paintImmediately(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknow
n Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

"AWT-Shutdown" prio=7 tid=0x00a4be88 nid=0x23c in Object.wait() [0x0388f000..0x0388fc64]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x6e271e40> (a java.lang.Object)
        at java.lang.Object.wait(Unknown Source)
        at sun.awt.AWTAutoShutdown.run(Unknown Source)
        - locked <0x6e271e40> (a java.lang.Object)
        at java.lang.Thread.run(Unknown Source)

"AWT-Windows" daemon prio=7 tid=0x00a4c100 nid=0x4a0 runnable [0x034bf000..0x034bfce4]
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"Java2D Disposer" daemon prio=10 tid=0x00a4a420 nid=0x340 in Object.wait() [0x032bf000..0x032bf9e4]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x6e29b658> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x6e29b658> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at sun.java2d.Disposer.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"Low Memory Detector" daemon prio=5 tid=0x009c9f50 nid=0x2d8 runnable [0x00000000..0x00000000]

"CompilerThread0" daemon prio=10 tid=0x009c8b98 nid=0x128 waiting on condition [0x00000000..0x00f8f854]

"Signal Dispatcher" daemon prio=10 tid=0x0023fe48 nid=0x4f8 waiting on condition
 [0x00000000..0x00000000]

"Finalizer" daemon prio=9 tid=0x009a1c68 nid=0x3d8 in Object.wait() [0x00d8f000..0x00d8fc64]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x6e271fe8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x6e271fe8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x009c6a18 nid=0x480 in Object.wait() [0x00c8f000..0x00c8fce4]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x6e272068> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Unknown Source)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <0x6e272068> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x009a0828 nid=0x2d0 runnable

"VM Periodic Task Thread" prio=10 tid=0x009cb168 nid=0x1a0 waiting on condition

I believe this is a known bug, fixed in beta2 (not yet available). Try to search on bug database for addDirtyRegion+deadlock, or something like that.

Your code (GLJPanel) is bugged.

at java.awt.Component.repaint(Component.java:2408)

at net.java.games.jogl.GLJPanel.display(GLJPanel.java:102)

Is not allowed. You must call SwingInvokeLater or similar to make that call. It must be made from the AWT event thread. I’ll bet that will make it work.

No it actually is bug 4837639 and I really need beta 2.

repaint() is among those few methods which can be called on any thread as it eventually posts a repaint event on EDT anyway.