[svn:parrot] r40380 - trunk/src/gc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Sun Aug 2 12:30:46 UTC 2009
Author: whiteknight
Date: Sun Aug 2 12:30:46 2009
New Revision: 40380
URL: https://trac.parrot.org/parrot/changeset/40380
Log:
[TT #895] Some more cleanups to the fixed-size allocation thing. Also, add two new functions to the GC API to act as mem_sys_allocate/mem_sys_free replacements in some situations.
Modified:
trunk/src/gc/api.c
trunk/src/gc/mark_sweep.c
Modified: trunk/src/gc/api.c
==============================================================================
--- trunk/src/gc/api.c Sun Aug 2 12:04:35 2009 (r40379)
+++ trunk/src/gc/api.c Sun Aug 2 12:30:46 2009 (r40380)
@@ -1684,10 +1684,10 @@
ASSERT_ARGS(Parrot_gc_allocate_pmc_attributes)
/* const size_t attr_size = pmc->vtable->attr_size; */
const size_t attr_size = size;
- PMC_Attribute_Pool * pool = Parrot_gc_get_attribute_pool(interp, attr_size);
- void * attrs = Parrot_gc_get_attributes_from_pool(interp, pool);
+ PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp,
+ attr_size);
+ void * const attrs = Parrot_gc_get_attributes_from_pool(interp, pool);
PMC_data(pmc) = attrs;
- pool->num_free_objects--;
return attrs;
}
@@ -1701,14 +1701,29 @@
const size_t size = item_size;
if (data != NULL) {
PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp, size);
- PMC_Attribute_Free_List * const item = (PMC_Attribute_Free_List *)data;
- item->next = pool->free_list;
- pool->free_list = item;
- pool->num_free_objects++;
+ Parrot_gc_free_attributes_from_pool(interp, pool, data);
PMC_data(pmc) = NULL;
}
}
+PARROT_CANNOT_RETURN_NULL
+void *
+Parrot_gc_allocate_fixed_size_storage(PARROT_INTERP, size_t size)
+{
+ ASSERT_ARGS(Parrot_gc_allocate_fixed_size_storage)
+ PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp,
+ size);
+ return Parrot_gc_get_attributes_from_pool(interp, pool);
+}
+
+void
+Parrot_gc_free_fixed_size_storage(PARROT_INTERP, size_t size, ARGMOD(void * data))
+{
+ ASSERT_ARGS(Parrot_gc_free_fixed_size_storage)
+ PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp,
+ size);
+ Parrot_gc_free_atributes_from_pool(interp, pool, data);
+}
/*
=back
Modified: trunk/src/gc/mark_sweep.c
==============================================================================
--- trunk/src/gc/mark_sweep.c Sun Aug 2 12:04:35 2009 (r40379)
+++ trunk/src/gc/mark_sweep.c Sun Aug 2 12:30:46 2009 (r40380)
@@ -1191,15 +1191,29 @@
=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<void Parrot_gc_allocate_new_attributes_arena(PARROT_INTERP,
PMC_Attribute_Pool *pool)>
+Allocate a new arena of fixed-sized data structures for the given pool.
+
+=item C<void Parrot_gc_free_attributes_from_pool(PARROT_INTERP, PMC_Attribute_Pool *pool, void *data)>
+
+Frees a fixed-size data item back to the pool for later reallocation
+
=item C<PMC_Attribute_Pool * Parrot_gc_get_attribute_pool(PARROT_INTERP, 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<PMC_Attribute_Pool * Parrot_gc_create_attrib_pool(PARROT_INTERP, size_t
attrib_size)>
+Create a new pool for fixed-sized data items with the given C<attrib_size>.
+
=back
=cut
@@ -1216,10 +1230,21 @@
Parrot_gc_allocate_new_attributes_arena(interp, pool);
item = pool->free_list;
pool->free_list = item->next;
+ pool->num_free_objects--;
return (void *)item;
}
void
+Parrot_gc_free_attributes_from_pool(PARROT_INTERP, ARGMOD(PMC_Attribute_Pool * pool)
+ ARGMOD(void *data))
+{
+ PMC_Attribute_Free_List * const item = (PMC_Attribute_Free_List *)data;
+ item->next = pool->free_list;
+ pool->free_list = item;
+ pool->num_free_objects++;
+}
+
+static void
Parrot_gc_allocate_new_attributes_arena(PARROT_INTERP, ARGMOD(PMC_Attribute_Pool *pool))
{
ASSERT_ARGS(Parrot_gc_allocate_new_attributes_arena)
@@ -1282,7 +1307,7 @@
}
PARROT_CANNOT_RETURN_NULL
-PMC_Attribute_Pool *
+static PMC_Attribute_Pool *
Parrot_gc_create_attrib_pool(PARROT_INTERP, size_t attrib_size)
{
ASSERT_ARGS(Parrot_gc_create_attrib_pool)
More information about the parrot-commits
mailing list