[svn:parrot] r46049 - branches/compact_pool_revamp/src/gc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Tue Apr 27 07:12:05 UTC 2010
Author: chromatic
Date: Tue Apr 27 07:12:04 2010
New Revision: 46049
URL: https://trac.parrot.org/parrot/changeset/46049
Log:
[GC] Moved PMC attribute allocation functions to a different file, where a good
compiler can optimize them better in gc_ms_allocate_pmc_attributes(). This
improves oofib.pir by 2.109% by making PMC allocation faster.
Modified:
branches/compact_pool_revamp/src/gc/alloc_resources.c
branches/compact_pool_revamp/src/gc/gc_ms.c
branches/compact_pool_revamp/src/gc/gc_private.h
branches/compact_pool_revamp/src/gc/mark_sweep.c
Modified: branches/compact_pool_revamp/src/gc/alloc_resources.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/alloc_resources.c Tue Apr 27 06:00:57 2010 (r46048)
+++ branches/compact_pool_revamp/src/gc/alloc_resources.c Tue Apr 27 07:12:04 2010 (r46049)
@@ -50,9 +50,6 @@
FUNC_MODIFIES(*mem_pools)
FUNC_MODIFIES(*pool);
-static int is_block_almost_full(ARGIN(const Memory_Block *block))
- __attribute__nonnull__(1);
-
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static const char * buffer_location(PARROT_INTERP, ARGIN(const Buffer *b))
@@ -93,6 +90,9 @@
FUNC_MODIFIES(*new_block);
static void free_pool(ARGFREE(Fixed_Size_Pool *pool));
+static int is_block_almost_full(ARGIN(const Memory_Block *block))
+ __attribute__nonnull__(1);
+
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static char * move_one_buffer(PARROT_INTERP,
@@ -152,8 +152,6 @@
PARROT_ASSERT_ARG(mem_pools) \
, PARROT_ASSERT_ARG(pool) \
, PARROT_ASSERT_ARG(why))
-#define ASSERT_ARGS_is_block_almost_full __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(block))
#define ASSERT_ARGS_buffer_location __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(b))
@@ -175,6 +173,8 @@
, PARROT_ASSERT_ARG(pool) \
, PARROT_ASSERT_ARG(new_block))
#define ASSERT_ARGS_free_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_is_block_almost_full __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(block))
#define ASSERT_ARGS_move_one_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pool) \
Modified: branches/compact_pool_revamp/src/gc/gc_ms.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/gc_ms.c Tue Apr 27 06:00:57 2010 (r46048)
+++ branches/compact_pool_revamp/src/gc/gc_ms.c Tue Apr 27 07:12:04 2010 (r46049)
@@ -70,6 +70,12 @@
PARROT_CANNOT_RETURN_NULL
static void * gc_ms_allocate_memory_chunk_zeroed(SHIM_INTERP, size_t size);
+PARROT_CANNOT_RETURN_NULL
+static void * gc_ms_allocate_pmc_attributes(PARROT_INTERP, ARGMOD(PMC *pmc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*pmc);
+
PARROT_CAN_RETURN_NULL
static PMC* gc_ms_allocate_pmc_header(PARROT_INTERP, UINTVAL flags)
__attribute__nonnull__(1);
@@ -215,6 +221,35 @@
static void gc_ms_unblock_GC_sweep(PARROT_INTERP)
__attribute__nonnull__(1);
+static void Parrot_gc_allocate_new_attributes_arena(
+ ARGMOD(PMC_Attribute_Pool *pool))
+ __attribute__nonnull__(1)
+ FUNC_MODIFIES(*pool);
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
+static PMC_Attribute_Pool * Parrot_gc_create_attrib_pool(size_t attrib_idx);
+
+PARROT_CANNOT_RETURN_NULL
+static PMC_Attribute_Pool * Parrot_gc_get_attribute_pool(SHIM_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t attrib_size)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*mem_pools);
+
+PARROT_CANNOT_RETURN_NULL
+static void * Parrot_gc_get_attributes_from_pool(PARROT_INTERP,
+ ARGMOD(PMC_Attribute_Pool * pool))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(* pool);
+
+static void Parrot_gc_initialize_fixed_size_pools(SHIM_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t init_num_pools)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*mem_pools);
+
#define ASSERT_ARGS_gc_ms_active_sized_buffers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(mem_pools))
#define ASSERT_ARGS_gc_ms_add_free_object __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -233,6 +268,9 @@
#define ASSERT_ARGS_gc_ms_allocate_memory_chunk __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_gc_ms_allocate_memory_chunk_zeroed \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_gc_ms_allocate_pmc_attributes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_gc_ms_allocate_pmc_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_gc_ms_allocate_string_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -308,6 +346,19 @@
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_gc_ms_unblock_GC_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_gc_allocate_new_attributes_arena \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_Parrot_gc_create_attrib_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_Parrot_gc_get_attribute_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(mem_pools))
+#define ASSERT_ARGS_Parrot_gc_get_attributes_from_pool \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_Parrot_gc_initialize_fixed_size_pools \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(mem_pools))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -737,7 +788,190 @@
/*
-=item C<void * gc_ms_allocate_pmc_attributes(PARROT_INTERP, PMC *pmc)>
+=over 4
+
+=item C<static void * Parrot_gc_get_attributes_from_pool(PARROT_INTERP,
+PMC_Attribute_Pool * pool)>
+
+Get a new fixed-size storage space from the given pool. The pool contains
+information on the size of the item to allocate already.
+
+=item C<static void Parrot_gc_allocate_new_attributes_arena(PMC_Attribute_Pool
+*pool)>
+
+Allocate a new arena of fixed-sized data structures for the given pool.
+
+=item C<static void Parrot_gc_initialize_fixed_size_pools(PARROT_INTERP,
+Memory_Pools *mem_pools, size_t init_num_pools)>
+
+Initialize the pools (zeroize)
+
+=item C<static PMC_Attribute_Pool * Parrot_gc_get_attribute_pool(PARROT_INTERP,
+Memory_Pools *mem_pools, size_t attrib_size)>
+
+Find a fixed-sized data structure pool given the size of the object to
+allocate. If the pool does not exist, create it.
+
+=item C<static PMC_Attribute_Pool * Parrot_gc_create_attrib_pool(size_t
+attrib_idx)>
+
+Create a new pool for fixed-sized data items with the given C<attrib_size>.
+
+=back
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static void *
+Parrot_gc_get_attributes_from_pool(PARROT_INTERP, ARGMOD(PMC_Attribute_Pool * pool))
+{
+ ASSERT_ARGS(Parrot_gc_get_attributes_from_pool)
+ PMC_Attribute_Free_List *item;
+
+#if GC_USE_LAZY_ALLOCATOR
+ if (pool->free_list) {
+ item = pool->free_list;
+ pool->free_list = item->next;
+ }
+ else if (pool->newfree) {
+ item = pool->newfree;
+ pool->newfree = (PMC_Attribute_Free_List *)
+ ((char *)(pool->newfree) + pool->attr_size);
+ if (pool->newfree >= pool->newlast)
+ pool->newfree = NULL;
+ }
+ else {
+ Parrot_gc_allocate_new_attributes_arena(pool);
+ return Parrot_gc_get_attributes_from_pool(interp, pool);
+ }
+#else
+ if (pool->free_list == NULL)
+ Parrot_gc_allocate_new_attributes_arena(pool);
+ item = pool->free_list;
+ pool->free_list = item->next;
+#endif
+
+ pool->num_free_objects--;
+ return (void *)item;
+}
+
+
+static void
+Parrot_gc_allocate_new_attributes_arena(ARGMOD(PMC_Attribute_Pool *pool))
+{
+ ASSERT_ARGS(Parrot_gc_allocate_new_attributes_arena)
+ PMC_Attribute_Free_List *next;
+
+ const size_t num_items = pool->objects_per_alloc;
+ const size_t item_size = pool->attr_size;
+ const size_t item_space = item_size * num_items;
+ const size_t total_size = sizeof (PMC_Attribute_Arena) + item_space;
+
+ PMC_Attribute_Arena * const new_arena = (PMC_Attribute_Arena *)mem_internal_allocate(
+ total_size);
+
+ new_arena->prev = NULL;
+ new_arena->next = pool->top_arena;
+ pool->top_arena = new_arena;
+ next = (PMC_Attribute_Free_List *)(new_arena + 1);
+
+#if GC_USE_LAZY_ALLOCATOR
+ pool->newfree = next;
+ pool->newlast = (PMC_Attribute_Free_List *)((char *)next + item_space);
+#else
+ pool->free_list = next;
+ for (i = 0; i < num_items; i++) {
+ list = next;
+ list->next = (PMC_Attribute_Free_List *)((char *)list + item_size);
+ next = list->next;
+ }
+ list->next = pool->free_list;
+#endif
+
+ pool->num_free_objects += num_items;
+ pool->total_objects += num_items;
+}
+
+static void
+Parrot_gc_initialize_fixed_size_pools(SHIM_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t init_num_pools)
+{
+ ASSERT_ARGS(Parrot_gc_initialize_fixed_size_pools)
+ PMC_Attribute_Pool **pools;
+ const size_t total_size = (init_num_pools + 1) * sizeof (void *);
+
+ pools = (PMC_Attribute_Pool **)mem_internal_allocate(total_size);
+ memset(pools, 0, total_size);
+
+ mem_pools->attrib_pools = pools;
+ mem_pools->num_attribs = init_num_pools;
+}
+
+
+PARROT_CANNOT_RETURN_NULL
+static PMC_Attribute_Pool *
+Parrot_gc_get_attribute_pool(SHIM_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t attrib_size)
+{
+ ASSERT_ARGS(Parrot_gc_get_attribute_pool)
+
+ PMC_Attribute_Pool **pools = mem_pools->attrib_pools;
+ const size_t idx = (attrib_size < sizeof (void *))
+ ? 0
+ : attrib_size - sizeof (void *);
+
+ if (mem_pools->num_attribs <= idx) {
+ const size_t total_length = idx + GC_ATTRIB_POOLS_HEADROOM;
+ const size_t total_size = total_length * sizeof (void *);
+ const size_t current_size = mem_pools->num_attribs;
+ const size_t diff = total_length - current_size;
+
+ pools = (PMC_Attribute_Pool **)mem_internal_realloc(pools, total_size);
+ memset(pools + current_size, 0, diff * sizeof (void *));
+ mem_pools->attrib_pools = pools;
+ mem_pools->num_attribs = total_length;
+ }
+
+ if (!pools[idx]) {
+ PMC_Attribute_Pool * const pool = Parrot_gc_create_attrib_pool(idx);
+ /* Create the first arena now, so we don't have to check for it later */
+ Parrot_gc_allocate_new_attributes_arena(pool);
+ pools[idx] = pool;
+ }
+
+ return pools[idx];
+}
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
+static PMC_Attribute_Pool *
+Parrot_gc_create_attrib_pool(size_t attrib_idx)
+{
+ ASSERT_ARGS(Parrot_gc_create_attrib_pool)
+ const size_t attrib_size = attrib_idx + sizeof (void *);
+ const size_t num_objs_raw =
+ (GC_FIXED_SIZE_POOL_SIZE - sizeof (PMC_Attribute_Arena)) / attrib_size;
+ const size_t num_objs = (num_objs_raw == 0)?(1):(num_objs_raw);
+ PMC_Attribute_Pool * const newpool = mem_internal_allocate_typed(PMC_Attribute_Pool);
+
+ newpool->attr_size = attrib_size;
+ newpool->total_objects = 0;
+ newpool->objects_per_alloc = num_objs;
+ newpool->num_free_objects = 0;
+ newpool->free_list = NULL;
+ newpool->top_arena = NULL;
+
+ return newpool;
+}
+
+
+/*
+
+=item C<static void * gc_ms_allocate_pmc_attributes(PARROT_INTERP, PMC *pmc)>
Allocates a new attribute structure for a PMC if it has the auto_attrs flag
set.
@@ -747,7 +981,7 @@
*/
PARROT_CANNOT_RETURN_NULL
-void *
+static void *
gc_ms_allocate_pmc_attributes(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(gc_ms_allocate_pmc_attributes)
Modified: branches/compact_pool_revamp/src/gc/gc_private.h
==============================================================================
--- branches/compact_pool_revamp/src/gc/gc_private.h Tue Apr 27 06:00:57 2010 (r46048)
+++ branches/compact_pool_revamp/src/gc/gc_private.h Tue Apr 27 07:12:04 2010 (r46049)
@@ -396,26 +396,6 @@
ARGIN(const Fixed_Size_Pool *pool))
__attribute__nonnull__(2);
-PARROT_CANNOT_RETURN_NULL
-PMC_Attribute_Pool * Parrot_gc_get_attribute_pool(SHIM_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t attrib_size)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*mem_pools);
-
-PARROT_CANNOT_RETURN_NULL
-void * Parrot_gc_get_attributes_from_pool(PARROT_INTERP,
- ARGMOD(PMC_Attribute_Pool * pool))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(* pool);
-
-void Parrot_gc_initialize_fixed_size_pools(SHIM_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t init_num_pools)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*mem_pools);
-
void Parrot_gc_run_init(SHIM_INTERP, ARGMOD(Memory_Pools *mem_pools))
__attribute__nonnull__(2)
FUNC_MODIFIES(*mem_pools);
@@ -462,15 +442,6 @@
, PARROT_ASSERT_ARG(new_arena))
#define ASSERT_ARGS_Parrot_gc_clear_live_bits __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pool))
-#define ASSERT_ARGS_Parrot_gc_get_attribute_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(mem_pools))
-#define ASSERT_ARGS_Parrot_gc_get_attributes_from_pool \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(pool))
-#define ASSERT_ARGS_Parrot_gc_initialize_fixed_size_pools \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(mem_pools))
#define ASSERT_ARGS_Parrot_gc_run_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(mem_pools))
#define ASSERT_ARGS_Parrot_gc_sweep_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -594,12 +565,6 @@
void * gc_ms_allocate_fixed_size_storage(PARROT_INTERP, size_t size)
__attribute__nonnull__(1);
-PARROT_CANNOT_RETURN_NULL
-void * gc_ms_allocate_pmc_attributes(PARROT_INTERP, ARGMOD(PMC *pmc))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*pmc);
-
void gc_ms_allocate_string_storage(PARROT_INTERP,
ARGOUT(STRING *str),
size_t size)
@@ -633,9 +598,6 @@
#define ASSERT_ARGS_gc_ms_allocate_fixed_size_storage \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_gc_ms_allocate_pmc_attributes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_gc_ms_allocate_string_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(str))
Modified: branches/compact_pool_revamp/src/gc/mark_sweep.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/mark_sweep.c Tue Apr 27 06:00:57 2010 (r46048)
+++ branches/compact_pool_revamp/src/gc/mark_sweep.c Tue Apr 27 07:12:04 2010 (r46049)
@@ -77,15 +77,6 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*mem_pools);
-static void Parrot_gc_allocate_new_attributes_arena(
- ARGMOD(PMC_Attribute_Pool *pool))
- __attribute__nonnull__(1)
- FUNC_MODIFIES(*pool);
-
-PARROT_CANNOT_RETURN_NULL
-PARROT_MALLOC
-static PMC_Attribute_Pool * Parrot_gc_create_attrib_pool(size_t attrib_idx);
-
#define ASSERT_ARGS_free_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pool) \
, PARROT_ASSERT_ARG(b))
@@ -102,10 +93,6 @@
#define ASSERT_ARGS_new_string_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(mem_pools))
-#define ASSERT_ARGS_Parrot_gc_allocate_new_attributes_arena \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(pool))
-#define ASSERT_ARGS_Parrot_gc_create_attrib_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -914,188 +901,6 @@
return 0;
}
-/*
-
-=over 4
-
-=item C<void * Parrot_gc_get_attributes_from_pool(PARROT_INTERP,
-PMC_Attribute_Pool * pool)>
-
-Get a new fixed-size storage space from the given pool. The pool contains
-information on the size of the item to allocate already.
-
-=item C<static void Parrot_gc_allocate_new_attributes_arena(PMC_Attribute_Pool
-*pool)>
-
-Allocate a new arena of fixed-sized data structures for the given pool.
-
-=item C<void Parrot_gc_initialize_fixed_size_pools(PARROT_INTERP, Memory_Pools
-*mem_pools, size_t init_num_pools)>
-
-Initialize the pools (zeroize)
-
-=item C<PMC_Attribute_Pool * Parrot_gc_get_attribute_pool(PARROT_INTERP,
-Memory_Pools *mem_pools, size_t attrib_size)>
-
-Find a fixed-sized data structure pool given the size of the object to
-allocate. If the pool does not exist, create it.
-
-=item C<static PMC_Attribute_Pool * Parrot_gc_create_attrib_pool(size_t
-attrib_idx)>
-
-Create a new pool for fixed-sized data items with the given C<attrib_size>.
-
-=back
-
-=cut
-
-*/
-
-PARROT_CANNOT_RETURN_NULL
-void *
-Parrot_gc_get_attributes_from_pool(PARROT_INTERP, ARGMOD(PMC_Attribute_Pool * pool))
-{
- ASSERT_ARGS(Parrot_gc_get_attributes_from_pool)
- PMC_Attribute_Free_List *item;
-
-#if GC_USE_LAZY_ALLOCATOR
- if (pool->free_list) {
- item = pool->free_list;
- pool->free_list = item->next;
- }
- else if (pool->newfree) {
- item = pool->newfree;
- pool->newfree = (PMC_Attribute_Free_List *)
- ((char *)(pool->newfree) + pool->attr_size);
- if (pool->newfree >= pool->newlast)
- pool->newfree = NULL;
- }
- else {
- Parrot_gc_allocate_new_attributes_arena(pool);
- return Parrot_gc_get_attributes_from_pool(interp, pool);
- }
-#else
- if (pool->free_list == NULL)
- Parrot_gc_allocate_new_attributes_arena(pool);
- item = pool->free_list;
- pool->free_list = item->next;
-#endif
-
- pool->num_free_objects--;
- return (void *)item;
-}
-
-
-static void
-Parrot_gc_allocate_new_attributes_arena(ARGMOD(PMC_Attribute_Pool *pool))
-{
- ASSERT_ARGS(Parrot_gc_allocate_new_attributes_arena)
- PMC_Attribute_Free_List *next;
-
- const size_t num_items = pool->objects_per_alloc;
- const size_t item_size = pool->attr_size;
- const size_t item_space = item_size * num_items;
- const size_t total_size = sizeof (PMC_Attribute_Arena) + item_space;
-
- PMC_Attribute_Arena * const new_arena = (PMC_Attribute_Arena *)mem_internal_allocate(
- total_size);
-
- new_arena->prev = NULL;
- new_arena->next = pool->top_arena;
- pool->top_arena = new_arena;
- next = (PMC_Attribute_Free_List *)(new_arena + 1);
-
-#if GC_USE_LAZY_ALLOCATOR
- pool->newfree = next;
- pool->newlast = (PMC_Attribute_Free_List *)((char *)next + item_space);
-#else
- pool->free_list = next;
- for (i = 0; i < num_items; i++) {
- list = next;
- list->next = (PMC_Attribute_Free_List *)((char *)list + item_size);
- next = list->next;
- }
- list->next = pool->free_list;
-#endif
-
- pool->num_free_objects += num_items;
- pool->total_objects += num_items;
-}
-
-void
-Parrot_gc_initialize_fixed_size_pools(SHIM_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t init_num_pools)
-{
- ASSERT_ARGS(Parrot_gc_initialize_fixed_size_pools)
- PMC_Attribute_Pool **pools;
- const size_t total_size = (init_num_pools + 1) * sizeof (void *);
-
- pools = (PMC_Attribute_Pool **)mem_internal_allocate(total_size);
- memset(pools, 0, total_size);
-
- mem_pools->attrib_pools = pools;
- mem_pools->num_attribs = init_num_pools;
-}
-
-
-PARROT_CANNOT_RETURN_NULL
-PMC_Attribute_Pool *
-Parrot_gc_get_attribute_pool(SHIM_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t attrib_size)
-{
- ASSERT_ARGS(Parrot_gc_get_attribute_pool)
-
- PMC_Attribute_Pool **pools = mem_pools->attrib_pools;
- const size_t idx = (attrib_size < sizeof (void *))
- ? 0
- : attrib_size - sizeof (void *);
-
- if (mem_pools->num_attribs <= idx) {
- const size_t total_length = idx + GC_ATTRIB_POOLS_HEADROOM;
- const size_t total_size = total_length * sizeof (void *);
- const size_t current_size = mem_pools->num_attribs;
- const size_t diff = total_length - current_size;
-
- pools = (PMC_Attribute_Pool **)mem_internal_realloc(pools, total_size);
- memset(pools + current_size, 0, diff * sizeof (void *));
- mem_pools->attrib_pools = pools;
- mem_pools->num_attribs = total_length;
- }
-
- if (!pools[idx]) {
- PMC_Attribute_Pool * const pool = Parrot_gc_create_attrib_pool(idx);
- /* Create the first arena now, so we don't have to check for it later */
- Parrot_gc_allocate_new_attributes_arena(pool);
- pools[idx] = pool;
- }
-
- return pools[idx];
-}
-
-PARROT_CANNOT_RETURN_NULL
-PARROT_MALLOC
-static PMC_Attribute_Pool *
-Parrot_gc_create_attrib_pool(size_t attrib_idx)
-{
- ASSERT_ARGS(Parrot_gc_create_attrib_pool)
- const size_t attrib_size = attrib_idx + sizeof (void *);
- const size_t num_objs_raw =
- (GC_FIXED_SIZE_POOL_SIZE - sizeof (PMC_Attribute_Arena)) / attrib_size;
- const size_t num_objs = (num_objs_raw == 0)?(1):(num_objs_raw);
- PMC_Attribute_Pool * const newpool = mem_internal_allocate_typed(PMC_Attribute_Pool);
-
- newpool->attr_size = attrib_size;
- newpool->total_objects = 0;
- newpool->objects_per_alloc = num_objs;
- newpool->num_free_objects = 0;
- newpool->free_list = NULL;
- newpool->top_arena = NULL;
-
- return newpool;
-}
-
/*
More information about the parrot-commits
mailing list