NAME
src/gc/resources.c - Allocate and deallocate tracked resources
DESCRIPTION
Functions to manage non-PObj memory, including strings and buffers.
Parrot Memory Management Code
static void alloc_new_block
Allocate a new memory block.
We allocate either the requested size or the default size,
whichever is larger.
Add the new block to the given memory pool.
The given static void *mem_allocate
Allocates memory for headers.Alignment problems history:See http://archive.develooper.com/perl6-internals%40perl.org/msg12310.html for details.- return aligned pointer *if needed* - return strings et al at unaligned i.e.
void* boundaries - remember alignment in a buffer header bit use this in compaction code - reduce alignment to a reasonable value i.e.
MALLOC_ALIGNMENT aka 2*sizeof (size_t) or just 8 (TODO make a config hint)Buffer memory layout:
static const char *buffer_location
Recturns a constant string representing the location of the given PObj static void debug_print_buf
Prints a debug statement with information about the given PObj
char *why
text is used for debugging.
+-----------------+ | ref_count |f | # GC header obj->bufstart -> +-----------------+ | data | v v * if PObj_is_COWable is set, then we have - a ref_count, {inc, dec}remented by 2 always - the lo bit 'f' means 'is being forwarded" - what TAIL_flag was * if PObj_align_FLAG is set, obj->bufstart is aligned like discussed above * obj->buflen is the usable length excluding the optional GC part.
b
in one of the PMC registers. If the PMC is not located in one of the PMC registers of the current context, returns the string "???"
.
b
.Compaction Code
static void compact_pool
Compact the string buffer pool. Does not perform a GC scan, or mark items as being alive in any way.
void Parrot_go_collect
Scan the string pools and compact them. This does not perform a GC mark or sweep run, and does not check whether string buffers are still alive. Redirects to static size_t aligned_size
Determines the size of Buffer static char *aligned_mem
Returns a pointer to the aligned allocated storage for Buffer static size_t aligned_string_size
Determines the size of a string of length int Parrot_in_memory_pool
Determines if the given
compact_pool
.
buffer
which has nominal length len
. The actual size in RAM of the Buffer might be different because of alignment issues.
buffer
, which might not be the same as the pointer to buffeR
because of memory alignment.
len
in RAM, accounting for alignment.
bufstart
pointer points to a location inside the memory pool. Returns 1 if the pointer is in the memory pool, 0 otherwise.Parrot Re/Allocate Code
void Parrot_reallocate
Reallocate the Buffer's buffer memory to the given size. The allocated buffer will not shrink. If the buffer was allocated with Parrot_allocate_aligned the new buffer will also be aligned. As with all reallocation, the new buffer might have moved and the additional memory is not cleared.
void Parrot_reallocate_string
Reallocate the STRING's buffer memory to the given size. The allocated buffer will not shrink. This function sets also void Parrot_allocate
Allocate buffer memory for the given Buffer pointer. The void Parrot_allocate_aligned
Like above, except the void Parrot_allocate_string
Allocate the STRING's buffer memory to the given size. The allocated buffer maybe slightly bigger than the given static Memory_Pool *new_memory_pool
Allocate a new void Parrot_initialize_memory_pools
Initialize the managed memory pools. Parrot maintains two void Parrot_destroy_memory_pools
Destroys the memory pool and the constant string pool. Loop through both pools and destroy all memory blocks contained in them. Once all the blocks are freed, free the pools themselves.
static void merge_pools
Merge two memory pools together. Do this by moving all memory blocks from the void Parrot_merge_memory_pools
Merge the memory pools of two interpreter structures. Merge the general memory pool and the constant string pools from
str->strstart
to the new buffer location, str->bufused
is not changed.
size
has to be a multiple of the word size. PObj_buflen
will be set to exactly the given size
.
size
will be rounded up and the address of the buffer will have the same alignment as a pointer returned by malloc(3) suitable to hold e.g. a FLOATVAL
array.
size
. This function sets also str->strstart
to the new buffer location, str->bufused
is not changed.
Memory_Pool
structures, and set some initial values. return a pointer to the new pool.
Memory_Pool
structures, the general memory pool and the constant string pool. Create and initialize both pool structures, and allocate initial blocks of memory for both.
*source
pool into the *dest
pool. The source
pool is emptied, but is not destroyed here.
source_interp
into dest_interp
.SEE ALSO
include/parrot/resources.h, src/gc/memory.c.
HISTORY
Initial version by Dan on 2001.10.2.