[pypy-commit] stmgc copy-over-original2: in-progress

arigo noreply at buildbot.pypy.org
Fri Jul 26 10:02:47 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: copy-over-original2
Changeset: r443:0dafc3959414
Date: 2013-07-25 22:51 +0200
http://bitbucket.org/pypy/stmgc/changeset/0dafc3959414/

Log:	in-progress

diff --git a/c4/dbgmem.c b/c4/dbgmem.c
--- a/c4/dbgmem.c
+++ b/c4/dbgmem.c
@@ -70,6 +70,10 @@
 
 void stm_free(void *p, size_t sz)
 {
+    if (p == NULL) {
+        assert(sz == 0);
+        return;
+    }
     assert(((intptr_t)((char *)p + sz) & (PAGE_SIZE-1)) == 0);
 
     size_t nb_pages = (sz + PAGE_SIZE - 1) / PAGE_SIZE + 1;
@@ -83,6 +87,14 @@
     _stm_dbgmem(p, sz, PROT_NONE);
 }
 
+void *stm_realloc(void *p, size_t newsz, size_t oldsz)
+{
+    void *r = stm_malloc(newsz);
+    memcpy(r, p, oldsz < newsz ? oldsz : newsz);
+    stm_free(p, oldsz);
+    return r;
+}
+
 int _stm_can_access_memory(char *p)
 {
     long base = ((char *)p - zone_start) / PAGE_SIZE;
diff --git a/c4/dbgmem.h b/c4/dbgmem.h
--- a/c4/dbgmem.h
+++ b/c4/dbgmem.h
@@ -6,6 +6,7 @@
 
 void *stm_malloc(size_t);
 void stm_free(void *, size_t);
+void *stm_realloc(void *, size_t, size_t);
 int _stm_can_access_memory(char *);
 void assert_cleared(char *, size_t);
 
@@ -13,6 +14,7 @@
 
 #define stm_malloc(sz)    malloc(sz)
 #define stm_free(p,sz)    free(p)
+#define stm_realloc(p,newsz,oldsz)  realloc(p,newsz)
 #define assert_cleared(p,sz)     do { } while(0)
 
 #endif
diff --git a/c4/gcpage.c b/c4/gcpage.c
--- a/c4/gcpage.c
+++ b/c4/gcpage.c
@@ -215,6 +215,7 @@
 static gcptr copy_over_original(gcptr obj, gcptr id_copy)
 {
     assert(obj != id_copy);
+    assert(id_copy == (gcptr)obj->h_original);
     assert(!(id_copy->h_revision & 1)); /* not head-revision itself */
 
     /* check a few flags */
diff --git a/c4/lists.c b/c4/lists.c
--- a/c4/lists.c
+++ b/c4/lists.c
@@ -18,7 +18,7 @@
 
 void g2l_delete(struct G2L *g2l)
 {
-  free(g2l->raw_start);
+  stm_free(g2l->raw_start, g2l->raw_end - g2l->raw_start);
   memset(g2l, 0, sizeof(struct G2L));
 }
 
@@ -56,7 +56,7 @@
   long alloc = g2l->raw_end - g2l->raw_start;
   long newalloc = (alloc + extra + (alloc >> 2) + 31) & ~15;
   //fprintf(stderr, "growth: %ld\n", newalloc);
-  char *newitems = malloc(newalloc);
+  char *newitems = stm_malloc(newalloc);
   newg2l.raw_start = newitems;
   newg2l.raw_current = newitems;
   newg2l.raw_end = newitems + newalloc;
@@ -65,7 +65,7 @@
     {
       g2l_insert(&newg2l, item->addr, item->val);
     } G2L_LOOP_END;
-  free(g2l->raw_start);
+  stm_free(g2l->raw_start, g2l->raw_end - g2l->raw_start);
   *g2l = newg2l;
 }
 
@@ -151,7 +151,7 @@
     //fprintf(stderr, "list %p deleted (%ld KB)\n",
     //gcptrlist, gcptrlist->alloc * sizeof(gcptr) / 1024);
   gcptrlist->size = 0;
-  free(gcptrlist->items);
+  stm_free(gcptrlist->items, gcptrlist->alloc * sizeof(gcptr));
   gcptrlist->items = NULL;
   gcptrlist->alloc = 0;
 }
@@ -162,7 +162,8 @@
     return;
 
   size_t nsize = gcptrlist->size * sizeof(gcptr);
-  gcptr *newitems = realloc(gcptrlist->items, nsize);
+  gcptr *newitems = stm_realloc(gcptrlist->items, nsize,
+                                gcptrlist->alloc * sizeof(gcptr));
   if (newitems != NULL || nsize == 0)
     {
       gcptrlist->items = newitems;
@@ -177,11 +178,11 @@
   //fprintf(stderr, "list %p growth to %ld items (%ld KB)\n",
   //          gcptrlist, newalloc, newalloc * sizeof(gcptr) / 1024);
 
-  gcptr *newitems = malloc(newalloc * sizeof(gcptr));
+  gcptr *newitems = stm_malloc(newalloc * sizeof(gcptr));
   long i;
   for (i=0; i<gcptrlist->size; i++)
     newitems[i] = gcptrlist->items[i];
-  free(gcptrlist->items);
+  stm_free(gcptrlist->items, gcptrlist->alloc * sizeof(gcptr));
   gcptrlist->items = newitems;
   gcptrlist->alloc = newalloc;
 }
diff --git a/c4/lists.h b/c4/lists.h
--- a/c4/lists.h
+++ b/c4/lists.h
@@ -1,6 +1,8 @@
 #ifndef _SRCSTM_LISTS_H
 #define _SRCSTM_LISTS_H
 
+#include "dbgmem.h"
+
 /************************************************************/
 
 /* The g2l_xx functions ("global_to_local") are implemented as a tree,
@@ -36,7 +38,7 @@
 void g2l_clear(struct G2L *g2l);
 void g2l_delete(struct G2L *g2l);
 static inline void g2l_delete_not_used_any_more(struct G2L *g2l) {
-    free(g2l->raw_start);
+    stm_free(g2l->raw_start, g2l->raw_end - g2l->raw_start);
 }
 
 static inline int g2l_any_entry(struct G2L *g2l) {
diff --git a/c4/test/test_gcpage.py b/c4/test/test_gcpage.py
--- a/c4/test/test_gcpage.py
+++ b/c4/test/test_gcpage.py
@@ -477,9 +477,12 @@
     lib.stm_commit_transaction()
     lib.stm_begin_inevitable_transaction()
     major_collect()
-    lib.stm_pop_root()
+    p2b = lib.stm_pop_root()
+    check_not_free(p2b)
+    check_not_free(p1)
     p1b = lib.stm_read_barrier(p1)
     check_not_free(p1b)
+    assert p1 != p1b and p1b != p2 and p2 != p1
 
 def test_big_old_object():
     for words in range(80):


More information about the pypy-commit mailing list