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

bacek at svn.parrot.org bacek at svn.parrot.org
Mon Sep 20 09:49:52 UTC 2010


Author: bacek
Date: Mon Sep 20 09:49:51 2010
New Revision: 49164
URL: https://trac.parrot.org/parrot/changeset/49164

Log:
Compact String pool in GC MS2

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	Mon Sep 20 05:38:36 2010	(r49163)
+++ branches/gc_massacre/src/gc/gc_ms2.c	Mon Sep 20 09:49:51 2010	(r49164)
@@ -116,7 +116,9 @@
 static void gc_ms2_block_GC_sweep(PARROT_INTERP)
         __attribute__nonnull__(1);
 
-static void gc_ms2_compact_memory_pool(SHIM_INTERP);
+static void gc_ms2_compact_memory_pool(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
 static size_t gc_ms2_count_used_pmc_memory(PARROT_INTERP,
     ARGIN(Linked_List *list))
         __attribute__nonnull__(1)
@@ -173,6 +175,11 @@
 static int gc_ms2_is_string_ptr(PARROT_INTERP, ARGIN_NULLOK(void *ptr))
         __attribute__nonnull__(1);
 
+static void gc_ms2_iterate_live_strings(PARROT_INTERP,
+    string_iterator_callback callback,
+    ARGIN_NULLOK(void *data))
+        __attribute__nonnull__(1);
+
 static void gc_ms2_mark_and_sweep(PARROT_INTERP, UINTVAL flags)
         __attribute__nonnull__(1);
 
@@ -269,7 +276,8 @@
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms2_block_GC_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_gc_ms2_compact_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_gc_ms2_compact_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms2_count_used_pmc_memory __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(list))
@@ -304,6 +312,8 @@
     , PARROT_ASSERT_ARG(list))
 #define ASSERT_ARGS_gc_ms2_is_string_ptr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_gc_ms2_iterate_live_strings __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms2_mark_and_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_ms2_mark_pmc_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -380,9 +390,11 @@
 
 */
 static void
-gc_ms2_compact_memory_pool(SHIM_INTERP)
+gc_ms2_compact_memory_pool(PARROT_INTERP)
 {
     ASSERT_ARGS(gc_ms2_compact_memory_pool)
+    MarkSweep_GC *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
+    Parrot_gc_str_compact_pool(interp, &self->string_gc);
 }
 
 /*
@@ -602,6 +614,8 @@
                 = gc_ms2_reallocate_memory_chunk_zeroed;
     interp->gc_sys->free_memory_chunk       = gc_ms2_free_memory_chunk;
 
+    interp->gc_sys->iterate_live_strings = gc_ms2_iterate_live_strings;
+
     interp->gc_sys->get_gc_info      = gc_ms2_get_gc_info;
 
     if (interp->parent_interpreter && interp->parent_interpreter->gc_sys) {
@@ -918,13 +932,39 @@
 {
     ASSERT_ARGS(gc_ms2_sweep_string_cb)
     MarkSweep_GC *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
-    STRING       *str  = (STRING *)obj;
+    Buffer       *str  = (Buffer *)obj;
     /* Compact string pool here. Or get rid of "shared buffers" and just free storage */
     if (Buffer_bufstart(str) && !PObj_external_TEST(str))
         Parrot_gc_str_free_buffer_storage(interp, &self->string_gc, str);
 }
 
 
+/*
+=item C<static void gc_ms_iterate_live_strings(PARROT_INTERP,
+string_iterator_callback callback, void *data)>
+
+Iterate over live string invoking callback for each of them. Used during
+compacting of string pool.
+
+=cut
+*/
+static void
+gc_ms2_iterate_live_strings(PARROT_INTERP,
+        string_iterator_callback callback,
+        ARGIN_NULLOK(void *data))
+{
+    ASSERT_ARGS(gc_ms2_iterate_live_strings)
+
+    MarkSweep_GC *self = (MarkSweep_GC *)interp->gc_sys->gc_private;
+    List_Item_Header *tmp = self->strings->first;
+
+    while (tmp) {
+        Buffer *b = LLH2Obj_typed(tmp, Buffer);
+        callback(interp, b, data);
+        tmp = tmp->next;
+    }
+}
+
 
 static void
 gc_ms2_mark_and_sweep(PARROT_INTERP, UINTVAL flags)
@@ -958,6 +998,8 @@
     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);
 
+    gc_ms2_compact_memory_pool(interp);
+
     //if (self->gc_threshold < 1024 * 1024 * 10)
     //    self->gc_threshold *= 1.1;
 


More information about the parrot-commits mailing list