[svn:parrot] r39005 - branches/gc_internals/src/gc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Thu May 21 02:03:49 UTC 2009
Author: whiteknight
Date: Thu May 21 02:03:47 2009
New Revision: 39005
URL: https://trac.parrot.org/parrot/changeset/39005
Log:
[gc_internals] start collapsing pools.c (nee smallobject.c) into api.c and system.c as appropriate
Modified:
branches/gc_internals/src/gc/api.c
branches/gc_internals/src/gc/pools.c
branches/gc_internals/src/gc/system.c
Modified: branches/gc_internals/src/gc/api.c
==============================================================================
--- branches/gc_internals/src/gc/api.c Thu May 21 01:41:48 2009 (r39004)
+++ branches/gc_internals/src/gc/api.c Thu May 21 02:03:47 2009 (r39005)
@@ -456,6 +456,37 @@
/*
+=item C<void * get_free_buffer(PARROT_INTERP, Small_Object_Pool *pool)>
+
+Gets a free object or buffer from the given C<pool> and returns it. If the
+object is larger then a standard C<PObj> structure, all additional memory is
+cleared.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+static void *
+get_free_buffer(PARROT_INTERP, ARGIN(Small_Object_Pool *pool))
+{
+ ASSERT_ARGS(get_free_buffer)
+ PObj * const buffer = (PObj *)pool->get_free_object(interp, pool);
+
+ /* don't mess around with flags */
+ PObj_bufstart(buffer) = NULL;
+ PObj_buflen(buffer) = 0;
+
+ if (pool->object_size - GC_HEADER_SIZE > sizeof (PObj))
+ memset(buffer + 1, 0,
+ pool->object_size - sizeof (PObj) - GC_HEADER_SIZE);
+
+ return buffer;
+}
+
+/*
+
=item C<void Parrot_gc_free_bufferlike_header(PARROT_INTERP, PObj *obj, size_t
size)>
@@ -795,6 +826,70 @@
/*
+=item C<void Parrot_gc_merge_buffer_pools(PARROT_INTERP, Small_Object_Pool
+*dest, Small_Object_Pool *source)>
+
+Merge pool C<source> into pool C<dest>. Combines the free lists directly,
+moves all arenas to the new pool, and remove the old pool. To merge, the
+two pools must have the same object size, and the same name (if they have
+names).
+
+=cut
+
+*/
+
+static void
+Parrot_gc_merge_buffer_pools(PARROT_INTERP,
+ ARGMOD(Small_Object_Pool *dest), ARGMOD(Small_Object_Pool *source))
+{
+ ASSERT_ARGS(Parrot_gc_merge_buffer_pools)
+ Small_Object_Arena *cur_arena;
+ void **free_list_end;
+
+ PARROT_ASSERT(dest->object_size == source->object_size);
+ PARROT_ASSERT((dest->name == NULL && source->name == NULL)
+ || STREQ(dest->name, source->name));
+
+ dest->total_objects += source->total_objects;
+
+ /* append new free_list to old */
+ /* XXX this won't work with, e.g., gc_gms */
+ free_list_end = &dest->free_list;
+
+ while (*free_list_end)
+ free_list_end = (void **)*free_list_end;
+
+ *free_list_end = source->free_list;
+
+ /* now append source arenas */
+ cur_arena = source->last_Arena;
+
+ while (cur_arena) {
+ size_t total_objects;
+ Small_Object_Arena * const next_arena = cur_arena->prev;
+
+ cur_arena->next = cur_arena->prev = NULL;
+
+ total_objects = cur_arena->total_objects;
+
+ Parrot_append_arena_in_pool(interp, dest, cur_arena,
+ cur_arena->total_objects);
+
+ /* XXX needed? */
+ cur_arena->total_objects = total_objects;
+
+ cur_arena = next_arena;
+ }
+
+ /* remove things from source */
+ source->last_Arena = NULL;
+ source->free_list = NULL;
+ source->total_objects = 0;
+ source->num_free_objects = 0;
+}
+
+/*
+
=item C<static void fix_pmc_syncs(Interp *dest_interp, Small_Object_Pool *pool)>
Walks through the given arena, looking for all live and shared PMCs,
@@ -938,6 +1033,33 @@
/*
+=item C<void free_pool(Small_Object_Pool *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.
+
+=cut
+
+*/
+
+static void
+free_pool(ARGMOD(Small_Object_Pool *pool))
+{
+ ASSERT_ARGS(free_pool)
+ Small_Object_Arena *cur_arena;
+
+ for (cur_arena = pool->last_Arena; cur_arena;) {
+ Small_Object_Arena * const next = cur_arena->prev;
+ mem_internal_free(cur_arena->start_objects);
+ mem_internal_free(cur_arena);
+ cur_arena = next;
+ }
+ mem_internal_free(pool);
+}
+
+
+/*
+
=item C<void Parrot_gc_destroy_memory_pools(PARROT_INTERP)>
Destroys the memory pool and the constant string pool. Loop through both
Modified: branches/gc_internals/src/gc/pools.c
==============================================================================
--- branches/gc_internals/src/gc/pools.c Thu May 21 01:41:48 2009 (r39004)
+++ branches/gc_internals/src/gc/pools.c Thu May 21 02:03:47 2009 (r39005)
@@ -104,140 +104,6 @@
#define CONSTANT_PMC_HEADERS_PER_ALLOC 64
#define GET_SIZED_POOL_IDX(x) ((x) / sizeof (void *))
-/*
-
-=head2 Buffer Header Functions for small-object lookup table
-
-=over 4
-
-=item C<void Parrot_gc_merge_memory_pools(Interp *dest_interp, Interp
-*source_interp)>
-
-Merge the memory pools of two interpreter structures. Merge the general
-memory pool and the constant string pools from C<source_interp> into
-C<dest_interp>.
-
-=cut
-
-*/
-
-void
-Parrot_gc_merge_memory_pools(ARGIN(Interp *dest_interp), ARGIN(Interp *source_interp))
-{
- ASSERT_ARGS(Parrot_gc_merge_memory_pools)
- merge_pools(dest_interp->arena_base->constant_string_pool,
- source_interp->arena_base->constant_string_pool);
-
- merge_pools(dest_interp->arena_base->memory_pool,
- source_interp->arena_base->memory_pool);
-}
-
-/*
-
-=item C<void Parrot_gc_merge_buffer_pools(PARROT_INTERP, Small_Object_Pool
-*dest, Small_Object_Pool *source)>
-
-Merge pool C<source> into pool C<dest>. Combines the free lists directly,
-moves all arenas to the new pool, and remove the old pool. To merge, the
-two pools must have the same object size, and the same name (if they have
-names).
-
-=cut
-
-*/
-
-void
-Parrot_gc_merge_buffer_pools(PARROT_INTERP,
- ARGMOD(Small_Object_Pool *dest), ARGMOD(Small_Object_Pool *source))
-{
- ASSERT_ARGS(Parrot_gc_merge_buffer_pools)
- Small_Object_Arena *cur_arena;
- void **free_list_end;
-
- /* XXX num_free_objects doesn't seem to be accounted correctly in, e.g.,
- * the PMC_EXT pool.
- */
-#if 0
- if (source->num_free_objects == source->total_objects) {
- return;
- }
-#endif
-
- /* PARROT_ASSERT(source->total_objects); */
- PARROT_ASSERT(dest->object_size == source->object_size);
- PARROT_ASSERT((dest->name == NULL && source->name == NULL)
- || STREQ(dest->name, source->name));
-
- dest->total_objects += source->total_objects;
-
- /* append new free_list to old */
- /* XXX this won't work with, e.g., gc_gms */
- free_list_end = &dest->free_list;
-
- while (*free_list_end)
- free_list_end = (void **)*free_list_end;
-
- *free_list_end = source->free_list;
-
- /* now append source arenas */
- cur_arena = source->last_Arena;
-
- while (cur_arena) {
- size_t total_objects;
- Small_Object_Arena * const next_arena = cur_arena->prev;
-
- cur_arena->next = cur_arena->prev = NULL;
-
- total_objects = cur_arena->total_objects;
-
- Parrot_append_arena_in_pool(interp, dest, cur_arena,
- cur_arena->total_objects);
-
- /* XXX needed? */
- cur_arena->total_objects = total_objects;
-
- cur_arena = next_arena;
- }
-
- /* remove things from source */
- /* XXX is this enough? */
- source->last_Arena = NULL;
- source->free_list = NULL;
- source->total_objects = 0;
- source->num_free_objects = 0;
-}
-
-
-/*
-
-=item C<void * get_free_buffer(PARROT_INTERP, Small_Object_Pool *pool)>
-
-Gets a free object or buffer from the given C<pool> and returns it. If the
-object is larger then a standard C<PObj> structure, all additional memory is
-cleared.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-void *
-get_free_buffer(PARROT_INTERP, ARGIN(Small_Object_Pool *pool))
-{
- ASSERT_ARGS(get_free_buffer)
- PObj * const buffer = (PObj *)pool->get_free_object(interp, pool);
-
- /* don't mess around with flags */
- PObj_bufstart(buffer) = NULL;
- PObj_buflen(buffer) = 0;
-
- if (pool->object_size - GC_HEADER_SIZE > sizeof (PObj))
- memset(buffer + 1, 0,
- pool->object_size - sizeof (PObj) - GC_HEADER_SIZE);
-
- return buffer;
-}
/*
@@ -549,166 +415,6 @@
return sized_pools[idx];
}
-
-/*
-
-=item C<size_t get_max_buffer_address(PARROT_INTERP)>
-
-Calculates the maximum buffer address and returns it. This is done by looping
-through all the sized pools, and finding the pool whose C<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.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-size_t
-get_max_buffer_address(PARROT_INTERP)
-{
- ASSERT_ARGS(get_max_buffer_address)
- Arenas * const arena_base = interp->arena_base;
- size_t max = 0;
- UINTVAL i;
-
- for (i = 0; i < arena_base->num_sized; i++) {
- if (arena_base->sized_header_pools[i]) {
- if (arena_base->sized_header_pools[i]->end_arena_memory > max)
- max = arena_base->sized_header_pools[i]->end_arena_memory;
- }
- }
-
- return max;
-}
-
-
-/*
-
-=item C<size_t get_min_buffer_address(PARROT_INTERP)>
-
-Calculates the minimum buffer address and returns it. Loops through all sized
-pools, and finds the one with the smallest C<start_arena_memory> field. Notice
-that the memory region between C<get_min_buffer_address> and
-C<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).
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-size_t
-get_min_buffer_address(PARROT_INTERP)
-{
- ASSERT_ARGS(get_min_buffer_address)
- Arenas * const arena_base = interp->arena_base;
- size_t min = (size_t) -1;
- UINTVAL i;
-
- for (i = 0; i < arena_base->num_sized; i++) {
- if (arena_base->sized_header_pools[i]
- && arena_base->sized_header_pools[i]->start_arena_memory) {
- if (arena_base->sized_header_pools[i]->start_arena_memory < min)
- min = arena_base->sized_header_pools[i]->start_arena_memory;
- }
- }
-
- return min;
-}
-
-
-/*
-
-=item C<size_t get_max_pmc_address(PARROT_INTERP)>
-
-Returns the maximum memory address used by the C<pmc_pool>.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-size_t
-get_max_pmc_address(PARROT_INTERP)
-{
- ASSERT_ARGS(get_max_pmc_address)
- return interp->arena_base->pmc_pool->end_arena_memory;
-}
-
-
-/*
-
-=item C<size_t get_min_pmc_address(PARROT_INTERP)>
-
-Returns the minimum memory address used by the C<pmc_pool>. Notice that the
-memory region between C<get_min_pmc_address> and C<get_max_pmc_address> may be
-fragmented, and not all of it may be used directly by Parrot for storing PMCs.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-size_t
-get_min_pmc_address(PARROT_INTERP)
-{
- ASSERT_ARGS(get_min_pmc_address)
- return interp->arena_base->pmc_pool->start_arena_memory;
-}
-
-
-/*
-
-=item C<int is_buffer_ptr(PARROT_INTERP, const void *ptr)>
-
-Checks whether the given C<ptr> is located within one of the sized
-header pools. Returns C<1> if it is, and C<0> if not.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-int
-is_buffer_ptr(PARROT_INTERP, ARGIN(const void *ptr))
-{
- ASSERT_ARGS(is_buffer_ptr)
- Arenas * const arena_base = interp->arena_base;
- UINTVAL i;
-
- for (i = 0; i < arena_base->num_sized; i++) {
- if (arena_base->sized_header_pools[i]
- && contained_in_pool(arena_base->sized_header_pools[i], ptr))
- return 1;
- }
-
- return 0;
-}
-
-
-/*
-
-=item C<int is_pmc_ptr(PARROT_INTERP, const void *ptr)>
-
-Checks that C<ptr> is actually a PMC pointer. Returns C<1> if it is, C<0>
-otherwise.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-int
-is_pmc_ptr(PARROT_INTERP, ARGIN(const void *ptr))
-{
- ASSERT_ARGS(is_pmc_ptr)
- return contained_in_pool(interp->arena_base->pmc_pool, ptr);
-}
-
-
/*
=item C<void initialize_header_pools(PARROT_INTERP)>
@@ -862,33 +568,6 @@
return 0;
}
-
-/*
-
-=item C<void free_pool(Small_Object_Pool *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.
-
-=cut
-
-*/
-
-void
-free_pool(ARGMOD(Small_Object_Pool *pool))
-{
- ASSERT_ARGS(free_pool)
- Small_Object_Arena *cur_arena;
-
- for (cur_arena = pool->last_Arena; cur_arena;) {
- Small_Object_Arena * const next = cur_arena->prev;
- mem_internal_free(cur_arena->start_objects);
- mem_internal_free(cur_arena);
- cur_arena = next;
- }
- mem_internal_free(pool);
-}
-
/*
=back
Modified: branches/gc_internals/src/gc/system.c
==============================================================================
--- branches/gc_internals/src/gc/system.c Thu May 21 01:41:48 2009 (r39004)
+++ branches/gc_internals/src/gc/system.c Thu May 21 02:03:47 2009 (r39005)
@@ -196,6 +196,116 @@
(size_t)&lo_var_ptr);
}
+/*
+
+=item C<size_t get_max_buffer_address(PARROT_INTERP)>
+
+Calculates the maximum buffer address and returns it. This is done by looping
+through all the sized pools, and finding the pool whose C<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.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static size_t
+get_max_buffer_address(PARROT_INTERP)
+{
+ ASSERT_ARGS(get_max_buffer_address)
+ Arenas * const arena_base = interp->arena_base;
+ size_t max = 0;
+ UINTVAL i;
+
+ for (i = 0; i < arena_base->num_sized; i++) {
+ if (arena_base->sized_header_pools[i]) {
+ if (arena_base->sized_header_pools[i]->end_arena_memory > max)
+ max = arena_base->sized_header_pools[i]->end_arena_memory;
+ }
+ }
+
+ return max;
+}
+
+
+/*
+
+=item C<size_t get_min_buffer_address(PARROT_INTERP)>
+
+Calculates the minimum buffer address and returns it. Loops through all sized
+pools, and finds the one with the smallest C<start_arena_memory> field. Notice
+that the memory region between C<get_min_buffer_address> and
+C<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).
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static size_t
+get_min_buffer_address(PARROT_INTERP)
+{
+ ASSERT_ARGS(get_min_buffer_address)
+ Arenas * const arena_base = interp->arena_base;
+ size_t min = (size_t) -1;
+ UINTVAL i;
+
+ for (i = 0; i < arena_base->num_sized; i++) {
+ if (arena_base->sized_header_pools[i]
+ && arena_base->sized_header_pools[i]->start_arena_memory) {
+ if (arena_base->sized_header_pools[i]->start_arena_memory < min)
+ min = arena_base->sized_header_pools[i]->start_arena_memory;
+ }
+ }
+
+ return min;
+}
+
+
+/*
+
+=item C<size_t get_max_pmc_address(PARROT_INTERP)>
+
+Returns the maximum memory address used by the C<pmc_pool>.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static size_t
+get_max_pmc_address(PARROT_INTERP)
+{
+ ASSERT_ARGS(get_max_pmc_address)
+ return interp->arena_base->pmc_pool->end_arena_memory;
+}
+
+
+/*
+
+=item C<size_t get_min_pmc_address(PARROT_INTERP)>
+
+Returns the minimum memory address used by the C<pmc_pool>. Notice that the
+memory region between C<get_min_pmc_address> and C<get_max_pmc_address> may be
+fragmented, and not all of it may be used directly by Parrot for storing PMCs.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static size_t
+get_min_pmc_address(PARROT_INTERP)
+{
+ ASSERT_ARGS(get_min_pmc_address)
+ return interp->arena_base->pmc_pool->start_arena_memory;
+}
+
+
#ifndef PLATFORM_STACK_WALK
/*
@@ -251,7 +361,7 @@
*/
-void
+static void
trace_mem_block(PARROT_INTERP, size_t lo_var_ptr, size_t hi_var_ptr)
{
ASSERT_ARGS(trace_mem_block)
@@ -309,6 +419,55 @@
return;
}
+
+/*
+
+=item C<int is_buffer_ptr(PARROT_INTERP, const void *ptr)>
+
+Checks whether the given C<ptr> is located within one of the sized
+header pools. Returns C<1> if it is, and C<0> if not.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static int
+is_buffer_ptr(PARROT_INTERP, ARGIN(const void *ptr))
+{
+ ASSERT_ARGS(is_buffer_ptr)
+ Arenas * const arena_base = interp->arena_base;
+ UINTVAL i;
+
+ for (i = 0; i < arena_base->num_sized; i++) {
+ if (arena_base->sized_header_pools[i]
+ && contained_in_pool(arena_base->sized_header_pools[i], ptr))
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+
+=item C<int is_pmc_ptr(PARROT_INTERP, const void *ptr)>
+
+Checks that C<ptr> is actually a PMC pointer. Returns C<1> if it is, C<0>
+otherwise.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+static int
+is_pmc_ptr(PARROT_INTERP, ARGIN(const void *ptr))
+{
+ ASSERT_ARGS(is_pmc_ptr)
+ return contained_in_pool(interp->arena_base->pmc_pool, ptr);
+}
+
+
#endif
/*
More information about the parrot-commits
mailing list