Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r917:2f1cd052bf40
Date: 2014-03-02 09:26 +0100
http://bitbucket.org/pypy/stmgc/changeset/2f1cd052bf40/

Log:    Unify the two hacks to check that memory is correctly zeroed.

diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c
--- a/c7/stm/gcpage.c
+++ b/c7/stm/gcpage.c
@@ -326,16 +326,10 @@
        major collection, is cleared in sweep_large_objects() for
        large objects, but is not cleared for small objects.
        Clear it now. */
-    object_t *loc2 = (object_t *)(uninitialized_page_stop  - stm_object_pages);
+    object_t *loc2 = (object_t *)(uninitialized_page_stop - stm_object_pages);
     uintptr_t lock2_idx = mark_loc(loc2 - 1) + 1;
 
-#ifdef STM_TESTS
-    long _i;
-    for (_i=0; _i<lock2_idx; _i++) {
-        assert(write_locks[_i] == 0);
-        if (_i == 1000000) break;  /* ok, stop testing */
-    }
-#endif
+    assert_memset_zero(write_locks, lock2_idx);
     memset(write_locks + lock2_idx, 0, sizeof(write_locks) - lock2_idx);
 }
 
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -355,21 +355,25 @@
 }
 #endif
 
+static void assert_memset_zero(void *s, size_t n)
+{
+#ifndef NDEBUG
+    size_t i;
+# ifndef STM_TESTS
+    if (n > 5000) n = 5000;
+# endif
+    n /= 8;
+    for (i = 0; i < n; i++)
+        assert(((uint64_t *)s)[i] == 0);
+#endif
+}
+
 static void check_nursery_at_transaction_start(void)
 {
-#ifndef NDEBUG
     assert((uintptr_t)STM_SEGMENT->nursery_current == _stm_nursery_start);
-    uintptr_t i, limit;
-# ifdef STM_TESTS
-    limit = NURSERY_END - _stm_nursery_start;
-# else
-    limit = 64;
-# endif
-    for (i = 0; i < limit; i += 8) {
-        assert(*(TLPREFIX uint64_t *)(STM_SEGMENT->nursery_current + i) == 0);
-        _duck();
-    }
-#endif
+    assert_memset_zero(REAL_ADDRESS(STM_SEGMENT->segment_base,
+                                    STM_SEGMENT->nursery_current),
+                       NURSERY_END - _stm_nursery_start);
 }
 
 static void major_do_minor_collections(void)
diff --git a/c7/stm/nursery.h b/c7/stm/nursery.h
--- a/c7/stm/nursery.h
+++ b/c7/stm/nursery.h
@@ -17,3 +17,5 @@
 static inline bool must_abort(void) {
     return STM_SEGMENT->nursery_end == NSE_SIGABORT;
 }
+
+static void assert_memset_zero(void *s, size_t n);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to