src/gc/dod.c - Dead object destruction of the various headers


This file implements dead object destruction. This is documented in PDD 9 with supplementary notes in docs/dev/dod.pod and docs/memory_internals.pod.

It's possible to turn on/off the checking of the system stack and processor registers. The actual checking is set up in src/cpu_dep.c and is performed in the function trace_memory_block here.

There's also a verbose mode for garbage collection.


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.

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 it's direct children nodes are marked alive. Implementation is generally dependant on the particular garbage collector in use.

int Parrot_dod_trace_root

Traces the root set. Returns 0 if it's a lazy DOD run and all objects that need timely destruction were found.

trace_stack can have these values:

 0 ... trace normal roots, no system areas
 1 ... trace whole root set
 2 ... trace system areas only
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.

int Parrot_dod_trace_children

Returns whether the tracing process has completed.

void Parrot_dod_trace_pmc_data

If the PMC is an array of PMCs, trace all elements in the array as children. Touches each object in the array to mark it as being alive. To determine whether a PMC is an array to be marked in this way, it is tested for the PObj_data_is_PMC_array_FLAG flag.

void clear_cow

Clears the COW ref count.

void used_cow

Finds other users of COW's bufstart.

void Parrot_dod_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 Parrot_dod_free_pmc

Frees a PMC that is no longer being used. Calls a custom destroy VTABLE method if one is available. If the PMC uses a PMC_EXT structure, that is freed as well.

void Parrot_free_pmc_ext

Frees the PMC_EXT structure attached to a PMC, if it exists.

void Parrot_dod_free_sysmem

If the PMC uses memory allocated directly from the system, this function frees that memory.

void Parrot_dod_free_buffer_malloc

Frees the given buffer, returning the storage space to the operating system and removing it from Parrot's memory management system. If the buffer is COW, The buffer is not freed if the reference count is greater then 1.

void Parrot_dod_free_buffer

Frees a buffer, returning it to the memory pool for Parrot to possibly reuse later.

static size_t find_common_mask

Finds a mask covering the longest common bit-prefix of val1 and val2.

void trace_mem_block

Traces the memory block between lo_var_ptr and hi_var_ptr. Attempt to find pointers to PObjs or buffers, and mark them as "alive" if found. See src/cpu_dep.c for more information about tracing memory areas.

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_dod_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.

void Parrot_dod_profile_start

Records the start time of a DOD run when profiling is enabled.

void Parrot_dod_profile_end

Records the end time of the DOD part what run when profiling is enabled. Also record start time of next part.

void Parrot_dod_ms_run_init

Prepares the collector for a mark & sweep DOD run. This is the initializer function for the MS garbage collector.

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.

void Parrot_dod_ms_run

Runs the stop-the-world mark & sweep (MS) collector.

void Parrot_do_dod_run

Calls the configured garbage collector to find and reclaim unused headers.


include/parrot/dod.h, src/cpu_dep.c, docs/dev/ and docs/pdds/pdd09_gc.pod.


Initial version by Mike Lambert on 2002.05.27.