Crash your JVM by killing the garbage collector!

My HotSpot 1.6.0_21 JVM crashes if the following code is run on it. And by “crashes”, I mean that the JVM crashes and leaves an hs_err_pid####.log file with the thread dump from the JVM itself – there is no exception from the application code.

class Crash {

	public static void main(String[] args) {

		Object[] link = null;

		while (true) {
			link = new Object[] { link };
		}

	}
}

What has happened here is that the deep chain of objects we have allocated here causes a StackOverflow on what appears to be a recursive call in the garbage collector.

Usually such errors happen because of misbehaving drivers. Perhaps your app uses a finger print scannner or a printer or a scanner? Any JNI code going wrong causes this.

A common pattern when dealing with native code in Java is to avoid doing the calls in the main process of your application. Instead, have a different process that does the dirty work via JNI and communicate with that process via some mechanism – perhaps sockets. So if something goes wrong in JNI, only that process with gets killed rather than the entire app. Remember, with JNI exceptions, you get a dead JVM rather than an exception. This is because there is no telling what a misbehaving piece of native code may have done to the memory within a process.

My hs_err_pid####.log file –

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x6d8b99f0, pid=3780, tid=2232
#
# JRE version: 6.0_21-b07
# Java VM: Java HotSpot(TM) Client VM (17.0-b17 mixed mode, sharing windows-x86 )
# Problematic frame:
# V  [jvm.dll+0x99f0]
#
# 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 (0x02b09c00):  VMThread [stack: 0x02bf0000,0x02c40000] [id=2232]

siginfo: ExceptionCode=0xc00000fd, ExceptionInformation=0x00000001 0x02bf2ffc 

Registers:
EAX=0x22e62fc4, EBX=0x22e62fc0, ECX=0x371bb3a0, EDX=0x00000001
ESP=0x02bf3000, EBP=0x02bf3014, ESI=0x22e62fc0, EDI=0x22e62fbc
EIP=0x6d8b99f0, EFLAGS=0x00010246

Top of Stack: (sp=0x02bf3000)
0x02bf3000:   6da2d162 22e62fc4 22e62fbc 22e62fc0
0x02bf3010:   22e62fc0 02bf302c 6da2d1de 22e62fc0
0x02bf3020:   22e62fac 22e62fb0 22e62fb0 02bf3044
0x02bf3030:   6da2d1de 00000003 22e62f9c 22e62fa0
0x02bf3040:   22e62fa0 02bf305c 6da2d1de 00000003
0x02bf3050:   22e62f8c 22e62f90 22e62f90 02bf3074
0x02bf3060:   6da2d1de 00000003 22e62f7c 22e62f80
0x02bf3070:   22e62f80 02bf308c 6da2d1de 00000003 

Instructions: (pc=0x6d8b99f0)
0x6d8b99e0:   5d c2 08 00 cc cc cc cc cc cc cc cc cc cc cc cc
0x6d8b99f0:   55 8b ec 8b 45 08 56 8b 30 85 f6 74 40 8b 0e 83 

Stack: [0x02bf0000,0x02c40000],  sp=0x02bf3000,  free space=c02bf2b74k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x99f0]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
V  [jvm.dll+0x17d1de]
......

JavaThread 0x002b6400 (nid = 2948) was being processed
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
v  ~RuntimeStub::new_object_array Runtime1 stub
J  Crash.main([Ljava/lang/String;)V
v  ~StubRoutines::call_stub
VM_Operation (0x0095fa14): GenCollectForAllocation, mode: safepoint, requested by thread 0x002b6400

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

Java Threads: ( => current thread )
  0x02b25000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=5292, stack(0x02dd0000,0x02e20000)]
  0x02b16400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4848, stack(0x02d80000,0x02dd0000)]
  0x02b14c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=5384, stack(0x02d30000,0x02d80000)]
  0x02b13800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=528, stack(0x02ce0000,0x02d30000)]
  0x02b0fc00 JavaThread "Finalizer" daemon [_thread_blocked, id=324, stack(0x02c90000,0x02ce0000)]
  0x02b0b400 JavaThread "Reference Handler" daemon [_thread_blocked, id=5940, stack(0x02c40000,0x02c90000)]
  0x002b6400 JavaThread "main" [_thread_blocked, id=2948, stack(0x00910000,0x00960000)]

Other Threads:
=>0x02b09c00 VMThread [stack: 0x02bf0000,0x02c40000] [id=2232]
  0x02b38800 WatcherThread [stack: 0x02e20000,0x02e70000] [id=4228]

VM state:at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
[0x002b55f0] Threads_lock - owner thread: 0x02b09c00
[0x002b5a00] Heap_lock - owner thread: 0x002b6400

Heap
 def new generation   total 4736K, used 512K [0x22990000, 0x22eb0000, 0x27c30000)
  eden space 4224K,   0% used [0x22990000, 0x22990000, 0x22db0000)
  from space 512K, 100% used [0x22e30000, 0x22eb0000, 0x22eb0000)
  to   space 512K,   0% used [0x22db0000, 0x22db0000, 0x22e30000)
 tenured generation   total 12160K, used 12091K [0x27c30000, 0x28810000, 0x32190000)
   the space 12160K,  99% used [0x27c30000, 0x287fed48, 0x287fee00, 0x28810000)
 compacting perm gen  total 12288K, used 25K [0x32190000, 0x32d90000, 0x36190000)
   the space 12288K,   0% used [0x32190000, 0x32196528, 0x32196600, 0x32d90000)
    ro space 10240K,  54% used [0x36190000, 0x3670c0f0, 0x3670c200, 0x36b90000)
    rw space 12288K,  55% used [0x36b90000, 0x3722fb80, 0x3722fc00, 0x37790000)

Dynamic libraries:
0x00400000 - 0x00424000 	E:\Java\jdk1.6.0_21\bin\java.exe
0x7c900000 - 0x7c9b2000 	D:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c8f6000 	D:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e6b000 	D:\WINDOWS\system32\ADVAPI32.dll
0x77e70000 - 0x77f03000 	D:\WINDOWS\system32\RPCRT4.dll
0x77fe0000 - 0x77ff1000 	D:\WINDOWS\system32\Secur32.dll
0x7c340000 - 0x7c396000 	E:\Java\jdk1.6.0_21\jre\bin\msvcr71.dll
0x6d8b0000 - 0x6db57000 	E:\Java\jdk1.6.0_21\jre\bin\client\jvm.dll
0x7e410000 - 0x7e4a1000 	D:\WINDOWS\system32\USER32.dll
0x77f10000 - 0x77f59000 	D:\WINDOWS\system32\GDI32.dll
0x76b40000 - 0x76b6d000 	D:\WINDOWS\system32\WINMM.dll
0x76390000 - 0x763ad000 	D:\WINDOWS\system32\IMM32.DLL
0x6d860000 - 0x6d86c000 	E:\Java\jdk1.6.0_21\jre\bin\verify.dll
0x6d3e0000 - 0x6d3ff000 	E:\Java\jdk1.6.0_21\jre\bin\java.dll
0x6d340000 - 0x6d348000 	E:\Java\jdk1.6.0_21\jre\bin\hpi.dll
0x76bf0000 - 0x76bfb000 	D:\WINDOWS\system32\PSAPI.DLL
0x6d8a0000 - 0x6d8af000 	E:\Java\jdk1.6.0_21\jre\bin\zip.dll

VM Arguments:
java_command: Crash
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=E:\Java\jdk1.6.0_21
CLASSPATH=.;E:\Java\jre6\lib\ext\QTJava.zip
PATH=E:\Java\jdk1.6.0_21\bin;D:\WINDOWS\SYSTEM32;D:\WINDOWS;D:\WINDOWS\SYSTEM32\WBEM
USERNAME=Onkar Joshi
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 10 Stepping 0, AuthenticAMD

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

OS: Windows XP Build 2600 Service Pack 3

CPU:total 1 (1 cores per cpu, 1 threads per core) family 6 model 10 stepping 0, cmov, cx8, fxsr, mmx, sse, mmxext, 3dnow, 3dnowext

Memory: 4k page, physical 1015152k(349348k free), swap 1974304k(600992k free)

vm_info: Java HotSpot(TM) Client VM (17.0-b17) for windows-x86 JRE (1.6.0_21-b07), built on Jul 17 2010 01:10:15 by "java_re" with MS VC++ 7.1 (VS2003)

time: Mon Mar 07 02:40:13 2011
elapsed time: 0 seconds


Tags: ,
This entry was posted on Tuesday, May 24th, 2011 at 9:33 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.