[svn:parrot] r43446 - branches/gc_encapsulate/src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Jan 13 22:06:37 UTC 2010


Author: bacek
Date: Wed Jan 13 22:06:36 2010
New Revision: 43446
URL: https://trac.parrot.org/parrot/changeset/43446

Log:
Reimplement allocation of attributes in GC MS

Modified:
   branches/gc_encapsulate/src/gc/api.c
   branches/gc_encapsulate/src/gc/gc_ms.c

Modified: branches/gc_encapsulate/src/gc/api.c
==============================================================================
--- branches/gc_encapsulate/src/gc/api.c	Wed Jan 13 17:47:33 2010	(r43445)
+++ branches/gc_encapsulate/src/gc/api.c	Wed Jan 13 22:06:36 2010	(r43446)
@@ -1077,21 +1077,6 @@
 Parrot_gc_allocate_pmc_attributes(PARROT_INTERP, ARGMOD(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_gc_allocate_pmc_attributes)
-#if 0
-    const size_t attr_size = pmc->vtable->attr_size;
-#if GC_USE_FIXED_SIZE_ALLOCATOR
-    PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp,
-        attr_size);
-    void * const attrs = Parrot_gc_get_attributes_from_pool(interp, pool);
-    memset(attrs, 0, attr_size);
-    PMC_data(pmc) = attrs;
-    return attrs;
-#else
-    void * const data =  mem_sys_allocate_zeroed(attr_size);
-    PMC_data(pmc) = data;
-    return data;
-#endif
-#endif
     interp->gc_sys->allocate_attributes(interp, pmc);
     return PMC_data(pmc);
 }
@@ -1109,23 +1094,6 @@
 Parrot_gc_free_pmc_attributes(PARROT_INTERP, ARGMOD(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_gc_free_pmc_attributes)
-    void * const data = PMC_data(pmc);
-
-#if 0
-    if (data) {
-
-#if GC_USE_FIXED_SIZE_ALLOCATOR
-        const size_t attr_size = pmc->vtable->attr_size;
-        const size_t item_size = attr_size < sizeof (void *) ? sizeof (void *) : attr_size;
-        PMC_Attribute_Pool ** const pools = interp->mem_pools->attrib_pools;
-        const size_t idx = item_size - sizeof (void *);
-        Parrot_gc_free_attributes_from_pool(interp, pools[idx], data);
-#else
-        mem_sys_free(PMC_data(pmc));
-        PMC_data(pmc) = NULL;
-#endif
-    }
-#endif
     interp->gc_sys->free_attributes(interp, pmc);
 }
 
@@ -1187,30 +1155,6 @@
 
 /*
 
-=item C<static 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.  Private
-to this file.
-
-*/
-
-static void
-Parrot_gc_free_attributes_from_pool(PARROT_INTERP,
-    ARGMOD(PMC_Attribute_Pool *pool),
-    ARGMOD(void *data))
-{
-    ASSERT_ARGS(Parrot_gc_free_attributes_from_pool)
-    PMC_Attribute_Free_List * const item = (PMC_Attribute_Free_List *)data;
-
-    item->next      = pool->free_list;
-    pool->free_list = item;
-
-    pool->num_free_objects++;
-}
-
-/*
-
 =back
 
 =head1 SEE ALSO

Modified: branches/gc_encapsulate/src/gc/gc_ms.c
==============================================================================
--- branches/gc_encapsulate/src/gc/gc_ms.c	Wed Jan 13 17:47:33 2010	(r43445)
+++ branches/gc_encapsulate/src/gc/gc_ms.c	Wed Jan 13 22:06:36 2010	(r43446)
@@ -77,6 +77,12 @@
         __attribute__nonnull__(3)
         FUNC_MODIFIES(*pool);
 
+static void gc_ms_init_child_inter(
+    ARGIN(Interp *parent_interp),
+    ARGIN(Interp *child_interp))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 static void gc_ms_mark_and_sweep(PARROT_INTERP, UINTVAL flags)
         __attribute__nonnull__(1);
 
@@ -108,6 +114,15 @@
     Parrot_gc_trace_type trace)
         __attribute__nonnull__(1);
 
+static void Parrot_gc_free_attributes_from_pool(PARROT_INTERP,
+    ARGMOD(PMC_Attribute_Pool *pool),
+    ARGMOD(void *data))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3)
+        FUNC_MODIFIES(*pool)
+        FUNC_MODIFIES(*data);
+
 #define ASSERT_ARGS_gc_ms_add_free_object __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(mem_pools) \
     , PARROT_ASSERT_ARG(pool) \
@@ -137,6 +152,9 @@
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(mem_pools) \
     , PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_gc_ms_init_child_inter __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(parent_interp) \
+    , PARROT_ASSERT_ARG(child_interp))
 #define ASSERT_ARGS_gc_ms_mark_and_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms_more_traceable_objects __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -152,6 +170,11 @@
     , PARROT_ASSERT_ARG(arg))
 #define ASSERT_ARGS_gc_ms_trace_active_PMCs __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_gc_free_attributes_from_pool \
+     __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(pool) \
+    , PARROT_ASSERT_ARG(data))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
@@ -180,6 +203,7 @@
     Memory_Pools *mem_pools = mem_allocate_zeroed_typed(Memory_Pools);
     GC_Subsystem *gc = interp->gc_sys;
 
+    gc->init_child_interp  = gc_ms_init_child_inter;
     gc->do_gc_mark         = gc_ms_mark_and_sweep;
     gc->finalize_gc_system = NULL;
 
@@ -205,6 +229,22 @@
 
 /*
 
+=item C<static void gc_ms_init_child_inter(Interp *parent_interp, Interp
+*child_interp)>
+
+Initialize child interp.
+
+=cut
+
+*/
+static void
+gc_ms_init_child_inter(ARGIN(Interp *parent_interp), ARGIN(Interp *child_interp))
+{
+    ASSERT_ARGS(gc_ms_init_child_inter)
+}
+
+/*
+
 =item C<static void gc_ms_mark_and_sweep(PARROT_INTERP, UINTVAL flags)>
 
 Runs the stop-the-world mark & sweep (MS) collector.
@@ -383,13 +423,41 @@
 gc_ms_allocate_attributes(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ASSERT_ARGS(gc_ms_allocate_attributes)
-    return NULL;
+    Memory_Pools * const mem_pools = (Memory_Pools*)interp->gc_sys->gc_private;
+    const size_t         attr_size = pmc->vtable->attr_size;
+#if GC_USE_FIXED_SIZE_ALLOCATOR
+    PMC_Attribute_Pool * const pool = Parrot_gc_get_attribute_pool(interp,
+            mem_pools, attr_size);
+    void * const attrs = Parrot_gc_get_attributes_from_pool(interp, pool);
+    memset(attrs, 0, attr_size);
+    PMC_data(pmc) = attrs;
+    return attrs;
+#else
+    void * const data =  mem_sys_allocate_zeroed(attr_size);
+    PMC_data(pmc) = data;
+    return data;
+#endif
 }
 
 static void
 gc_ms_free_attributes(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ASSERT_ARGS(gc_ms_free_attributes)
+    Memory_Pools * const mem_pools = (Memory_Pools*)interp->gc_sys->gc_private;
+    void                *data      = PMC_data(pmc);
+    if (data) {
+
+#if GC_USE_FIXED_SIZE_ALLOCATOR
+        const size_t attr_size = pmc->vtable->attr_size;
+        const size_t item_size = attr_size < sizeof (void *) ? sizeof (void *) : attr_size;
+        PMC_Attribute_Pool ** const pools = mem_pools->attrib_pools;
+        const size_t idx = item_size - sizeof (void *);
+        Parrot_gc_free_attributes_from_pool(interp, pools[idx], data);
+#else
+        mem_sys_free(PMC_data(pmc));
+        PMC_data(pmc) = NULL;
+#endif
+    }
 }
 
 /*
@@ -660,6 +728,30 @@
 
 /*
 
+=item C<static 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.  Private
+to this file.
+
+*/
+
+static void
+Parrot_gc_free_attributes_from_pool(PARROT_INTERP,
+    ARGMOD(PMC_Attribute_Pool *pool),
+    ARGMOD(void *data))
+{
+    ASSERT_ARGS(Parrot_gc_free_attributes_from_pool)
+    PMC_Attribute_Free_List * const item = (PMC_Attribute_Free_List *)data;
+
+    item->next      = pool->free_list;
+    pool->free_list = item;
+
+    pool->num_free_objects++;
+}
+
+/*
+
 =back
 
 =cut


More information about the parrot-commits mailing list