Bug 21703 - hang when rapidly calling String.intern()
Summary: hang when rapidly calling String.intern()
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 4.0.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-21 19:55 UTC by Debian GCC Maintainers
Modified: 2005-05-25 15:24 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-21 20:14:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2005-05-21 19:55:25 UTC
[ 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.
Comment 1 Andrew Pinski 2005-05-21 20:14:33 UTC
Confirmed, looks like the intern hash table becomes full.
Comment 2 Tom Tromey 2005-05-21 23:48:03 UTC
Testing a patch.
Comment 3 Tom Tromey 2005-05-21 23:56:27 UTC
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.
Comment 4 Tom Tromey 2005-05-22 00:37:57 UTC
One more note -- the test case will loop infinitely
even when the intern() bug has been fixed, since every
'char' value is <= \uffff
Comment 5 GCC Commits 2005-05-22 01:04:59 UTC
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

Comment 6 Tom Tromey 2005-05-22 01:06:15 UTC
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.
Comment 7 GCC Commits 2005-05-25 15:24:17 UTC
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

Comment 8 Tom Tromey 2005-05-25 15:24:52 UTC
Fix checked in.