NAME

src/gc/pools.c - Header management functions

DESCRIPTION

Handles pool creation for PMC headers.

Buffer Header Functions for small-object lookup table

void *get_free_buffer
Gets a free object or buffer from the given pool and returns it. If the object is larger then a standard PObj structure, all additional memory is cleared.

Header Pool Creation Functions

Small_Object_Pool *new_pmc_pool
Creates and initializes a new pool for PMCs and returns it.
Small_Object_Pool *new_bufferlike_pool
Creates a new pool for buffer-like structures. This is called from get_bufferlike_pool(), and should probably not be called directly.
Small_Object_Pool *new_buffer_pool
Creates a new Small_Object_Pool structure for managing buffer objects.Non-constant strings and plain Buffers are stored in the sized header pools.
Small_Object_Pool *new_string_pool
Creates a new pool for STRINGs and returns it. This calls get_bufferlike_pool internally, which in turn calls new_bufferlike_pool.
Small_Object_Pool *get_bufferlike_pool
Makes and return a bufferlike header pool for objects of a given size. If a pool for objects of that size already exists, no new pool will be created and the pointer to the existing pool is returned.
size_t get_max_buffer_address
Calculates the maximum buffer address and returns it. This is done by looping through all the sized pools, and finding the pool whose end_arena_memory field is the highest. Notice that arenas in each pool are not necessarily located directly next to each other in memory, and the last arena in the pool's list may not be located at the highest memory address.
size_t get_min_buffer_address
Calculates the minimum buffer address and returns it. Loops through all sized pools, and finds the one with the smallest start_arena_memory field. Notice that the memory region between get_min_buffer_address and get_max_buffer_address may be fragmented, and parts of it may not be available for Parrot to use directly (such as bookkeeping data for the OS memory manager).
size_t get_max_pmc_address
Returns the maximum memory address used by the pmc_pool.
size_t get_min_pmc_address
Returns the minimum memory address used by the pmc_pool. Notice that the memory region between get_min_pmc_address and get_max_pmc_address may be fragmented, and not all of it may be used directly by Parrot for storing PMCs.
int is_buffer_ptr
Checks whether the given ptr is located within one of the sized header pools. Returns 1 if it is, and 0 if not.
int is_pmc_ptr
Checks that ptr is actually a PMC pointer. Returns 1 if it is, 0 otherwise.
void Parrot_initialize_header_pools
The initialization routine for the interpreter's header pools. Initializes pools for string headers, constant string headers, buffers, PMCs, PMC_EXTs, and constant PMCs.The string_header_pool and buffer_header_pool are actually both in the sized pools, although no other sized pools are created here.
int Parrot_forall_header_pools
Iterates through header pools, invoking the given callback function on each pool in the list matching the given criteria. Determines which pools to iterate over depending on flags passed to the function. Returns the callback's return value, if non-zero. A non-zero return value from the callback function will terminate the iteration prematurely.
flag is one of
  POOL_PMC
  POOL_BUFFER
  POOL_CONST
  POOL_ALL
Only matching pools will be used. Notice that it is not possible to iterate over certain sets of pools using the provided flags in the single pass. For instance, both the PMC pool and the constant PMC pool cannot be iterated over in a single pass.
arg
This argument is passed on to the iteration function.
pool_iter_fn
Called with (Parrot_Interp, Small_Object_Pool *, int flag, void *arg). If the function returns a non-zero value, iteration will stop.
static void free_pool
Frees a pool and all of its arenas. Loops through the list of arenas backwards and returns each to the memory manager. Then, frees the pool structure itself.
static int sweep_cb_buf
Performs a final garbage collection sweep, then frees the pool. Calls Parrot_gc_sweep to perform the sweep, and free_pool to free the pool and all its arenas.
static int sweep_cb_pmc
Performs a garbage collection sweep of the given pmc pool, then frees it. Calls Parrot_gc_sweep to perform the sweep, and free_pool to free the pool and all its arenas. Always returns 0.
void Parrot_destroy_header_pools
Performs a garbage collection sweep on all pools, then frees them. Calls Parrot_forall_header_pools to loop over all the pools, passing sweep_cb_pmc and sweep_cb_buf callback routines. Frees the array of sized header pointers in the Arenas structure too.
static void fix_pmc_syncs
Walks through the given arena, looking for all live and shared PMCs, transferring their sync values to the destination interpreter.
void Parrot_merge_header_pools
Merges the header pools of source_interp into those of dest_interp. (Used to deal with shared objects left after interpreter destruction.)

SEE ALSO

include/parrot/gc_pools.h.

HISTORY

Initial version by Mike Lambert on 2002.05.27.