Author: Remi Meier <remi.me...@inf.ethz.ch>
Branch: 
Changeset: r1338:410a8bb1bea6
Date: 2014-09-03 13:17 +0200
http://bitbucket.org/pypy/stmgc/changeset/410a8bb1bea6/

Log:    deal with unshared-pages-by-default with an explicit obj-sync after
        allocate_old

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -82,6 +82,66 @@
 
 /************************************************************/
 
+static void _page_wise_synchronize_object_now(object_t *obj)
+{
+    uintptr_t start = (uintptr_t)obj;
+    uintptr_t first_page = start / 4096UL;
+
+    char *realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
+    ssize_t obj_size = stmcb_size_rounded_up((struct object_s *)realobj);
+    assert(obj_size >= 16);
+    uintptr_t end = start + obj_size;
+    uintptr_t last_page = (end - 1) / 4096UL;
+    long i, myself = STM_SEGMENT->segment_num;
+
+    for (; first_page <= last_page; first_page++) {
+
+        uintptr_t copy_size;
+        if (first_page == last_page) {
+            /* this is the final fragment */
+            copy_size = end - start;
+        }
+        else {
+            /* this is a non-final fragment, going up to the
+               page's end */
+            copy_size = 4096 - (start & 4095);
+        }
+        /* double-check that the result fits in one page */
+        assert(copy_size > 0);
+        assert(copy_size + (start & 4095) <= 4096);
+
+        char *dst, *src;
+        src = REAL_ADDRESS(STM_SEGMENT->segment_base, start);
+        for (i = 0; i < NB_SEGMENTS; i++) {
+            if (i == myself)
+                continue;
+
+            dst = REAL_ADDRESS(get_segment_base(i), start);
+            if (is_private_page(i, first_page)) {
+                /* The page is a private page.  We need to diffuse this
+                   fragment of object from the shared page to this private
+                   page. */
+                if (copy_size == 4096)
+                    pagecopy(dst, src);
+                else
+                    memcpy(dst, src, copy_size);
+            }
+            else {
+                assert(!memcmp(dst, src, copy_size));  /* same page */
+            }
+        }
+
+        start = (start + 4096) & ~4095;
+    }
+}
+
+void _push_obj_to_other_segments(object_t *obj)
+{
+    acquire_privatization_lock();
+    _page_wise_synchronize_object_now(obj);
+    release_privatization_lock();
+}
+
 static void _finish_transaction()
 {
     stm_thread_local_t *tl = STM_SEGMENT->running_thread;
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -72,6 +72,7 @@
 
 long stm_can_move(object_t *obj);
 void _stm_test_switch(stm_thread_local_t *tl);
+void _push_obj_to_other_segments(object_t *obj);
 
 char *_stm_get_segment_base(long index);
 bool _stm_in_transaction(stm_thread_local_t *tl);
diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -38,6 +38,7 @@
 char *_stm_get_segment_base(long index);
 bool _stm_in_transaction(stm_thread_local_t *tl);
 int _stm_get_flags(object_t *obj);
+void _push_obj_to_other_segments(object_t *obj);
 
 object_t *_stm_allocate_old(ssize_t size_rounded_up);
 long stm_can_move(object_t *obj);
@@ -215,12 +216,14 @@
     o = lib._stm_allocate_old(size)
     tid = 42 + size
     lib._set_type_id(o, tid)
+    lib._push_obj_to_other_segments(o)
     return o
 
 def stm_allocate_old_refs(n):
     o = lib._stm_allocate_old(HDR + n * WORD)
     tid = 421420 + n
     lib._set_type_id(o, tid)
+    lib._push_obj_to_other_segments(o)
     return o
 
 def stm_allocate(size):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to