Flexibility Required
Being able to characterize the dynamic memory allocation behavior of
an application helps in choosing a garbage collection algorithm. For
example, if it appears that the embedded application is known to build
no cyclic data structures, then a derived reference counting algorithm
might be appropriate. If allocated objects are known to be fairly
similar in sizes, then a non compacting algorithm might be used.
Instrumentation of memory allocations behavior, including peak size,
object sizes and life spans statistics will help a developer to select
the correct garbage collection algorithm. Such a monitoring can be
performed during development and the test phases by using a special
version of the runtime environment. The next step is to assist the
developer by allowing them to plug and tune the garbage collector of
their choice.
These issues are being seriously examined at Cygnus Solutions, which
is developing a Java runtime and Java extensions for the GCC compiler
[see side bar "The Cygnus GNUPro compiler for the Java language"].
Being in control of the tools that generate the code gives us
opportunities to ease the work of a garbage collector in many ways.
We can precisely perform any relevant static allocation of objects and
implement write barriers, even though the implementation of this may
be challenging if we want to support pluggable collectors. An
efficient write barrier needs to interact very closely with the
collector in use, being aware of either its internal data structures
or the object marking in use. They usually feature between ten to
thirty instructions and can't really afford the versatility of using
function calls. One solution might be to specify the write barrier as
a user-editable piece of code, which can be inserted as necessary by
the compiler during the instruction generation phase. Developing our
own compiler also gives us a chance to analyze the way finalizers are
written, thus detecting actions that resuscitate objects being thrown
away. This could be done by analyzing the use of this as an
expression right-hand side or method parameter.
|