This is the mail archive of the java-discuss@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: Speeding up method searches


Bryce McKinlay <bryce@albatross.co.nz> writes:

> Ok, so the behavior of the constructors for String would need to be
> special-cased somehow, because they need to return a reference to an already
> existing String (rather than allocate a new one) in the case where a match
> already exists in the intern hashtable.

Actually, no.  String *constructors* do not need to do interning.
Just the intern function.  And intern never needs to construct
a new String - it either returns the argument, or a String
previously interned.

> How do interned strings get garbage collected? The intern hashtable would need
> to use some kind of weak referencing scheme (so that the collector won't
> consider the pointers in the hashtable to be legitimate references), and
> runtime-allocated Strings would need to have a finalizer to remove themselves
> from the hashtable when they get collected.

Basically - though only for those Strings that *are* interned.

> In the case of dynamic linking , it probibly won't make much difference exactly
> where the interning is done - so I guess linker support for interning is
> something which we can worry about later.

Yes.  It still be helpful to coalesce equal pre-allocated String
*within* each library or main program.  But it's an optimization
that can wait.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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