Why not only allow class unloading only for classes without static
fields, static methods, or static initializers? That side-steps the
initialization issues and means that you need an instance in order to
use it (no static elements + no references = no problem unloading). Am
I correct in my line of thinking?

-Adam


On Jan 15, 2008 3:57 AM, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote:
>
> Ted Neward wrote:
> > Hate to say it, Kresten, but I don't think you'll ever see this--the
> > semantics of unloading classes, except by GC, would need to be worked out
> > and codified someplace before this could happen.
>
> I think the thing Kresten is looking for is an ability to unload classes
> (or make them eligible for GC) when they are known to be unused. Or if
> he's not, that's what I want.
>
> > Assume for the moment that we go with a simpler implementation,
> > System.classGC() that takes a Class object and unloads it. (Ignore the
> > complications of ClassLoaders for now.) Suppose...
> > (*) ... there is an instance of that Class still reachable in the system?
> > What should happen?
>
> It's a hard reference; there's nothing new here. An object references
> its class.
>
> > (*) ... this is an abstract class that is inherited by other classes in the
> > system (which may or may not have instances still reachable)?
>
> A child class has a hard reference to a parent class. No problem.
>
> > (*) ... you're in the middle of a static method execution call on that class
> > on another Thread?
>
> Then there's a hard reference to that class from that thread or from
> frame executing it.
>
> > (*) ... another thread is *about* (say, five seconds from now) to make a
> > static method execution call on that class?
>
> Can't predict the future; but if the caller already has a reference to
> the class it wouldn't be able to go away.
>
> In general, if all reference to a class go away, there should be a way
> to make it eligible for immediate GC.
>
> The larger issues, as I understand them, relate to static initializers.
> In order to guarantee the static initializers don't fire again under a
> given classloader, there must be guarantees about classes staying alive.
> If they could GC when there are no more references to them, their static
> initializers could fire again.
>
> However, there's a lot of uses for classes that don't require such
> guarantees, such as generating anonymous classes to hold code compiled
> at runtime. I don't care if the classes I compile in JRuby's JIT get
> unloaded or reloaded, because I'll manage my own references to them. But
> because of the Vector in ClassLoader...they tend to stick around too
> long without ClassLoader tricks.
>
> - Charlie
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to