Because of the new definition of when a Class can be unloaded (although
JDK1.1 doesn't implement this spec correctly), jnilink has become useless.
     The new definition, from Clarifications and Amendments to the JLS:
     A class or interface may be unloaded if and only if its class loader is
unreachable. Classes loaded by the bootstrap loader may not be unloaded.
     (My Note: A class loader is unreachable if and only if all of its
classes are unreachable and no explicit references to it exist.)
     (My Note: A class is unreachable if and only if it has no instances,
its subclasses have no instances, and it is not referenced explicitly.)

     The reasoning chain is this (some of the assumptions are new to 1.2 as
well):

     1. A ClassLoader cannot be unloaded if any of its Class objects can be
reached.
     2. Class A always accesses Class B using the same ClassLoader.
     3. Thus, as long as Class A is reachable, so are all the classes it
accesses.
     4. If you are working outside this rule, you must know exactly what
you're doing (i.e. you're loading a class using
SomeClassLoaderThatIsntMyClassLoader.loadClass()).  In that case, you can
bloody well cache the damned things yourself :)

     JNILINK is useless.  Use it no longer.  Eventually (once everyone that
has used it, which I think is just Aaron and myself, has removed references
to it), I will deprecate it and take it out entirely.  I feel real bad about
it, and all these changes to it, but I also feel happy that the language is
robust enough (finally) that we don't have to worry about crap like that.
     (Oh, and as to the only thing it actually does currently, just cache
the NewGlobalRef yourself if you really feel like it.)

--John Keiser

Reply via email to