Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r473:ef085b2228e4
Date: 2013-08-03 14:33 +0200
http://bitbucket.org/pypy/stmgc/changeset/ef085b2228e4/

Log:    stm_repeat_write_barrier()

diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -618,6 +618,16 @@
     }
 }
 
+gcptr stm_RepeatWriteBarrier(gcptr P)
+{
+  assert(!(P->h_tid & GCFLAG_IMMUTABLE));
+  assert(is_private(P));
+  assert(P->h_tid & GCFLAG_WRITE_BARRIER);
+  P->h_tid &= ~GCFLAG_WRITE_BARRIER;
+  gcptrlist_insert(&thread_descriptor->old_objects_to_trace, P);
+  return P;
+}
+
 gcptr stm_WriteBarrier(gcptr P)
 {
   assert(!(P->h_tid & GCFLAG_IMMUTABLE));
diff --git a/c4/et.h b/c4/et.h
--- a/c4/et.h
+++ b/c4/et.h
@@ -198,6 +198,7 @@
 gcptr stm_WriteBarrier(gcptr);
 gcptr stm_RepeatReadBarrier(gcptr);
 gcptr stm_ImmutReadBarrier(gcptr);
+gcptr stm_RepeatWriteBarrier(gcptr);
 gcptr _stm_nonrecord_barrier(gcptr);  /* debugging: read barrier, but
                                          not recording anything */
 int _stm_is_private(gcptr);  /* debugging */
diff --git a/c4/stmgc.h b/c4/stmgc.h
--- a/c4/stmgc.h
+++ b/c4/stmgc.h
@@ -79,12 +79,17 @@
    - a different optimization is to read immutable fields: in order
      to do that, use stm_immut_read_barrier(), which only activates
      on stubs.
+
+   - stm_repeat_write_barrier() can be used on an object on which
+     we already did stm_write_barrier(), but a potential collection
+     can have occurred.
 */
 #if 0     // (optimized version below)
 gcptr stm_read_barrier(gcptr);
 gcptr stm_write_barrier(gcptr);
 gcptr stm_repeat_read_barrier(gcptr);
 gcptr stm_immut_read_barrier(gcptr);
+gcptr stm_repeat_write_barrier(gcptr);   /* <= always returns its argument */
 #endif
 
 /* start a new transaction, calls callback(), and when it returns
@@ -204,5 +209,10 @@
         stm_ImmutReadBarrier(obj)                               \
      :  (obj))
 
+#define stm_repeat_write_barrier(obj)                           \
+    (UNLIKELY((obj)->h_tid & GCFLAG_WRITE_BARRIER) ?            \
+        stm_RepeatWriteBarrier(obj)                             \
+     :  (obj))
+
 
 #endif
diff --git a/c4/test/support.py b/c4/test/support.py
--- a/c4/test/support.py
+++ b/c4/test/support.py
@@ -59,6 +59,7 @@
     gcptr stm_write_barrier(gcptr);
     gcptr stm_repeat_read_barrier(gcptr);
     gcptr stm_immut_read_barrier(gcptr);
+    gcptr stm_repeat_write_barrier(gcptr);
     void stm_perform_transaction(gcptr arg, int (*callback)(gcptr, int));
     void stm_commit_transaction(void);
     void stm_begin_inevitable_transaction(void);
diff --git a/c4/test/test_et.py b/c4/test/test_et.py
--- a/c4/test/test_et.py
+++ b/c4/test/test_et.py
@@ -745,3 +745,20 @@
     assert lib.stm_read_barrier(p2) == p2
     assert lib.stm_read_barrier(pstub) == p2
     assert lib.stm_read_barrier(p) == p2
+
+def test_repeat_write_barrier():
+    n = nalloc_refs(1)
+    lib.stm_push_root(n)
+    minor_collect()
+    n = lib.stm_pop_root()
+    q = nalloc(HDR + WORD)
+    lib.rawsetlong(q, 0, 1298719)
+    n1 = lib.stm_repeat_write_barrier(n)
+    assert n1 == n
+    lib.rawsetptr(n, 0, q)
+    lib.stm_push_root(n)
+    minor_collect()
+    n1 = lib.stm_pop_root()
+    assert n1 == n
+    q = lib.rawgetptr(n, 0)
+    assert lib.rawgetlong(q, 0) == 1298719
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to