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

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Sep 22 09:55:55 UTC 2010


Author: bacek
Date: Wed Sep 22 09:55:55 2010
New Revision: 49242
URL: https://trac.parrot.org/parrot/changeset/49242

Log:
Made GC MS2 marking non-recursive. Close TT#1723 after merge back to trunk.

Modified:
   branches/gc_massacre/src/gc/gc_ms2.c

Modified: branches/gc_massacre/src/gc/gc_ms2.c
==============================================================================
--- branches/gc_massacre/src/gc/gc_ms2.c	Wed Sep 22 06:55:03 2010	(r49241)
+++ branches/gc_massacre/src/gc/gc_ms2.c	Wed Sep 22 09:55:55 2010	(r49242)
@@ -24,7 +24,10 @@
 typedef struct MarkSweep_GC {
     /* Allocator for PMC headers */
     struct Pool_Allocator *pmc_allocator;
+    /* Currently allocate objects */
     struct Linked_List    *objects;
+    /* During M&S gather new live objects in this list */
+    struct Linked_List    *new_objects;
 
     /* Allocator for strings */
     struct Pool_Allocator *string_allocator;
@@ -693,15 +696,9 @@
     /* mark it live */
     PObj_live_SET(pmc);
 
-    /* if object is a PMC and contains buffers or PMCs, then attach the PMC
-     * to the chained mark list. */
-    if (PObj_is_special_PMC_TEST(pmc)) {
-        if (PObj_custom_mark_TEST(pmc))
-            VTABLE_mark(interp, pmc);
-    }
+    LIST_REMOVE(self->objects, item);
+    LIST_APPEND(self->new_objects, item);
 
-    if (PMC_metadata(pmc))
-        Parrot_gc_mark_PMC_alive(interp, PMC_metadata(pmc));
 }
 
 /*
@@ -990,17 +987,48 @@
 
     ++self->gc_mark_block_level;
 
+    /* Allocate list for gray objects */
+    self->new_objects = Parrot_list_new(interp);
+
+    /* Trace "roots" into new_objects */
     gc_ms2_mark_pmc_header(interp, PMCNULL);
 
     Parrot_gc_trace_root(interp, NULL, GC_TRACE_FULL);
-
     if (interp->pdb && interp->pdb->debugger) {
         Parrot_gc_trace_root(interp->pdb->debugger, NULL, (Parrot_gc_trace_type)0);
     }
 
+    /* new_objects are "gray" untill fully marked */
+    /* Additional gray objects will appened to new_objects list */
+    /* So, iterate over them in one go */
+    tmp = self->new_objects->first;
+    while (tmp) {
+        PMC *pmc = LLH2Obj_typed(tmp, PMC);
+        /* if object is a PMC and contains buffers or PMCs, then attach the PMC
+         * to the chained mark list. */
+        if (PObj_is_special_PMC_TEST(pmc)) {
+            if (PObj_custom_mark_TEST(pmc))
+                VTABLE_mark(interp, pmc);
+        }
+
+        if (PMC_metadata(pmc))
+            Parrot_gc_mark_PMC_alive(interp, PMC_metadata(pmc));
+
+        tmp = tmp->next;
+    }
+
+    /* At this point of time new_objects contains only live PMCs */
+    /* objects contains "dead" or "constant" PMCs */
+    /* sweep of new_objects will repaint them white */
+    /* sweep of objects will destroy dead objects leaving only "constant" */
+    gc_ms2_sweep_pool(interp, self->pmc_allocator, self->new_objects, gc_ms2_sweep_pmc_cb);
     gc_ms2_sweep_pool(interp, self->pmc_allocator, self->objects, gc_ms2_sweep_pmc_cb);
     gc_ms2_sweep_pool(interp, self->string_allocator, self->strings, gc_ms2_sweep_string_cb);
 
+    /* Replace objects with new_objects. Ignoring "constant" one */
+    list = self->objects;
+    self->objects = self->new_objects;
+    Parrot_list_destroy(interp, list);
 
     interp->gc_sys->stats.header_allocs_since_last_collect = 0;
     interp->gc_sys->stats.mem_used_last_collect            = 0;


More information about the parrot-commits mailing list