|parrotcode: Dead object destruction of the various headers
Contents | C
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
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.
- 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.
- 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.
- Returns whether the tracing process has completed.
- 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
- Clears the COW ref count.
- Finds other users of COW's
- 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).
- 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.
- Frees the
PMC_EXT structure attached to a PMC, if it exists.
- If the PMC uses memory allocated directly from the system, this function frees that memory.
- 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.
- 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
- Traces the memory block between
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.
- 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.
- Records the start time of a DOD run when profiling is enabled.
- Records the end time of the DOD part
what run when profiling is enabled. Also record start time of next part.
- 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.
- Runs the stop-the-world mark & sweep (MS) collector.
- Calls the configured garbage collector to find and reclaim unused headers.
include/parrot/dod.h, src/cpu_dep.c, docs/dev/dod.dev and docs/pdds/pdd09_gc.pod.
Initial version by Mike Lambert on 2002.05.27.