[svn:parrot] r38633 - in branches/gc_api: include/parrot src src/gc src/interp src/string src/string/encoding

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Sat May 9 12:04:02 UTC 2009


Author: whiteknight
Date: Sat May  9 12:04:01 2009
New Revision: 38633
URL: https://trac.parrot.org/parrot/changeset/38633

Log:
[gc_api] move some logic from src/pmc_freeze.c to the gc api, because it was monkeying around in the arenas. I'm still not entirely happy about how pmc_freeze breaks GC encapsulation, need to work on that

Modified:
   branches/gc_api/include/parrot/gc_api.h
   branches/gc_api/src/gc/api.c
   branches/gc_api/src/interp/inter_create.c
   branches/gc_api/src/pmc_freeze.c
   branches/gc_api/src/string/api.c
   branches/gc_api/src/string/encoding/utf16.c
   branches/gc_api/src/string/encoding/utf8.c

Modified: branches/gc_api/include/parrot/gc_api.h
==============================================================================
--- branches/gc_api/include/parrot/gc_api.h	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/include/parrot/gc_api.h	Sat May  9 12:04:01 2009	(r38633)
@@ -381,6 +381,10 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*p);
 
+int Parrot_gc_get_pmc_index(PARROT_INTERP, ARGIN(PMC* pmc))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 void Parrot_gc_initialize(PARROT_INTERP, ARGIN(void *stacktop))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
@@ -466,6 +470,9 @@
 #define ASSERT_ARGS_Parrot_gc_free_pmc_ext __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(p)
+#define ASSERT_ARGS_Parrot_gc_get_pmc_index __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(interp) \
+    || PARROT_ASSERT_ARG(pmc)
 #define ASSERT_ARGS_Parrot_gc_initialize __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(stacktop)

Modified: branches/gc_api/src/gc/api.c
==============================================================================
--- branches/gc_api/src/gc/api.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/gc/api.c	Sat May  9 12:04:01 2009	(r38633)
@@ -1027,6 +1027,53 @@
 
 /*
 
+=item C<int Parrot_gc_get_pmc_index(PARROT_INTERP, PMC* pmc)>
+
+Gets the index of the PMC in the pool. The first PMC in the first pool is 1,
+the second is 2, etc.
+
+=cut
+
+*/
+
+int
+Parrot_gc_get_pmc_index(PARROT_INTERP, ARGIN(PMC* pmc))
+{
+    ASSERT_ARGS(Parrot_gc_get_pmc_index)
+    UINTVAL id = 1;     /* first PMC in first arena */
+    Small_Object_Arena *arena;
+    Small_Object_Pool *pool;
+
+    pmc = (PMC*)PObj_to_ARENA(pmc);
+    pool = interp->arena_base->pmc_pool;
+    for (arena = pool->last_Arena; arena; arena = arena->prev) {
+        const ptrdiff_t ptr_diff = (ptrdiff_t)pmc - (ptrdiff_t)arena->start_objects;
+        if (ptr_diff >= 0 && ptr_diff <
+                (ptrdiff_t)(arena->used * pool->object_size)) {
+            PARROT_ASSERT(ptr_diff % pool->object_size == 0);
+            id += ptr_diff / pool->object_size;
+            return id;
+        }
+        id += arena->total_objects;
+    }
+
+    pool = interp->arena_base->constant_pmc_pool;
+    for (arena = pool->last_Arena; arena; arena = arena->prev) {
+        const ptrdiff_t ptr_diff = (ptrdiff_t)pmc - (ptrdiff_t)arena->start_objects;
+        if (ptr_diff >= 0 && ptr_diff <
+                (ptrdiff_t)(arena->used * pool->object_size)) {
+            PARROT_ASSERT(ptr_diff % pool->object_size == 0);
+            id += ptr_diff / pool->object_size;
+            return id;
+        }
+        id += arena->total_objects;
+    }
+
+    Parrot_ex_throw_from_c_args(interp, NULL, 1, "Couldn't find PMC in arenas");
+}
+
+/*
+
 =back
 
 =head1 SEE ALSO

Modified: branches/gc_api/src/interp/inter_create.c
==============================================================================
--- branches/gc_api/src/interp/inter_create.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/interp/inter_create.c	Sat May  9 12:04:01 2009	(r38633)
@@ -385,7 +385,7 @@
     &&  interp->thread_data
     && (interp->thread_data->state & THREAD_STATE_JOINED)) {
         Parrot_gc_merge_header_pools(interp->parent_interpreter, interp);
-        Parrot_gc_merge_memory_pools(interp->parent_interpreter, interp);
+        Parrot_gc_merge_header_pools(interp->parent_interpreter, interp);
     }
 
     if (interp->arena_base->finalize_gc_system)

Modified: branches/gc_api/src/pmc_freeze.c
==============================================================================
--- branches/gc_api/src/pmc_freeze.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/pmc_freeze.c	Sat May  9 12:04:01 2009	(r38633)
@@ -1374,37 +1374,7 @@
 static UINTVAL
 id_from_pmc(PARROT_INTERP, ARGIN(PMC* pmc))
 {
-    ASSERT_ARGS(id_from_pmc)
-    UINTVAL id = 1;     /* first PMC in first arena */
-    Small_Object_Arena *arena;
-    Small_Object_Pool *pool;
-
-    pmc = (PMC*)PObj_to_ARENA(pmc);
-    pool = interp->arena_base->pmc_pool;
-    for (arena = pool->last_Arena; arena; arena = arena->prev) {
-        const ptrdiff_t ptr_diff = (ptrdiff_t)pmc - (ptrdiff_t)arena->start_objects;
-        if (ptr_diff >= 0 && ptr_diff <
-                (ptrdiff_t)(arena->used * pool->object_size)) {
-            PARROT_ASSERT(ptr_diff % pool->object_size == 0);
-            id += ptr_diff / pool->object_size;
-            return id << 2;
-        }
-        id += arena->total_objects;
-    }
-
-    pool = interp->arena_base->constant_pmc_pool;
-    for (arena = pool->last_Arena; arena; arena = arena->prev) {
-        const ptrdiff_t ptr_diff = (ptrdiff_t)pmc - (ptrdiff_t)arena->start_objects;
-        if (ptr_diff >= 0 && ptr_diff <
-                (ptrdiff_t)(arena->used * pool->object_size)) {
-            PARROT_ASSERT(ptr_diff % pool->object_size == 0);
-            id += ptr_diff / pool->object_size;
-            return id << 2;
-        }
-        id += arena->total_objects;
-    }
-
-    Parrot_ex_throw_from_c_args(interp, NULL, 1, "Couldn't find PMC in arenas");
+    return Parrot_gc_get_pmc_index(interp, pmc) << 2;
 }
 
 /*

Modified: branches/gc_api/src/string/api.c
==============================================================================
--- branches/gc_api/src/string/api.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/string/api.c	Sat May  9 12:04:01 2009	(r38633)
@@ -581,7 +581,7 @@
 
     /* make sure A's big enough for both  */
     if (total_length > a_capacity)
-        Parrot_reallocate_string(interp, a, total_length << 1);
+        Parrot_gc_reallocate_string_storage(interp, a, total_length << 1);
 
     /* A is now ready to receive the contents of B */
 
@@ -823,7 +823,7 @@
     Parrot_str_write_COW(interp, s);
 
     /* Don't check buflen, if we are here, we already checked. */
-    Parrot_reallocate_string(interp,
+    Parrot_gc_reallocate_string_storage(interp,
         s, PObj_buflen(s) + string_max_bytes(interp, s, addlen));
     return s;
 }
@@ -2328,7 +2328,7 @@
     memory = PObj_bufstart(s);
 
     /* Reallocate it the same size
-     * NOTE can't use Parrot_reallocate_string because of the LEA
+     * NOTE can't use Parrot_gc_reallocate_string_storage because of the LEA
      * allocator, where this is a noop for the same size
      *
      * We have to block GC here, as we have a pointer to bufstart
@@ -2456,7 +2456,7 @@
             if (i >= charlen - 2) {
                 /* resize - still len codepoints to go */
                 charlen += len * 2 + 16;
-                Parrot_reallocate_string(interp, result, charlen);
+                Parrot_gc_reallocate_string_storage(interp, result, charlen);
                 /* start can change */
                 dp = (unsigned char *)result->strstart;
             }

Modified: branches/gc_api/src/string/encoding/utf16.c
==============================================================================
--- branches/gc_api/src/string/encoding/utf16.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/string/encoding/utf16.c	Sat May  9 12:04:01 2009	(r38633)
@@ -286,7 +286,7 @@
         p = (UChar *)mem_sys_allocate(src_len * sizeof (UChar));
     }
     else {
-        Parrot_reallocate_string(interp, dest, sizeof (UChar) * src_len);
+        Parrot_gc_reallocate_string_storage(interp, dest, sizeof (UChar) * src_len);
         p = (UChar *)dest->strstart;
     }
     if (src->charset == Parrot_iso_8859_1_charset_ptr ||
@@ -307,7 +307,7 @@
                 p = (UChar *)mem_sys_realloc(p, dest_len * sizeof (UChar));
             else {
                 result->bufused = dest_len * sizeof (UChar);
-                Parrot_reallocate_string(interp, dest,
+                Parrot_gc_reallocate_string_storage(interp, dest,
                                          sizeof (UChar) * dest_len);
                 p = (UChar *)dest->strstart;
             }
@@ -318,7 +318,7 @@
     }
     result->bufused = dest_len * sizeof (UChar);
     if (in_place) {
-        Parrot_reallocate_string(interp, src, src->bufused);
+        Parrot_gc_reallocate_string_storage(interp, src, src->bufused);
         memcpy(src->strstart, p, src->bufused);
         mem_sys_free(p);
     }

Modified: branches/gc_api/src/string/encoding/utf8.c
==============================================================================
--- branches/gc_api/src/string/encoding/utf8.c	Sat May  9 11:42:41 2009	(r38632)
+++ branches/gc_api/src/string/encoding/utf8.c	Sat May  9 12:04:01 2009	(r38633)
@@ -596,7 +596,7 @@
         p = (unsigned char *)mem_sys_allocate(src_len);
     }
     else {
-        Parrot_reallocate_string(interp, dest, src_len);
+        Parrot_gc_reallocate_string_storage(interp, dest, src_len);
         p = (unsigned char *)dest->strstart;
     }
     if (src->charset == Parrot_ascii_charset_ptr) {
@@ -619,7 +619,7 @@
                     p = (unsigned char *)mem_sys_realloc(p, dest_len);
                 else {
                     result->bufused = dest_pos;
-                    Parrot_reallocate_string(interp, dest, dest_len);
+                    Parrot_gc_reallocate_string_storage(interp, dest, dest_len);
                     p = (unsigned char *)dest->strstart;
                 }
             }
@@ -631,7 +631,7 @@
         result->bufused = dest_pos;
     }
     if (in_place) {
-        Parrot_reallocate_string(interp, src, src->bufused);
+        Parrot_gc_reallocate_string_storage(interp, src, src->bufused);
         memcpy(src->strstart, p, src->bufused);
         mem_sys_free(p);
     }


More information about the parrot-commits mailing list