Re: class gc

Date view Thread view Subject view Author view

From: Alexandre Oliva (oliva@dcc.unicamp.br)
Date: Thu Dec 17 1998 - 14:51:49 EST


On Dec 17, 1998, Godmar Back <gback@marker.cs.utah.edu> wrote:

> Class gc is "automatic"; there is no finalizer for class objects
> at this time.

Do you mean the classFinalize() method is not invoked? It shouldn't
be hard to run it before the function that does the actual clean-up.
But then, the classFinalizer might make the class reachable again, so
the constant pool should not be disallocated.

How about the following mechanism: when a class is loaded, we check
whether there's a classFinalize or not. If there is, we instantiate a
helper class that will invoke the classFinalizer and replace its
reference in the classFinalize with another helper object, that will
then invoke the actual finalizer.

I think the same applies to other finalizable objects, such as
Threads, otherwise we may end up disallocating the stack of a Thread
before its finalizer starts the Thread (if this is possible at all).
So we won't break given the following (untested) code:

class Test extends Thread {
  public void finalize() { start(); }
  public void run() { System.out.println("Worked!"); }
  private void test() { new Test(); }
  public static void main(String[] argv) {
    new Test();
    System.gc();
    System.runFinalization();
  }
}

> This is done in a quasi-finalizer for the classloader that loaded
> the classes. Quasi-finalizer is the term I just coined for
> Alexandre's idea of associating a private static object of an
> anonymous private class for purposes of finalization.

Cool! Maybe we should write a paper on this subject :-)

> Note that classes keep their loader alive, while the loader does
> not (per se) keep the classes alive.

Shouldn't it maintain a hashtable pointing to all classes, so as to
(as a side effect) keep them all alive?

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:57:20 EDT