'Kay, here's a quick overview of how memory, garbage collection, and dead 
object detection are going to work in Parrot. (And I appreciate this 
getting raised now, BTW--both because it's about time and because it makes 
me think about it in time for next saturday)

There are three sets of memory pools for each interpreter. They are:

*) The PMC pool
*) The Buffer header pool
*) The honking great slab of memory pool

The PMC and buffer pools each consist of one or more arenas, while the 
HGSOM pool has one or more slabs of memory allocated to it.

Each arena is thread-private, and no other interpreter can allocate out of it.

When the interpreter needs to do a garbage run, it runs through all the 
PMCs in the PMC pool. Any that look like they might be live and that point 
to buffer objects are assumed to be alive, and the memory their buffer 
objects points to is collected. It's essentially a barely-conditional 
sweep, with the assumption that dead objects are marked as such and thus 
won't be collected

The dead object phase is essentially the mark phase of a GC run. We mark 
all the PMCs in the pool as unused, start with the root set and then mark 
all the used ones. When we run out, any PMCs that were used but aren't 
pointed to are then marked as unused so garbage runs will ignore them. If 
any of these PMCs require active destruction then that'll be done here.

If at any point an arena or memory slab is completely unused, it may be 
handed back. Whether that's to the system or a global allocator's up in the 
air--I can see it going either way.

Separating things this way means that a garbage run without an immediately 
preceding DOD run may collect on some PMCs that are really dead. That's OK.

Also, we may well use a vmem system to allocate buffer headers rather than 
using per-interpreter pools of arenas. I can see it going either way, and 
if we have several sizes of buffers it might be more space-efficient to do 
so, but on the other hand using arenas makes collecting the buffer headers, 
which can be done during DOD time, easier. (Basically we wouldn't need to 
explicitly free those either, and could trace the used and unused buffer 
objects at DOD time)

This help any?


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to