[ forwarded from http://bugs.debian.org/275547 ] falk@juist:/tmp% cat Test.java class Test { public static void main(String[] argv) { for (char i = '\u0001'; i <= '\uffff'; i++) { char[] ca = { i }; System.out.println("Interning "+((int)i)+"th String"); (new String(ca)).intern(); } } } falk@juist:/tmp% gcj-3.4 -o Test --main=Test Test.java && ./Test [...] Interning 16380th String Interning 16381th String Interning 16382th String Interning 16383th String Interning 16384th String [hangs infintely] See also some analysis at the URL above. Also present in 3.3.
Confirmed, looks like the intern hash table becomes full.
Testing a patch.
In the upstream PR, a real deadlock is mentioned. The backtrace shows the finalizer thread blocking. Probably what is happening is that one thread is spinning while looking for an empty slot in the string hash table, and then the GC tries to finalize one of these strings. The String finalizer tries to acquire the lock already held by the thread looking for an empty slot, resulting in deadlock. This is just a theory, I would need at least backtraces of all the threads to be sure.
One more note -- the test case will loop infinitely even when the intern() bug has been fixed, since every 'char' value is <= \uffff
Subject: Bug 21703 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tromey@gcc.gnu.org 2005-05-22 01:04:47 Modified files: libjava : ChangeLog libjava/java/lang: natString.cc libjava/java/lang/ref: natReference.cc Log message: PR libgcj/21703: * java/lang/ref/natReference.cc (find_slot): Handle case where table has no NULL entries. * java/lang/natString.cc (_Jv_StringFindSlot): Handle case where table has no NULL entries. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.74&r2=1.3391.2.75 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natString.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.36&r2=1.36.12.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/ref/natReference.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.6&r2=1.6.72.1
I've checked in a patch on the 4.0 branch. I will put it on the trunk when it emerges from its current slushy state; I am leaving the PR open until then. I'm not planning to put this on the 3.4 branch, but if someone is motivated I think they are free to do so.
Subject: Bug 21703 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2005-05-25 15:23:57 Modified files: libjava : ChangeLog libjava/java/lang: natString.cc libjava/java/lang/ref: natReference.cc Log message: PR libgcj/21703: * java/lang/ref/natReference.cc (find_slot): Handle case where table has no NULL entries. * java/lang/natString.cc (_Jv_StringFindSlot): Handle case where table has no NULL entries. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3631&r2=1.3632 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natString.cc.diff?cvsroot=gcc&r1=1.37&r2=1.38 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/ref/natReference.cc.diff?cvsroot=gcc&r1=1.6&r2=1.7
Fix checked in.