Santiago Gala wrote:
IIRC, the (JVM spec v2) requirement for .equals String literals to be
(==)identical only holds for Strings in the same .class file, but I
could be wrong.

I believe the requirement is stronger than that. Any two
String literals (i.e., String constants from class files)
that are the same string must be the same object (==).
It doesn't matter if they come from different classes.

In any case, interning all VM Strings in some sort of global weak set
would do the trick, as shared literals would remain referenced on
classloader collection, while unreferenced ones would be eligible for
collection. This is typically how symbols in lisp or smalltalk are
managed (most implementations don't even bother to use a weak structure,
so symbols are never collected). Basically this is what String.intern()
does, and nothing impedes us to actually use it for all Strings in the
VM.

This is how Classpath works. Strings are intern'd using a weak
hash map and String.intern() is implemented in pure Java.
The JVM does nothing special for strings, with the exception
that when it creates them from class files it also interns them.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

Reply via email to