[svn:parrot] r49054 - branches/string_gc_encapsulate/src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Sep 16 11:01:54 UTC 2010


Author: bacek
Date: Thu Sep 16 11:01:53 2010
New Revision: 49054
URL: https://trac.parrot.org/parrot/changeset/49054

Log:
Shuffle functions around. Restore build and almost finish String GC encapsulting. Still some polish required

Modified:
   branches/string_gc_encapsulate/src/gc/alloc_resources.c
   branches/string_gc_encapsulate/src/gc/gc_ms.c
   branches/string_gc_encapsulate/src/gc/gc_private.h
   branches/string_gc_encapsulate/src/gc/mark_sweep.c
   branches/string_gc_encapsulate/src/gc/string_gc.c

Modified: branches/string_gc_encapsulate/src/gc/alloc_resources.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/alloc_resources.c	Thu Sep 16 11:01:23 2010	(r49053)
+++ branches/string_gc_encapsulate/src/gc/alloc_resources.c	Thu Sep 16 11:01:53 2010	(r49054)
@@ -30,10 +30,6 @@
 #define RESOURCE_DEBUG 0
 #define RESOURCE_DEBUG_SIZE 1000000
 
-#define POOL_SIZE (65536 * 2)
-
-typedef void (*compact_f) (Interp *, Memory_Pools * const, Variable_Size_Pool *);
-
 typedef struct string_callback_data {
     Memory_Block *new_block;     /* A pointer to our working block */
     char         *cur_spot;      /* Where we're currently copying to */
@@ -44,17 +40,6 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
-static void alloc_new_block(
-     ARGMOD(Memory_Pools *mem_pools),
-    size_t size,
-    ARGMOD(Variable_Size_Pool *pool),
-    ARGIN(const char *why))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(3)
-        __attribute__nonnull__(4)
-        FUNC_MODIFIES(*mem_pools)
-        FUNC_MODIFIES(*pool);
-
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 static const char * buffer_location(PARROT_INTERP, ARGIN(const Buffer *b))
@@ -118,13 +103,6 @@
         FUNC_MODIFIES(*old_buf)
         FUNC_MODIFIES(*new_pool_ptr);
 
-PARROT_WARN_UNUSED_RESULT
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-static Variable_Size_Pool * new_memory_pool(
-    size_t min_block,
-    NULLOK(compact_f compact));
-
 PARROT_CANNOT_RETURN_NULL
 static UINTVAL pad_pool_size(ARGIN(const Variable_Size_Pool *pool))
         __attribute__nonnull__(1);
@@ -160,10 +138,6 @@
         FUNC_MODIFIES(*mem_pools)
         FUNC_MODIFIES(*pool);
 
-#define ASSERT_ARGS_alloc_new_block __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(mem_pools) \
-    , PARROT_ASSERT_ARG(pool) \
-    , PARROT_ASSERT_ARG(why))
 #define ASSERT_ARGS_buffer_location __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(b))
@@ -196,7 +170,6 @@
     , PARROT_ASSERT_ARG(pool) \
     , PARROT_ASSERT_ARG(old_buf) \
     , PARROT_ASSERT_ARG(new_pool_ptr))
-#define ASSERT_ARGS_new_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_pad_pool_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(pool))
 #define ASSERT_ARGS_Parrot_gc_merge_buffer_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -217,69 +190,6 @@
 
 /*
 
-=item C<static void alloc_new_block( Memory_Pools *mem_pools, size_t size,
-Variable_Size_Pool *pool, const char *why)>
-
-Allocate a new memory block. We allocate either the requested size or the
-default size, whichever is larger. Add the new block to the given memory
-pool. The given C<char *why> text is used for debugging.
-
-=cut
-
-*/
-
-static void
-alloc_new_block(
-        ARGMOD(Memory_Pools *mem_pools),
-        size_t size,
-        ARGMOD(Variable_Size_Pool *pool),
-        ARGIN(const char *why))
-{
-    ASSERT_ARGS(alloc_new_block)
-    Memory_Block *new_block;
-
-    const size_t alloc_size = (size > pool->minimum_block_size)
-            ? size : pool->minimum_block_size;
-
-#if RESOURCE_DEBUG
-    fprintf(stderr, "new_block (%s) size %u -> %u\n",
-        why, size, alloc_size);
-#else
-    UNUSED(why)
-#endif
-
-    /* Allocate a new block. Header info's on the front */
-    new_block = (Memory_Block *)mem_internal_allocate_zeroed(
-        sizeof (Memory_Block) + alloc_size);
-
-    if (!new_block) {
-        fprintf(stderr, "out of mem allocsize = %d\n", (int)alloc_size);
-        exit(EXIT_FAILURE);
-    }
-
-    new_block->free  = alloc_size;
-    new_block->size  = alloc_size;
-
-    new_block->next  = NULL;
-    new_block->start = (char *)new_block + sizeof (Memory_Block);
-    new_block->top   = new_block->start;
-
-    /* Note that we've allocated it */
-    mem_pools->memory_allocated += alloc_size;
-
-    /* If this is for a public pool, add it to the list */
-    new_block->prev = pool->top_block;
-
-    /* If we're not first, then tack us on the list */
-    if (pool->top_block)
-        pool->top_block->next = new_block;
-
-    pool->top_block        = new_block;
-    pool->total_allocated += alloc_size;
-}
-
-/*
-
 =item C<void * mem_allocate(PARROT_INTERP, Memory_Pools *mem_pools, size_t size,
 Variable_Size_Pool *pool)>
 
@@ -354,7 +264,7 @@
              * Mark the block as big block (it has just one item)
              * And don't set big blocks as the top_block.
              */
-            alloc_new_block(mem_pools, size, pool, "compact failed");
+            Parrot_gc_str_alloc_new_block(mem_pools, size, pool, "compact failed");
 
             ++mem_pools->mem_allocs_since_last_collect;
 
@@ -481,7 +391,7 @@
         return;
     }
 
-    alloc_new_block(mem_pools, total_size, pool, "inside compact");
+    Parrot_gc_str_alloc_new_block(mem_pools, total_size, pool, "inside compact");
 
     cb_data.new_block = pool->top_block;
 
@@ -820,63 +730,8 @@
 
 =over 4
 
-=item C<static Variable_Size_Pool * new_memory_pool(size_t min_block, compact_f
-compact)>
-
-Allocate a new C<Variable_Size_Pool> structures, and set some initial values.
-return a pointer to the new pool.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-static Variable_Size_Pool *
-new_memory_pool(size_t min_block, NULLOK(compact_f compact))
-{
-    ASSERT_ARGS(new_memory_pool)
-    Variable_Size_Pool * const pool = mem_internal_allocate_typed(Variable_Size_Pool);
-
-    pool->top_block              = NULL;
-    pool->compact                = compact;
-    pool->minimum_block_size     = min_block;
-    pool->total_allocated        = 0;
-    pool->guaranteed_reclaimable = 0;
-    pool->possibly_reclaimable   = 0;
-    pool->reclaim_factor         = RECLAMATION_FACTOR;
-
-    return pool;
-}
-
-/*
-
-=item C<void initialize_var_size_pools(PARROT_INTERP, Memory_Pools *mem_pools)>
-
-Initialize the managed memory pools. Parrot maintains two C<Variable_Size_Pool>
-structures, the general memory pool and the constant string pool. Create
-and initialize both pool structures, and allocate initial blocks of memory
-for both.
-
-=cut
-
 */
 
-void
-initialize_var_size_pools(SHIM_INTERP, ARGMOD(Memory_Pools *mem_pools))
-{
-    ASSERT_ARGS(initialize_var_size_pools)
-
-    mem_pools->memory_pool   = new_memory_pool(POOL_SIZE, &compact_pool);
-    alloc_new_block(mem_pools, POOL_SIZE, mem_pools->memory_pool, "init");
-
-    /* Constant strings - not compacted */
-    mem_pools->constant_string_pool = new_memory_pool(POOL_SIZE, NULL);
-    alloc_new_block(mem_pools, POOL_SIZE, mem_pools->constant_string_pool, "init");
-}
-
-
 /*
 
 =item C<void merge_pools(Variable_Size_Pool *dest, Variable_Size_Pool *source)>
@@ -938,8 +793,9 @@
     ASSERT_ARGS(check_memory_system)
     size_t i;
 
-    check_var_size_obj_pool(mem_pools->memory_pool);
-    check_var_size_obj_pool(mem_pools->constant_string_pool);
+    check_var_size_obj_pool(mem_pools->string_gc.memory_pool);
+    check_var_size_obj_pool(mem_pools->string_gc.constant_string_pool);
+
     check_fixed_size_obj_pool(mem_pools->pmc_pool);
     check_fixed_size_obj_pool(mem_pools->constant_pmc_pool);
     check_fixed_size_obj_pool(mem_pools->string_header_pool);
@@ -1000,10 +856,6 @@
                     PARROT_ASSERT(PObj_on_free_list_TEST((PObj*)pobj_walker));
                 }
             }
-            else if (pool->mem_pool != NULL) {
-                /*then it means we are a buffer*/
-                check_buffer_ptr((Buffer*)object, pool->mem_pool);
-            }
             object = (PObj*)((char *)object + pool->object_size);
             PARROT_ASSERT(--count);
         }
@@ -1307,8 +1159,8 @@
 {
     ASSERT_ARGS(Parrot_gc_destroy_memory_pools)
 
-    free_memory_pool(mem_pools->constant_string_pool);
-    free_memory_pool(mem_pools->memory_pool);
+    free_memory_pool(mem_pools->string_gc.constant_string_pool);
+    free_memory_pool(mem_pools->string_gc.memory_pool);
 }
 
 /*

Modified: branches/string_gc_encapsulate/src/gc/gc_ms.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/gc_ms.c	Thu Sep 16 11:01:23 2010	(r49053)
+++ branches/string_gc_encapsulate/src/gc/gc_ms.c	Thu Sep 16 11:01:53 2010	(r49054)
@@ -433,7 +433,7 @@
 
     interp->gc_sys->iterate_live_strings = gc_ms_iterate_live_strings;
 
-    initialize_var_size_pools(interp, interp->mem_pools);
+    Parrot_gc_str_initialize(interp, &interp->mem_pools->string_gc);
     initialize_fixed_size_pools(interp, interp->mem_pools);
     Parrot_gc_initialize_fixed_size_pools(interp, interp->mem_pools,
                                           GC_NUM_INITIAL_FIXED_SIZE_POOLS);

Modified: branches/string_gc_encapsulate/src/gc/gc_private.h
==============================================================================
--- branches/string_gc_encapsulate/src/gc/gc_private.h	Thu Sep 16 11:01:23 2010	(r49053)
+++ branches/string_gc_encapsulate/src/gc/gc_private.h	Thu Sep 16 11:01:53 2010	(r49054)
@@ -247,9 +247,6 @@
    hang off the Memory_Pools root structure. */
 
 typedef struct Fixed_Size_Pool {
-
-    struct Variable_Size_Pool *mem_pool; /* Pointer to associated variable-size
-                                            pool, or NULL. */
     size_t object_size;                 /* Size in bytes of an individual pool
                                            object. This size may include
                                            a GC system-specific GC header. */
@@ -533,10 +530,6 @@
         FUNC_MODIFIES(*mem_pools)
         FUNC_MODIFIES(*pool);
 
-void initialize_var_size_pools(SHIM_INTERP, ARGMOD(Memory_Pools *mem_pools))
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*mem_pools);
-
 PARROT_MALLOC
 PARROT_CANNOT_RETURN_NULL
 void * mem_allocate(PARROT_INTERP,
@@ -587,8 +580,6 @@
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(mem_pools) \
     , PARROT_ASSERT_ARG(pool))
-#define ASSERT_ARGS_initialize_var_size_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(mem_pools))
 #define ASSERT_ARGS_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(mem_pools) \
@@ -676,6 +667,17 @@
 /* HEADERIZER BEGIN: src/gc/string_gc.c */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
+void Parrot_gc_str_alloc_new_block(
+     ARGMOD(Memory_Pools *mem_pools),
+    size_t size,
+    ARGMOD(Variable_Size_Pool *pool),
+    ARGIN(const char *why))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(3)
+        __attribute__nonnull__(4)
+        FUNC_MODIFIES(*mem_pools)
+        FUNC_MODIFIES(*pool);
+
 void Parrot_gc_str_allocate_buffer_storage(PARROT_INTERP,
     ARGOUT(Buffer *buffer),
     size_t size)
@@ -701,6 +703,11 @@
         __attribute__nonnull__(3)
         FUNC_MODIFIES(*b);
 
+void Parrot_gc_str_initialize(PARROT_INTERP, ARGMOD(String_GC *gc))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*gc);
+
 void Parrot_gc_str_reallocate_buffer_storage(PARROT_INTERP,
     ARGMOD(Buffer *buffer),
     size_t newsize)
@@ -715,6 +722,10 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*str);
 
+#define ASSERT_ARGS_Parrot_gc_str_alloc_new_block __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(mem_pools) \
+    , PARROT_ASSERT_ARG(pool) \
+    , PARROT_ASSERT_ARG(why))
 #define ASSERT_ARGS_Parrot_gc_str_allocate_buffer_storage \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
@@ -730,6 +741,9 @@
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(gc) \
     , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_Parrot_gc_str_initialize __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(gc))
 #define ASSERT_ARGS_Parrot_gc_str_reallocate_buffer_storage \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \

Modified: branches/string_gc_encapsulate/src/gc/mark_sweep.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/mark_sweep.c	Thu Sep 16 11:01:23 2010	(r49053)
+++ branches/string_gc_encapsulate/src/gc/mark_sweep.c	Thu Sep 16 11:01:53 2010	(r49054)
@@ -510,7 +510,6 @@
     Fixed_Size_Pool * const pmc_pool =
         new_fixed_size_obj_pool(sizeof (PMC), num_headers);
 
-    pmc_pool->mem_pool   = NULL;
     pmc_pool->gc_object  = free_pmc_in_pool;
 
     (interp->gc_sys->init_pool)(interp, pmc_pool);
@@ -575,7 +574,6 @@
 
     pool->gc_object = (gc_object_fn_type)free_buffer;
 
-    pool->mem_pool  = mem_pools->memory_pool;
     (interp->gc_sys->init_pool)(interp, pool);
     return pool;
 }
@@ -604,7 +602,6 @@
 
     pool->last_Arena        = NULL;
     pool->free_list         = NULL;
-    pool->mem_pool          = NULL;
     pool->newfree           = NULL;
     pool->newlast           = NULL;
     pool->object_size       = object_size;
@@ -635,7 +632,6 @@
     if (constant) {
         pool           = new_bufferlike_pool(interp, mem_pools, sizeof (STRING));
         pool->gc_object = NULL;
-        pool->mem_pool = mem_pools->constant_string_pool;
     }
     else
         pool = get_bufferlike_pool(interp, mem_pools, sizeof (STRING));

Modified: branches/string_gc_encapsulate/src/gc/string_gc.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/string_gc.c	Thu Sep 16 11:01:23 2010	(r49053)
+++ branches/string_gc_encapsulate/src/gc/string_gc.c	Thu Sep 16 11:01:53 2010	(r49054)
@@ -21,8 +21,84 @@
 #include "parrot/parrot.h"
 #include "gc_private.h"
 
+typedef void (*compact_f) (Interp *, Memory_Pools * const, Variable_Size_Pool *);
+
+#define POOL_SIZE (65536 * 2)
+
+/* show allocated blocks on stderr */
+#define RESOURCE_DEBUG 0
+#define RESOURCE_DEBUG_SIZE 1000000
+
+#define RECLAMATION_FACTOR 0.20
+
 /* HEADERIZER HFILE: src/gc/gc_private.h */
 
+/* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+
+static void alloc_new_block(
+     ARGMOD(Memory_Pools *mem_pools),
+    size_t size,
+    ARGMOD(Variable_Size_Pool *pool),
+    ARGIN(const char *why))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(3)
+        __attribute__nonnull__(4)
+        FUNC_MODIFIES(*mem_pools)
+        FUNC_MODIFIES(*pool);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+static Variable_Size_Pool * new_memory_pool(
+    size_t min_block,
+    NULLOK(compact_f compact));
+
+#define ASSERT_ARGS_alloc_new_block __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(mem_pools) \
+    , PARROT_ASSERT_ARG(pool) \
+    , PARROT_ASSERT_ARG(why))
+#define ASSERT_ARGS_new_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+/* HEADERIZER END: static */
+
+/*
+
+=item C<void Parrot_gc_str_initialize(PARROT_INTERP, String_GC *gc)>
+
+Initialize the managed memory pools. Parrot maintains two C<Variable_Size_Pool>
+structures, the general memory pool and the constant string pool. Create
+and initialize both pool structures, and allocate initial blocks of memory
+for both.
+
+=cut
+
+*/
+
+void
+Parrot_gc_str_initialize(PARROT_INTERP, ARGMOD(String_GC *gc))
+{
+    ASSERT_ARGS(Parrot_gc_str_initialize)
+
+    gc->memory_pool   = new_memory_pool(POOL_SIZE, &compact_pool);
+    alloc_new_block(interp->mem_pools, POOL_SIZE, gc->memory_pool, "init");
+
+    /* Constant strings - not compacted */
+    gc->constant_string_pool = new_memory_pool(POOL_SIZE, NULL);
+    alloc_new_block(interp->mem_pools, POOL_SIZE, gc->constant_string_pool, "init");
+}
+
+
+void
+Parrot_gc_str_alloc_new_block(
+        ARGMOD(Memory_Pools *mem_pools),
+        size_t size,
+        ARGMOD(Variable_Size_Pool *pool),
+        ARGIN(const char *why))
+{
+    alloc_new_block(mem_pools, size, pool, why);
+}
+
 /*
 
 =item C<void Parrot_gc_str_allocate_buffer_storage(PARROT_INTERP, Buffer
@@ -45,10 +121,10 @@
 
     Buffer_bufstart(buffer) = (void *)aligned_mem(buffer,
         (char *)mem_allocate(interp,
-        interp->mem_pools, new_size, interp->mem_pools->memory_pool));
+        interp->mem_pools, new_size, interp->mem_pools->string_gc.memory_pool));
 
     /* Save pool used to allocate into buffer header */
-    *Buffer_poolptr(buffer) = interp->mem_pools->memory_pool->top_block;
+    *Buffer_poolptr(buffer) = interp->mem_pools->string_gc.memory_pool->top_block;
 
     Buffer_buflen(buffer)   = new_size - sizeof (void *);
 }
@@ -75,7 +151,7 @@
     ASSERT_ARGS(Parrot_gc_str_reallocate_buffer_storage)
     size_t copysize;
     char  *mem;
-    Variable_Size_Pool * const pool = interp->mem_pools->memory_pool;
+    Variable_Size_Pool * const pool = interp->mem_pools->string_gc.memory_pool;
     size_t new_size, needed, old_size;
 
     /* we don't shrink buffers */
@@ -120,7 +196,7 @@
     Buffer_buflen(buffer) = new_size;
 
     /* Save pool used to allocate into buffer header */
-    *Buffer_poolptr(buffer) = interp->mem_pools->memory_pool->top_block;
+    *Buffer_poolptr(buffer) = interp->mem_pools->string_gc.memory_pool->top_block;
 }
 
 /*
@@ -153,8 +229,8 @@
         return;
 
     pool     = PObj_constant_TEST(str)
-                ? interp->mem_pools->constant_string_pool
-                : interp->mem_pools->memory_pool;
+                ? interp->mem_pools->string_gc.constant_string_pool
+                : interp->mem_pools->string_gc.memory_pool;
 
     new_size = ALIGNED_STRING_SIZE(size);
     mem      = (char *)mem_allocate(interp, interp->mem_pools, new_size, pool);
@@ -191,8 +267,8 @@
 
     Variable_Size_Pool * const pool =
         PObj_constant_TEST(str)
-            ? interp->mem_pools->constant_string_pool
-            : interp->mem_pools->memory_pool;
+            ? interp->mem_pools->string_gc.constant_string_pool
+            : interp->mem_pools->string_gc.memory_pool;
 
     /* if the requested size is smaller then buflen, we are done */
     if (newsize <= Buffer_buflen(str))
@@ -281,7 +357,7 @@
         ARGIN(String_GC *gc),
         ARGMOD(Buffer *b))
 {
-    ASSERT_ARGS(free_buffer)
+    ASSERT_ARGS(Parrot_gc_str_free_buffer_storage)
     Variable_Size_Pool * const mem_pool = gc->memory_pool;
 
     /* If there is no allocated buffer - bail out */
@@ -308,6 +384,101 @@
 
     Buffer_buflen(b) = 0;
 }
+
+/*
+=item C<static Variable_Size_Pool * new_memory_pool(size_t min_block, compact_f
+compact)>
+
+Allocate a new C<Variable_Size_Pool> structures, and set some initial values.
+return a pointer to the new pool.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+static Variable_Size_Pool *
+new_memory_pool(size_t min_block, NULLOK(compact_f compact))
+{
+    ASSERT_ARGS(new_memory_pool)
+    Variable_Size_Pool * const pool = mem_internal_allocate_typed(Variable_Size_Pool);
+
+    pool->top_block              = NULL;
+    pool->compact                = compact;
+    pool->minimum_block_size     = min_block;
+    pool->total_allocated        = 0;
+    pool->guaranteed_reclaimable = 0;
+    pool->possibly_reclaimable   = 0;
+    pool->reclaim_factor         = RECLAMATION_FACTOR;
+
+    return pool;
+}
+
+/*
+
+=item C<static void alloc_new_block( Memory_Pools *mem_pools, size_t size,
+Variable_Size_Pool *pool, const char *why)>
+
+Allocate a new memory block. We allocate either the requested size or the
+default size, whichever is larger. Add the new block to the given memory
+pool. The given C<char *why> text is used for debugging.
+
+=cut
+
+*/
+
+static void
+alloc_new_block(
+        ARGMOD(Memory_Pools *mem_pools),
+        size_t size,
+        ARGMOD(Variable_Size_Pool *pool),
+        ARGIN(const char *why))
+{
+    ASSERT_ARGS(alloc_new_block)
+    Memory_Block *new_block;
+
+    const size_t alloc_size = (size > pool->minimum_block_size)
+            ? size : pool->minimum_block_size;
+
+#if RESOURCE_DEBUG
+    fprintf(stderr, "new_block (%s) size %u -> %u\n",
+        why, size, alloc_size);
+#else
+    UNUSED(why)
+#endif
+
+    /* Allocate a new block. Header info's on the front */
+    new_block = (Memory_Block *)mem_internal_allocate_zeroed(
+        sizeof (Memory_Block) + alloc_size);
+
+    if (!new_block) {
+        fprintf(stderr, "out of mem allocsize = %d\n", (int)alloc_size);
+        exit(EXIT_FAILURE);
+    }
+
+    new_block->free  = alloc_size;
+    new_block->size  = alloc_size;
+
+    new_block->next  = NULL;
+    new_block->start = (char *)new_block + sizeof (Memory_Block);
+    new_block->top   = new_block->start;
+
+    /* Note that we've allocated it */
+    mem_pools->memory_allocated += alloc_size;
+
+    /* If this is for a public pool, add it to the list */
+    new_block->prev = pool->top_block;
+
+    /* If we're not first, then tack us on the list */
+    if (pool->top_block)
+        pool->top_block->next = new_block;
+
+    pool->top_block        = new_block;
+    pool->total_allocated += alloc_size;
+}
+
 /*
 
 =back


More information about the parrot-commits mailing list