Crashing in Java2D (JRE 1.6.0_01 on Win XP)

It’s not a game, but the people here know more about Java 2D quirks…

I’m getting reports of my application crashing and the hotspot error log file shows the crash is happening deep in a Java 2D blit loop. The stack trace is below.

Has anyone seen this before? Is it a known issue? A quick search didn’t find anything conclusive.

The app runs on Java 6 update 1 under Win XP. The crash log below is from a system with a Nvidia Quadro FX 1300 using older drivers (from 2005/07).

I’m going to try modifying my app launcher so that I set the noddraw flag to see if the crash can be avoided that way, and I will update the graphics drivers just in case they are the root of the issue. This issue doesn’t happen everywhere and can take some time to reproduce… so it’s going to take some time to get feedback.

Here’s the hs_err_pidXXXX.log file:

An unexpected error has been detected by Java Runtime Environment:

EXCEPTION_INVALID_HANDLE (0xc0000008) at pc=0x7c964ed1, pid=2100, tid=2848

Java VM: Java HotSpot™ Client VM (1.6.0_01-b06 mixed mode)

Problematic frame:

C [ntdll.dll+0x64ed1]

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

--------------- T H R E A D ---------------

Current thread (0x0c191800): JavaThread “AWT-EventQueue-0” [_thread_in_native, id=2848]

siginfo: ExceptionCode=0xc0000008

Registers:
EAX=0x0e75f15c, EBX=0x00000000, ECX=0x0e75f1a4, EDX=0x7c90eb94
ESP=0x0e75f15c, EBP=0x0e75f1ac, ESI=0x6d17c32c, EDI=0x00000000
EIP=0x7c964ed1, EFLAGS=0x00000246

Top of Stack: (sp=0x0e75f15c)
0x0e75f15c: c0000008 00000001 00000000 7c964ed1
0x0e75f16c: 00000000 7379adb6 737613c0 ffffffff
0x0e75f17c: 73775be2 73775c9b 001799a0 73775cb2
0x0e75f18c: 737a09e8 6d0e4ce8 00b21f64 0f2c9718
0x0e75f19c: 00000000 6d0f615e 7c90e9c0 7c91901b
0x0e75f1ac: 0e75f22c 7c94243c c0000008 6d17c344
0x0e75f1bc: 6d17c32c 7c901005 04c031a4 0c0c2960
0x0e75f1cc: 6d008c2c 0c1918e8 0c0c2960 0e75f1fc

Instructions: (pc=0x7c964ed1)
0x7c964ec1: 8d 45 b0 50 c7 45 b4 01 00 00 00 e8 db 9c fa ff
0x7c964ed1: c9 c2 04 00 90 90 90 90 90 8b ff 55 8b ec 53 56

Stack: [0x0e660000,0x0e760000), sp=0x0e75f15c, free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ntdll.dll+0x64ed1]
C [ntdll.dll+0x4243c]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J sun.java2d.windows.DDBlitLoops.Blit(Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;Ljava/awt/Composite;Lsun/java2d/pipe/Region;IIIIII)V
J sun.java2d.pipe.DrawImage.blitSurfaceData(Lsun/java2d/SunGraphics2D;Lsun/java2d/pipe/Region;Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;Lsun/java2d/loops/SurfaceType;Lsun/java2d/loops/SurfaceType;IIIIIILjava/awt/Color;)V
J sun.java2d.pipe.DrawImage.renderImageCopy(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;Ljava/awt/Color;IIIIII)Z
J sun.java2d.pipe.DrawImage.copyImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;IILjava/awt/Color;)Z
J sun.java2d.pipe.DrawImage.copyImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;IILjava/awt/Color;Ljava/awt/image/ImageObserver;)Z
J sun.java2d.pipe.ValidatePipe.copyImage(Lsun/java2d/SunGraphics2D;Ljava/awt/Image;IILjava/awt/Color;Ljava/awt/image/ImageObserver;)Z
J sun.java2d.SunGraphics2D.drawImage(Ljava/awt/Image;IILjava/awt/Color;Ljava/awt/image/ImageObserver;)Z
J sun.java2d.SunGraphics2D.drawImage(Ljava/awt/Image;IILjava/awt/image/ImageObserver;)Z
J javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Ljavax/swing/JComponent;Ljava/awt/Image;Ljava/awt/Graphics;IIII)V
J javax.swing.RepaintManager$PaintManager.paint(Ljavax/swing/JComponent;Ljavax/swing/JComponent;Ljava/awt/Graphics;IIII)Z
J javax.swing.BufferStrategyPaintManager.paint(Ljavax/swing/JComponent;Ljavax/swing/JComponent;Ljava/awt/Graphics;IIII)Z
J javax.swing.RepaintManager.paint(Ljavax/swing/JComponent;Ljavax/swing/JComponent;Ljava/awt/Graphics;IIII)V
J javax.swing.JComponent._paintImmediately(IIII)V
J javax.swing.JComponent.paintImmediately(IIII)V
J javax.swing.RepaintManager.paintDirtyRegions(Ljava/util/Map;)V
J javax.swing.RepaintManager.paintDirtyRegions()V
J javax.swing.RepaintManager.seqPaintDirtyRegions()V
J javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run()V
J java.awt.event.InvocationEvent.dispatch()V
J java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V
J java.awt.EventDispatchThread.pumpOneEventForFilters(I)Z
J java.awt.EventDispatchThread.pumpEventsForFilter(ILjava/awt/Conditional;Ljava/awt/EventFilter;)V
j java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+11
j java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j java.awt.EventDispatchThread.run()V+9
v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x0c20f800 JavaThread “DeckCaptureList” [_thread_blocked, id=2424]
0x0f2c7400 JavaThread “Thread-19” daemon [_thread_in_native, id=3052]
0x0f2c6400 JavaThread “pool-1-thread-1” [_thread_blocked, id=568]
0x0f2c5400 JavaThread “Thread-18” daemon [_thread_in_native, id=2604]
0x0ca12000 JavaThread “Thread-14” daemon [_thread_in_native, id=2920]
0x0c247400 JavaThread “KMR Status Poller” daemon [_thread_blocked, id=2928]
0x00a41c00 JavaThread “DestroyJavaVM” [_thread_blocked, id=2104]
=>0x0c191800 JavaThread “AWT-EventQueue-0” [_thread_in_native, id=2848]
0x0c1ff800 JavaThread “AWT-Shutdown” [_thread_blocked, id=2836]
0x0c16a400 JavaThread “com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2” daemon [_thread_blocked, id=2772]
0x0c16dc00 JavaThread “com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1” daemon [_thread_blocked, id=1084]
0x0c161800 JavaThread “com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0” daemon [_thread_blocked, id=2160]
0x0c187800 JavaThread “Timer-0” daemon [_thread_blocked, id=2712]
0x00b35400 JavaThread “WorkQueue” [_thread_blocked, id=2556]
0x0c961800 JavaThread “TimerQueue” daemon [_thread_blocked, id=2304]
0x0c93c800 JavaThread “AWT-Windows” daemon [_thread_in_native, id=2176]
0x0c93b000 JavaThread “Java2D Disposer” daemon [_thread_blocked, id=2168]
0x0c056000 JavaThread “Low Memory Detector” daemon [_thread_blocked, id=2164]
0x0c051400 JavaThread “CompilerThread0” daemon [_thread_blocked, id=656]
0x0c050400 JavaThread “Attach Listener” daemon [_thread_blocked, id=1596]
0x00b3f000 JavaThread “Signal Dispatcher” daemon [_thread_blocked, id=228]
0x00b3e000 JavaThread “Surrogate Locker Thread (CMS)” daemon [_thread_blocked, id=1612]
0x00b28000 JavaThread “Finalizer” daemon [_thread_blocked, id=2148]
0x00b23c00 JavaThread “Reference Handler” daemon [_thread_blocked, id=2152]

Other Threads:
0x00b20c00 VMThread [id=2140]
0x0c057400 WatcherThread [id=2172]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
par new generation total 14784K, used 3339K [0x032a0000, 0x042a0000, 0x042a0000)
eden space 13184K, 22% used [0x032a0000, 0x0358b958, 0x03f80000)
from space 1600K, 21% used [0x04110000, 0x04167318, 0x042a0000)
to space 1600K, 0% used [0x03f80000, 0x03f80000, 0x04110000)
concurrent mark-sweep generation total 49152K, used 13041K [0x042a0000, 0x072a0000, 0x072a0000)
concurrent-mark-sweep perm gen total 47916K, used 28980K [0x072a0000, 0x0a16b000, 0x0b2a0000)

Dynamic libraries:

VM Arguments:
jvm_args: -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=endorsed -Dswing.aatext=true -Dsun.swing.enableImprovedDragGesture
java_command: MyApplication.jar
Launcher Type: SUN_STANDARD

Environment Variables:
CLASSPATH=.;C:\Program Files\QuickTime\QTSystem\QTJava.zip
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem
USERNAME=SomeDude
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows XP Build 2600 Service Pack 2

CPU:total 2 family 15, cmov, cx8, fxsr, mmx, sse, sse2

Memory: 4k page, physical 2096088k(1247604k free), swap 3511508k(2574268k free)

vm_info: Java HotSpot™ Client VM (1.6.0_01-b06) for windows-x86, built on Mar 14 2007 00:24:02 by “java_re” with unknown MS VC++:1310

It turns out that an older version of the application that runs on Java 1.5 has similar problems. The Java2D Disposer thread crashes in sun.java2d.DefaultDisposerRecord.invokeNativeDispose due to either EXCEPTION_INVALID_HANDLE (0xc0000008) or Internal Error (0xc0000024). In other cases it crashes in sun.awt.windows.Win32OffScreenSurfaceData with the same Windows exception.

It’s almost like one thread is destroying a surface while another tries to access it.

I even have one case of java.net.SocketInputStream.socketRead0 crashing with Internal Error (0xc0000024) though… so maybe this isn’t so much a Java 2D issue? I still think it is related to window handles.

What a problem! ???

May I ask how you are doing your own rendering, is it in your own thread (which may conflict with Swing’s event dispatch thread?) or do you do SwingUtilities.invokeLater(…painting code here…)?

Keith

I try to do all of the manipulation of Swing objects like you say with invoke later. I do have a few threads that are updating the UI like that… but I thought I had that covered… I’m going to go over the code again just in case something slipped in. The project is worked on by several devs and some of them are less “event thread aware” :slight_smile: Though I have to admit I would never have expected this severe of a crash from that mistake. I figured a simple Java exception (NPE or out of bounds) because of corrupted state in the java objects.
I’m also using JNI to invoke native dialogs in third party libraries and for that I use JAWT to get the HWND to use as the parent for those dialogs.

To be honest I don’t think that its a threading issue, Java’s garbage collectors are thread-aware and the Java2Disposer is simply a ReferenveQueue waiting for dead objects (=not visible to any threads).

I guess the handles die somewhere else … and to be honest I think its a driver bug, I’ve already heard/read about some obscure dirver bugs in nvidia drivers leading to dead surfaces.
Could you re-test with an updated driver?

I know thats probably not the answer you hoped for, and it may be totally wrong - but give it a try. At least it would make it more clear where the problem could come from -> no more crashes -> chances for a driver bug.

Good luck, lg Clemens

To quickly check if there are any non-EDT-painting calls, install a special RepaintManager which does a thread check, there’s one here:
http://www.clientjava.com/blog/2004/08/31/1093972473000.html

Yes usually the EDT just stops with one of those exceptions and drawing freezes, maybe that funky stuff that you’re doing with JAWT and HWND is causing the problems because it’s conflicting with Swing’s calls to the graphics - this probably won’t help at all but maybe try flushing all the calls to the graphics card’s driver by doing Toolkit.flush() before you let the third party code do any painting.

Keith

Unfortunately it’s hard to diagnose such issues without a test case.

Is there a way to hack out a test out of your application?

Thanks,
Dmitri
Java2D Team