This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: String interning


Tom Tromey wrote:

> Bryce> You're right. I think the solution is to work the other way -
> Bryce> initially memset() the table to ~0, and treat NULLs as
> Bryce> DELETED_STRINGs.  Unfortunatly it means that we're memset()-ing
> Bryce> twice, but we're already doing that.

> If you make the DELETED_STRING change, plus the comment, feel free to
> just check it in if it passes your test.

Unfortunatly the DELETED_STRING (using weak references) thing didnt work
out either. The problem is that the hashtable ends up being populated
nearly entirely with DELETED_STRINGs after lots of strings have been
interned and collected, this means that intern() ends up having to
traverse anything up to the entire table looking for the first
UNUSED_SLOT (~0) entry, so performance sucks. One workaround would be to
remove the "do we really need to bother" check in rehash(), so that the
table gets rehashed (to the same size) periodically to clear out the
DELETED_STRINGs... better, but could also result in unneccessarily poor
performance (unless we can assume that most interned strings will never
be collected). Otherwise, it would seem that we need to change the
hashtable design somewhat to accomodate this efficiently.

So, I thought about going back to using a finalizer for interned strings
instead. But it is safe to have a synchronized{} block inside a
finializer? Does the collector invoke finalizers while it is in the
"world-stopped" state? What would happen if the garbage collector is
invoked inside intern(), while it holds the lock on String.class?

Its like digging deeper and deeper into a hole... now I know why JDK
1.1.x doesn't do this right.

regards

  [ bryce ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]