Parrot Virtual Machine/Memory and Garbage Collection
Arenas and PoolsEdit
Parrot allocates memory in large blocks called arenas. Each arena has enough space to hold exactly N items of size M, typically tightly packed together in consecutive memory locations. Some collectors may also store additional metadata in the arena as well. Multiple arenas of the same type are stored as a linked list inside a pool. A pool may no arenas, one arena, or multiple arenas, but arenas in a given pool all contain objects of the same size. However, each arena may hold a different number of objects.
The parrot interpreter structure, which maintains state for the entire virtual machine, contains a pointer to the arena_base structure. The arena base structure contains pointers to all the various pools, and a few other important data items that are used for memory management.
Parrot has a number of garbage collectors available, which can be selected at compile time using compiler directives. The most mature and robust collector at this time is a simple mark & sweep collector, GC_MS. The different collectors can be activated or deactivated prior to compilation in the file
include/Parrot/settings.h. That file contains a number of options that you can set to customize the behavior of Parrot.
Development on new garbage collectors, and improvement in the current collector system, is currently occurring, and this page may be out of date.
Mark & Sweep CollectorEdit
The Mark & Sweep (MS) collector is the only collector for Parrot that is currently mature and stable enough for regular use. However, this collector is the cause of several performance problems in Parrot, and there are active efforts under way to replace it. The mark & sweep collector will likely be deprecated or removed entirely from Parrot by the 1.0.0 release.
Incremental Tricolor CollectorEdit
Development is currently under way on a new garbage collection scheme which uses a tricolor marking algorithm to mark data objects. The tricolor algorithm will enable an incremental behavior in the collector so that the "stop the world" behavior of the MS collector can be avoided for large memory pools.
Writing new CollectorsEdit
Writing a new collector is as simple as implementing a particular interface. This interface is defined in detail in PDD 09, but we will cover some of the basics here.
Arena_base and function pointersEdit
Pools and function pointersEdit