> 
> Turning off class GC has nothing to do with making things like static
> counters work.  GC will only happen if the class becomes unreachable.
> And being unreachable means (by definition) you have no way to access
> the counter, so you can't check its value.
> 

I'm only familiar with Kaffe's class gc, but I have heard that
older versions of Sun's JVM would unload a class even if its classloader
was still reachable.  [*] Suppose you implemented your counter using reflection
so that you don't hold on to the Class object (or any other object of
that class), say you look it up everytime you need it using Class.forName()
and set/get your counter with Field.set/get.  In this case, disabling class 
gc is indeed necessary for a process lifetime counter to work.  

Of course, the other alternative you mentioned, using a shared class loaded 
by the system loader, works too.  However, it has the disadvantage of 
polluting your system namespace since there can be only one class of whatever 
name you choose in it.

        - Godmar

[*]
Sun later realized that this is confusing, and said that a class is
unreachable if its defining classloader is unreachable.  (See one of the
clarifications to the JLS):
http://java.sun.com/docs/books/jls/unloading-rationale.html

As an aside, I agree that the term class reloading is confusing.
To make matters worse, I've heard it used in three different contexts/meaning.
First, there's the meaning in systems like JServ: create a new classloader
that loads the class, drop the old classloader and everything else belonging
to the old class, and you have essentially "reloaded" the class.

The second meaning is mentioned in Sun's rationale above: a class is unloaded
despite the fact that its defining loader is still alive: later on, this
loader has to load the same name again, "reloading" the class.  This should
not happen with newer VMs.

The third meaning is in multi-process Java systems where you feed the same
bytecode to multiple classloaders for the purpose of instantiating or
"reloading" the same class into multiple namespace.  By doing so, you can
for instance provide each namespace with its own instance of System.out.



----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to