[kaffe] Kaffe CVS: kaffe hkraemer

Archie Cobbs archie at dellroad.org
Tue May 20 09:57:01 PDT 2003

Dalibor Topic wrote:
> thanks for the tip, I've found this article on JavaWorld that explains the
> problem in some detail:
> http://www.javaworld.com/javaworld/javatips/jw-javatip52.html
> > Strongly referencing a class from the classloader that loaded it
> > solves this problem, since a class can then only be gc'ed if its
> > defining classloader can be gc'ed, which means that nobody is able
> > to access the singleton anyway. This in turn would mean that the
> > test in its current form is wrong, the failure is a correct result
> > and we should fix the test case and should better leave the rest
> > of the vm untouched...
> I gave it a shot using a static WeakHashMap to store a map of (classloader ->
> map of(name -> class)), removing the direct reference to the loadedClasses
> hashmap. Didn't work as expected, i.e. ClassGC still failed. Then I tried to
> also keep class loaders away from the (name -> class) map, but that wasn't
> helpful either. Ugh.
> What puzzles me is that the ClassGC test works with Sun's Java 1.4. It unloads
> the classes all right, and loads them back again. I guess we should go through
> the diffs and see where a new reference to the class loader has been added.

Not certain, but I think the only way this can work is if the
references from a ClassLoader to its classes are "implicit" in the
VM and not normal Java references e.g. via a Hashtable object. That
is, they don't "count" when computing liveness during garbage
collection. Otherwise every class would always be (indirectly)
referenced by the bootstrap ClassLoader and therefore could never
be unloaded.

The reference from a class to its ClassLoader object could in theory
be a normal reference, but what field would it live in? So it too must
be implicit, but otherwise acts like a normal "live" reference.

Then, a ClassLoader X may be unloaded when the X object itself is
determined to no longer be live (implying all its classes are also
no longer live). Then the VM must explicitly remove the "implicit"
reference that exists within the VM from the other ClassLoader Y
that loaded X to X.


Archie Cobbs     *     Precision I/O      *     http://www.precisionio.com

More information about the kaffe mailing list