[svn:parrot] r49657 - trunk/src/gc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Oct 25 03:14:53 UTC 2010


Author: chromatic
Date: Mon Oct 25 03:14:53 2010
New Revision: 49657
URL: https://trac.parrot.org/parrot/changeset/49657

Log:
[GC] Changed mark/sweep detector to a macro.

This avoids an instruction jump from the two places it's called.

Modified:
   trunk/src/gc/gc_ms2.c

Modified: trunk/src/gc/gc_ms2.c
==============================================================================
--- trunk/src/gc/gc_ms2.c	Mon Oct 25 03:14:48 2010	(r49656)
+++ trunk/src/gc/gc_ms2.c	Mon Oct 25 03:14:53 2010	(r49657)
@@ -21,6 +21,13 @@
 
 #define PANIC_OUT_OF_MEM(size) failed_allocation(__LINE__, (size))
 
+/* Maybe M&S. Depends on total allocated memory, memory allocated since last
+alloc, and phase of the Moon. */
+#define MAYBE_MARK_AND_SWEEP(interp, self) { \
+    if ((interp)->gc_sys->stats.mem_used_last_collect > (self)->gc_threshold) \
+        gc_ms2_mark_and_sweep((interp), 0); \
+    }
+
 /* Private information */
 typedef struct MarkSweep_GC {
     /* Allocator for PMC headers */
@@ -196,9 +203,6 @@
 static void gc_ms2_mark_pobj_header(PARROT_INTERP, ARGIN_NULLOK(PObj * obj))
         __attribute__nonnull__(1);
 
-static void gc_ms2_maybe_mark_and_sweep(PARROT_INTERP)
-        __attribute__nonnull__(1);
-
 static void gc_ms2_pmc_needs_early_collection(PARROT_INTERP,
     ARGMOD(PMC *pmc))
         __attribute__nonnull__(1)
@@ -335,8 +339,6 @@
     , PARROT_ASSERT_ARG(pmc))
 #define ASSERT_ARGS_gc_ms2_mark_pobj_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_gc_ms2_maybe_mark_and_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms2_pmc_needs_early_collection \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
@@ -683,9 +685,10 @@
 {
     ASSERT_ARGS(gc_ms2_allocate_pmc_header)
     MarkSweep_GC     *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
+    Pool_Allocator   *pool = self->pmc_allocator;
     List_Item_Header *ptr;
 
-    gc_ms2_maybe_mark_and_sweep(interp);
+    MAYBE_MARK_AND_SWEEP(interp, self);
 
     /* Increase used memory. Not precisely accurate due Pool_Allocator paging */
     ++interp->gc_sys->stats.header_allocs_since_last_collect;
@@ -693,8 +696,7 @@
     interp->gc_sys->stats.memory_allocated      += sizeof (PMC);
     interp->gc_sys->stats.mem_used_last_collect += sizeof (PMC);
 
-    ptr = (List_Item_Header *)Parrot_gc_pool_allocate(interp,
-            self->pmc_allocator);
+    ptr = (List_Item_Header *)Parrot_gc_pool_allocate(interp, pool);
     LIST_APPEND(self->objects, ptr);
 
     return LLH2Obj_typed(ptr, PMC);
@@ -814,18 +816,18 @@
 {
     ASSERT_ARGS(gc_ms2_allocate_string_header)
     MarkSweep_GC     *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
+    Pool_Allocator   *pool = self->string_allocator;
     List_Item_Header *ptr;
     STRING           *ret;
 
-    gc_ms2_maybe_mark_and_sweep(interp);
+    MAYBE_MARK_AND_SWEEP(interp, self);
 
     /* Increase used memory. Not precisely accurate due Pool_Allocator paging */
     ++interp->gc_sys->stats.header_allocs_since_last_collect;
     interp->gc_sys->stats.memory_allocated      += sizeof (STRING);
     interp->gc_sys->stats.mem_used_last_collect += sizeof (STRING);
 
-    ptr = (List_Item_Header *)Parrot_gc_pool_allocate(interp,
-            self->string_allocator);
+    ptr = (List_Item_Header *)Parrot_gc_pool_allocate(interp, pool);
     LIST_APPEND(self->strings, ptr);
 
     ret = LLH2Obj_typed(ptr, STRING);
@@ -1448,31 +1450,6 @@
 
 /*
 
-=item C<static void gc_ms2_maybe_mark_and_sweep(PARROT_INTERP)>
-
-Maybe M&S. Depends on total allocated memory, memory allocated since last
-alloc, and phase of the Moon.
-
-=cut
-
-*/
-
-static void
-gc_ms2_maybe_mark_and_sweep(PARROT_INTERP)
-{
-    ASSERT_ARGS(gc_ms2_maybe_mark_and_sweep)
-
-    MarkSweep_GC *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
-
-    /* Collect every ~n bytes */
-    if (interp->gc_sys->stats.mem_used_last_collect > self->gc_threshold) {
-        gc_ms2_mark_and_sweep(interp, 0);
-    }
-}
-
-
-/*
-
 =item C<static size_t gc_ms2_count_used_string_memory(PARROT_INTERP, Linked_List
 *list)>
 


More information about the parrot-commits mailing list