[svn:parrot] r47172 - branches/gc_massacre/src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun May 30 22:23:27 UTC 2010


Author: bacek
Date: Sun May 30 22:23:27 2010
New Revision: 47172
URL: https://trac.parrot.org/parrot/changeset/47172

Log:
Always use lazy allocator in PoolAllocator.

It's proven to be faster.

Modified:
   branches/gc_massacre/src/gc/pool_allocator.c
   branches/gc_massacre/src/gc/pool_allocator.h

Modified: branches/gc_massacre/src/gc/pool_allocator.c
==============================================================================
--- branches/gc_massacre/src/gc/pool_allocator.c	Sun May 30 22:22:07 2010	(r47171)
+++ branches/gc_massacre/src/gc/pool_allocator.c	Sun May 30 22:23:27 2010	(r47172)
@@ -26,8 +26,13 @@
         __attribute__nonnull__(1)
         FUNC_MODIFIES(*pool);
 
+static size_t arena_size(ARGIN(const Pool_Allocator *self))
+        __attribute__nonnull__(1);
+
 #define ASSERT_ARGS_allocate_new_pool_arena __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_arena_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(self))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
@@ -114,7 +119,6 @@
     ASSERT_ARGS(Parrot_gc_pool_allocate)
     Pool_Allocator_Free_List *item;
 
-#if GC_USE_LAZY_ALLOCATOR
     if (pool->free_list) {
         item            = pool->free_list;
         pool->free_list = item->next;
@@ -130,12 +134,6 @@
         allocate_new_pool_arena(pool);
         return Parrot_gc_pool_allocate(interp, pool);
     }
-#else
-    if (pool->free_list == NULL)
-        allocate_new_pool_arena(pool);
-    item            = pool->free_list;
-    pool->free_list = item->next;
-#endif
 
     --pool->num_free_objects;
     return (void *)item;
@@ -170,13 +168,15 @@
 {
     ASSERT_ARGS(Parrot_gc_pool_is_owned)
     Pool_Allocator_Arena *arena = pool->top_arena;
+    /* We can cache this value. All arenas are same size */
+    size_t                a_size = arena_size(pool);
     while (arena) {
         const ptrdiff_t ptr_diff =
             (ptrdiff_t)ptr - (ptrdiff_t)(arena + 1);
 
         if (0 <= ptr_diff
-              && ptr_diff < GC_FIXED_SIZE_POOL_SIZE // It's wrong check.
-        ) //&& ptr_diff % pool->attr_size == 0)
+              && ptr_diff < a_size
+              && ptr_diff % pool->object_size == 0)
             return 1;
 
         arena = arena->prev;
@@ -195,37 +195,45 @@
     const size_t num_items  = pool->objects_per_alloc;
     const size_t item_size  = pool->object_size;
     const size_t item_space = item_size * num_items;
-    size_t total_size = sizeof (Pool_Allocator_Arena) + item_space;
 
     /* Round up to 4kb */
     Pool_Allocator_Arena * const new_arena = (Pool_Allocator_Arena *)mem_internal_allocate(
-        total_size < GC_FIXED_SIZE_POOL_SIZE
-            ? GC_FIXED_SIZE_POOL_SIZE
-            : total_size);
+                                                arena_size(pool));
 
     new_arena->prev = NULL;
     new_arena->next = pool->top_arena;
     pool->top_arena = new_arena;
     next            = (Pool_Allocator_Free_List *)(new_arena + 1);
 
-#if GC_USE_LAZY_ALLOCATOR
     pool->newfree   = next;
     pool->newlast   = (Pool_Allocator_Free_List *)((char *)next + item_space);
-#else
-    pool->free_list = next;
-    for (i = 0; i < num_items; ++i) {
-        list        = next;
-        list->next  = (Pool_Allocator_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;
 }
 
 /*
+=item C<static size_t arena_size(const Pool_Allocator *self)>
+
+Calculate size of Arena.
+
+=cut
+*/
+static size_t
+arena_size(ARGIN(const Pool_Allocator *self))
+{
+    const size_t num_items  = self->objects_per_alloc;
+    const size_t item_size  = self->object_size;
+    const size_t item_space = item_size * num_items;
+    size_t total_size = sizeof (Pool_Allocator_Arena) + item_space;
+
+    /* Round up to 4kb */
+    return total_size < GC_FIXED_SIZE_POOL_SIZE
+                      ? GC_FIXED_SIZE_POOL_SIZE
+                      : total_size;
+}
+
+/*
 
 =back
 

Modified: branches/gc_massacre/src/gc/pool_allocator.h
==============================================================================
--- branches/gc_massacre/src/gc/pool_allocator.h	Sun May 30 22:22:07 2010	(r47171)
+++ branches/gc_massacre/src/gc/pool_allocator.h	Sun May 30 22:23:27 2010	(r47172)
@@ -25,7 +25,6 @@
    this on at the same time that you increase the size of allocated arenas.
    increase *_HEADERS_PER_ALLOC and GC_FIXED_SIZE_POOL_SIZE to be large
    enough to satisfy most startup costs. */
-#define GC_USE_LAZY_ALLOCATOR 1
 
 typedef struct Pool_Allocator_Free_List {
     struct Pool_Allocator_Free_List * next;
@@ -43,10 +42,8 @@
     size_t num_free_objects;
     Pool_Allocator_Free_List * free_list;
     Pool_Allocator_Arena     * top_arena;
-#if GC_USE_LAZY_ALLOCATOR
     Pool_Allocator_Free_List * newfree;
     Pool_Allocator_Free_List * newlast;
-#endif
 } Pool_Allocator;
 
 


More information about the parrot-commits mailing list