harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "bootjvm@earthlink.net" <boot...@earthlink.net>
Subject Example GC algorithm
Date Fri, 28 Oct 2005 21:23:40 GMT


Sometimes the best explanation is a good example.
I have written a simple GC algorithm that counts
references to objects as an example of how the
GC interface might be implemented.  Some algorithms
may not use all the hooks, perhaps some might need
an additional hook or two beyond what is currently
defined, but this example should give the idea of the
rationale behind the GC methodology.

Look into 'jvm/src/object.c' for object_instance_new()
and object_instance_delete() for the GC hooks that
will be needed for most Java bytecode 'new' events
and for collection.

The source file 'jvm/src/gc_refcount.c' implements
the GC API of 'jvm/src/gc.h' and is configured from
'config.sh' with a new GC option 'refcount.  When any
GC_xxx() macro is called, then this code will be
called when so configured.

When a 'NEW' bytecode (still under construction)
or related opcodes requests a new object to be
created, a reference to it will also soon be
created.  When this happens, the GC counts it (+1).
As many references may be created as needed by
the Java program.  When a reference variable is
not needed or is modified with another object's
reference, the reference count goes down (-1).
When the count reaches zero, the object status
bit OBJECT_STATUS_GCREQ is set and the
GC_RUN() macro will collect it when invoked
at some point in the future.

Of course, there are better GC algorithms than
simple reference counts, but this should give the
idea of the rationale behind the GC interface.
As usual, comments and questions are welcome.

Dan Lydick

Dan Lydick

View raw message