[svn:parrot] r40394 - trunk/src/gc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Mon Aug 3 22:50:38 UTC 2009
Author: whiteknight
Date: Mon Aug 3 22:50:35 2009
New Revision: 40394
URL: https://trac.parrot.org/parrot/changeset/40394
Log:
[TT #895] improvement to the fixed-size allocator that uses a lazy allocation approach as suggested by chromatic++. May adapt this same methodology, after testing, to the PObj allocator as well for the win.
Modified:
trunk/src/gc/gc_private.h
trunk/src/gc/mark_sweep.c
Modified: trunk/src/gc/gc_private.h
==============================================================================
--- trunk/src/gc/gc_private.h Mon Aug 3 15:20:49 2009 (r40393)
+++ trunk/src/gc/gc_private.h Mon Aug 3 22:50:35 2009 (r40394)
@@ -124,13 +124,19 @@
#endif /* PARROT_GC_GMS */
+#define GC_USE_LAZY_ALLOCATOR 1
+
typedef struct PMC_Attribute_Pool {
size_t attr_size;
size_t total_objects;
size_t objects_per_alloc;
size_t num_free_objects;
PMC_Attribute_Free_List * free_list;
- PMC_Attribute_Arena * top_arena;
+ PMC_Attribute_Arena * top_arena;
+#if GC_USE_LAZY_ALLOCATOR
+ PMC_Attribute_Free_List * newfree;
+ PMC_Attribute_Free_List * newlast;
+#endif
} PMC_Attribute_Pool;
/* Tracked resource pool */
Modified: trunk/src/gc/mark_sweep.c
==============================================================================
--- trunk/src/gc/mark_sweep.c Mon Aug 3 15:20:49 2009 (r40393)
+++ trunk/src/gc/mark_sweep.c Mon Aug 3 22:50:35 2009 (r40394)
@@ -1244,10 +1244,29 @@
{
ASSERT_ARGS(Parrot_gc_get_attributes_from_pool)
PMC_Attribute_Free_List * item;
- if (pool->top_arena == NULL || pool->free_list == NULL)
+ if (pool->top_arena == NULL
+#if GC_USE_LAZY_ALLOCATOR
+ || (pool->newfree == NULL && pool->free_list == NULL)
+#else
+ || pool->free_list == NULL
+#endif
+ )
Parrot_gc_allocate_new_attributes_arena(interp, pool);
+#if GC_USE_LAZY_ALLOCATOR
+ if(pool->newfree != NULL) {
+ item = pool->newfree;
+ pool->newfree = (PMC_Attribute_Free_List*)((char*)(pool->newfree) + pool->attr_size);
+ if(pool->newfree >= pool->newlast)
+ pool->newfree = NULL;
+ }
+ else {
+ item = pool->free_list;
+ pool->free_list = item->next;
+ }
+#else
item = pool->free_list;
pool->free_list = item->next;
+#endif
pool->num_free_objects--;
return (void *)item;
}
@@ -1269,14 +1288,19 @@
ASSERT_ARGS(Parrot_gc_allocate_new_attributes_arena)
const size_t num_items = pool->objects_per_alloc;
const size_t item_size = pool->attr_size;
+ const size_t total_size = sizeof (PMC_Attribute_Arena) + (pool->attr_size * num_items);
size_t i;
PMC_Attribute_Free_List *list, *next, *first;
PMC_Attribute_Arena * const new_arena = (PMC_Attribute_Arena *)mem_internal_allocate(
- sizeof (PMC_Attribute_Arena) + (pool->attr_size * num_items));
+ total_size);
new_arena->prev = NULL;
new_arena->next = pool->top_arena;
pool->top_arena = new_arena;
first = next = (PMC_Attribute_Free_List *)(new_arena + 1);
+#if GC_USE_LAZY_ALLOCATOR
+ pool->newfree = first;
+ pool->newlast = (PMC_Attribute_Free_List*)((char*)first + (item_size * num_items));
+#else
for (i = 0; i < num_items; i++) {
list = next;
list->next = (PMC_Attribute_Free_List *)((char *)list + item_size);
@@ -1284,6 +1308,7 @@
}
list->next = pool->free_list;
pool->free_list = first;
+#endif
pool->total_objects += num_items;
}
More information about the parrot-commits
mailing list