NAME ^

src/headers.c - Header management functions

DESCRIPTION ^

Handles getting of various headers, and pool creation.

Buffer Header Functions for small-object lookup table ^

static void *get_free_buffer

Gets a free object or buffer from the given pool and returns it. If the object is larger then a starndard 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 make_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 make_bufferlike_pool internally, which in turn calls new_bufferlike_pool.

Small_Object_Pool *make_bufferlike_pool

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

Small_Object_Pool *get_bufferlike_pool

Returns a bufferlike header pool for objects of a given size. Does not check to see if the pool already exists, so if the pool is non-existant, this will return an invalid pointer.

PMC *new_pmc_header

Gets a new PMC header from the PMC pool's free list. Guaranteed to return a valid PMC object or else Parrot will panic. Set's the necessary flags for the objects and initializes the PMC data pointer to NULL.

static PMC_EXT *new_pmc_ext

Gets a new free PMC_EXT structure from the PMC_EXT pool. A pointer to the new PMC_EXT is returned. Does not check to ensure the PMC_EXT is non-null before it is returned (yet).

void add_pmc_ext

Obtains a new PMC_EXT structure, and attaches it to the given PMC. Sets the necessary flags associated with the PMC_EXT structure. Ensures that the PMC_EXT structure is marked as "alive" by the GC.

void add_pmc_sync

Adds a Sync* structure to the given PMC. Initializes the PMC's owner field and the synchronization mutext. Does not check to ensure the Sync* is non-null.

STRING *new_string_header

Returns a new STRING structure from the string pool or the constant string pool. Sets default flags on the string object: PObj_is_string_FLAG, PObj_is_COWable_FLAG, and PObj_live_FLAG (for GC). Initializes the data field of the string buffer to NULL.

Buffer *new_buffer_header

Creates and returns a new Buffer from the buffer header pool. Does not check that the pointer is non-null. Calls get_free_buffer to do all the work.

void *new_bufferlike_header

Returns a new buffer-like header from the appropriate sized pool. Does not check to ensure the header is non-null.

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, returns 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

It is called with (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 it's arenas. Loops through the list of arenas backwards and returns each to the memory manager. Then, it frees the pool structure itself.

static int sweep_cb_buf

Performs a final garbage collection sweep, and then frees the pool. Calls Parrot_dod_sweep to perform the sweep, and free_pool to free the pool and all it's arenas.

static int sweep_cb_pmc

Performs a garbage collection sweep of the given pmc pool, and then frees it. Calls Parrot_dod_sweep to perform the sweep, and free_pool to free the pool and all it's arenas. Always returns 0.

void Parrot_destroy_header_pools

Performs a garbage collection sweep on all pools, and 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 destionation interpreter.

void Parrot_merge_header_pools

Merge the header pools of source_interp into those of dest_interp. (Used to deal with shared objects left after interpreter destruction.)

void Parrot_initialize_header_pool_names

UNUSED. Sets the name parameter of the various header pools to a Parrot string structure for the name of the pool.

SEE ALSO ^

include/parrot/headers.h.

HISTORY ^

Initial version by Mike Lambert on 2002.05.27.


parrot