The JVM bug occurs in the thread-safe part. The information returned by eclipse is as follows,
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal error (classfileparser. cpp: 3161), pid = 1116, tid = 3912
# Error: shouldnotreachhere ()
#
# JRE version: 6.0 _ 21-b07
# Java VM: Java hotspot (TM) Client VM (17.0-B17 mixed mode windows-x86)
# An error report file with more information is saved:
# D: \ User \ workspace \ multithread \ hs_err_pid1116.log
Multithread \ hs_err_pid1116.log content:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal error (classfileparser. cpp: 3161), pid = 1116, tid = 3912
# Error: shouldnotreachhere ()
#
# JRE version: 6.0 _ 21-b07
# Java VM: Java hotspot (TM) Client VM (17.0-B17 mixed mode windows-x86)
# If you wowould like to submit a bug report, please visit:
# Http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------- T h r e a d ---------------
Current thread (0x01ad9000): javathread "unknown thread" [_ thread_in_vm, id = 3912, stack (0x00260000, 0x002b0000)]
STACK: [0x00260000, 0x002b0000], SP = 0x002af880, free space = 13e002af890k
Native frames: (j = compiled Java code, j = interpreted, VV = VM code, c = native code)
V [JVM. dll + 0x1fd090]
V [JVM. dll + 0xa47c9]
V [JNDI. dll + 0x75f01]
V [JVM. dll + 0x775a4]
V [JVM. dll + 0x1cbcb5]
V [JVM. dll + 0x1cc3ed]
V [JVM. dll + 0x1cc7a5]
V [JVM. dll + 0x1cc7eb]
V [JVM. dll + 0x1cc912]
V [JVM. dll + 0x1cc98a]
V [JVM. dll + 0x1cce3d]
V [JVM. dll + 0x1cd252]
V [JVM. dll + 0x1eceb3]
V [JVM. dll + 0x1ed28c]
V [JVM. dll + 0xdb721]
V [JVM. dll + 0x1e6618]
V [JVM. dll + 0x1065d0]
C producer javaw.exe + 0x1657]
C producer javaw.exe + 0x1e2c]
C producer javaw.exe + 0x8614]
C [kernel32.dll + 0x4ed6c]
C [NTDLL. dll + 0x6377b]
C [NTDLL. dll + 0x6374e]
--------------- P r o c e s ---------------
Java threads: (=> current thread)
Other threads:
=> 0x01ad9000 (exited) javathread "unknown thread" [_ thread_in_vm, id = 3912, stack (0x00260000, 0x002b0000)]
VM state: Not at safepoint (not fully initialized)
VM mutex/monitor currently owned by a thread: None
Dynamic libraries:
0x00400000-0x00424000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin \ javaw.exe
0x775f0000-0x7772c000 C: \ windows \ system32 \ NTDLL. dll
0x76bd0000-0x76ca4000 C: \ windows \ system32 \ kernel32.dll
0x75860000-0x758aa000 C: \ windows \ system32 \ kernelbase. dll
0x77430000-0x774d0000 C: \ windows \ system32 \ advapi32.dll
0x76d90000-0x76e3c000 C: \ windows \ system32 \ msvcrt. dll
0x75c20000-0x75c39000 C: \ windows \ system32 \ sechost. dll
0x75a80000-0x75b21000 C: \ windows \ system32 \ rpcrt4.dll
0x77360000-0x77429000 C: \ windows \ system32 \ user32.dll
0x75da0000-0x75dee000 C: \ windows \ system32 \ gdi32.dll
0x777b0000-0x777ba000 C: \ windows \ system32 \ LPK. dll
0x772c0000-0x7735d000 C: \ windows \ system32 \ usp10.dll
0x77760000-0x7777f000 C: \ windows \ system32 \ imm32.dll
0x75df0000-0x75ebc000 C: \ windows \ system32 \ msctf. dll
0x7c340000-0x7c0000000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ msvcr71.dll
0x6d8b0000-0x6db57000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ Client \ JVM. dll
0x73c80000-0x73cb2000 C: \ windows \ system32 \ winmm. dll
0x756b0000-0x756fc000 C: \ windows \ system32 \ apphelp. dll
0x6d860000-0x6d86c000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ verify. dll
0x6d3e0000-0x6d3ff000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ Java. dll
0x6d340000-0x6d348000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ HPI. dll
0x77750000-0x77755000 C: \ windows \ system32 \ psapi. dll
0x6d8a0000-0x6d8af000 C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ JRE \ bin \ zip. dll
VM arguments:
Jvm_args:-dfile. Encoding = UTF-8-xbootclasspath: C: \ Program Files \ Android-SDK \ platforms \ Android-14 \ Android. Jar
Java_command: COM. gogler. Multithread. threadsafedemo
Launcher type: sun_standard
Environment variables:
Java_home = c: \ Program Files \ Java \ jdk1.6.0 _ 21
Classpath = .; c: \ Program Files \ Java \ jdk1.6.0 _ 21 \ Lib \ tools. jar; C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ Lib \ DT. jar; C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin;
Path = C:/program files/Java/jre6/bin/client; C:/program files/Java/jre6/bin; C: /program files/Java/jre6/lib/i386; C: \ Program Files \ common files \ netsarang; c: \ windows \ system32; C: \ WINDOWS; C: \ windows \ system32 \ WBEM; c: \ windows \ system32 \ windowspowershell \ V1.0 \; D: \ Program
Files \ tortoisesvn \ bin; C: \ Program Files \ Java \ jdk1.6.0 _ 21 \ bin; F: \ Android-SDK-Windows \ tools; F: \ Android-SDK-Windows \ platform-tools; D: \ Program Files \ dbank \ clickup; C: \ Users \ Administrator \ downloads \ eclipse-SDK-3.7-win32 \ eclipse;
Username = Administrator
OS = windows_nt
Processor_identifier = x86 family 6 model 23 stepping 10, genuineintel
--------------- S y s t e m ---------------
OS: Windows 7 build 7601 Service Pack 1
CPU: Total 2 (2 cores per CPU, 1 threads per core) family 6 model 23 stepping 10, cmov, cx8, fxsr, MMX, SSE, sse2, sse3, ssse3
Memory: 4 K page, physical 3634232 K (2249368 K free), swap 7266708 K (5328364 K 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: Sat Apr 28 8 17:11:19 2012
Elapsed time: 0 seconds
ExecutedCode:
Package COM. gogler. multithread; // Java language: arraylist thread security and unsafe comparison demonstration import Java. util. arraylist; import Java. util. collections; import Java. util. list; import Java. util. random; public class threadsafedemo {public static int demo (final list, final int testcount) throws interruptedexception {threadgroup group Group = new threadgroup (list. getclass (). getname () + "@" + list. hashcode (); final random Rand = new random (); runnable listappender = new runnable () {public void run () {try {thread. sleep (Rand. nextint (2);} catch (interruptedexception e) {return;} List. add ("0") ;}}; for (INT I = 0; I <testcount; I ++) {New thread (group, listappender, "insertlist-" + I ). start ();} while (group. activecount ()> 0) {thread. sleep (10);} return list. size ();} public static void main (string [] ARGs) throws interruptedexception {list unsafelist = new arraylist (); List safelist = collections. synchronizedlist (New arraylist (); Final int n = 10000; For (INT I = 0; I <10; I ++) {unsafelist. clear (); safelist. clear (); int unsafesize = demo (unsafelist, n); int safesize = demo (safelist, n); system. out. println ("unsafe/safe:" + unsafesize + "/" + safesize );}}}