NAME

src/gc/mark_sweep.c - Small Object Pools and general mark/sweep GC behavior

DESCRIPTION

Handles the accessing of small object pools (header pools). All of the mark/sweep garbage collectors use this code.

Functions

void Parrot_gc_ms_run
Runs the stop-the-world mark & sweep (MS) collector.
int Parrot_gc_trace_root
Traces the root set. Returns 0 if it's a lazy GC run and all objects that need timely destruction were found.trace_stack can have these values:
  • GC_TRACE_FULL
  • trace whole root set, including system areas

  • GC_TRACE_ROOT_ONLY
  • trace normal roots, no system areas

  • GC_TRACE_SYSTEM_ONLY
  • trace system areas only

void Parrot_gc_sweep
Puts any buffers/PMCs that are now unused onto the pool's free list. If GC_IS_MALLOC, bufstart gets freed too, if possible. Avoids buffers that are immune from collection (i.e. constant).
void pobject_lives
Marks the PObj as "alive" for the Garbage Collector. Takes a pointer to a PObj, and performs necessary marking to ensure the PMC and its direct children nodes are marked alive. Implementation is generally dependant on the particular garbage collector in use.
INTVAL contained_in_pool
Returns whether the given *ptr points to a location in pool.
int Parrot_is_const_pmc
Returns whether *pmc is a constant PMC. The given pointer is a constant PMC if it points into the constant PMC pool.
static void mark_special
Marks the children of a special PMC. Handles the marking necessary for shared PMCs, and ensures timely marking of high-priority PMCs. Ensures PMC_EXT structures are properly organized for garbage collection.
static void more_traceable_objects
We're out of traceable objects. First we try a GC run to free some up. If that doesn't work, allocate a new arena.
static void gc_ms_add_free_pmc_ext
Add a freed PMC_EXT structure to the free list in the PMC_EXT pool. Objects on the free list can be reused later.
static void gc_ms_add_free_object
Add an unused object back to the pool's free list for later reuse. Set the PObj flags to indicate that the item is free.
static void *gc_ms_get_free_object
Free object allocator for the MS garbage collector system. If there are no free objects, call gc_ms_add_free_object to either free them up with a GC run, or allocate new objects. If there are objects available on the free list, pop it off and return it.
static void *gc_ms_get_free_pmc_ext
Get a new PMC_EXT structure from the free pool and return it.
static int sweep_cb
Sweeps the given pool for the MS collector. This function also ends the profiling timer, if profiling is enabled. Returns the total number of objects freed.
static int trace_active_PMCs
Performs a full trace run and marks all the PMCs as active if they are. Returns whether the run completed, that is, whether it's safe to proceed with GC.
static void clear_live_bits
Runs through all PMC arenas and clear live bits. This is used to reset the GC system after a full system sweep.
void Parrot_gc_clear_live_bits
Resets the PMC pool, so all objects are marked as "White". This is done after a GC run to reset the system and prepare for the next mark phase.
int Parrot_gc_trace_children
Returns whether the tracing process has completed.
void Parrot_add_to_free_list
Adds the objects in the newly allocated arena to the free list.
void Parrot_append_arena_in_pool
Insert the new arena into the pool's structure. Arenas are stored in a linked list, so add the new arena to the list. Set information in the arenas structure, such as the number of objects allocated in it.
static void gc_ms_alloc_objects
New arena allocator function for the MS garbage collector system. Allocates and initializes a new memory arena in the given pool. Adds all the new objects to the pool's free list for later allocation.
Small_Object_Pool *new_small_object_pool
Creates a new Small_Object_Pool and returns a pointer to it. Initializes the pool structure based on the size of objects in the pool and the number of items to allocate in each arena.
void gc_pmc_ext_pool_init
Initialize the PMC_EXT pool functions. This is done separately from other pools.
static void gc_ms_pool_init
Initialize a memory pool for the MS garbage collector system. Sets the function pointers necessary to perform basic operations on a pool, such as object allocation.
void Parrot_gc_ms_init
Initialize the state structures of the gc system. Called immediately before creation of memory pools. This function must set the function pointers for add_free_object_fn, get_free_object_fn, alloc_object_fn, and more_object_fn.
void Parrot_small_object_pool_merge
Merge pool source into pool dest. Combines the free lists directly, moves all arenas to the new pool, and remove the old pool. To merge, the two pools must have the same object size, and the same name (if they have names).

SEE ALSO

include/parrot/mark_sweep.h, docs/memory_internals.pod.