Commits

Armin Rigo committed 0e454af

Better test, bug fixes

  • Participants
  • Parent commits 2943d03
  • Branches gc-small-uniform

Comments (0)

Files changed (5)

File c7/stm/core.h

     TS_INEVITABLE,
 };
 
-static char *stm_object_pages;
+#ifndef STM_TESTS
+static
+#endif
+       char *stm_object_pages;
 static stm_thread_local_t *stm_all_thread_locals = NULL;
 
 static uint8_t write_locks[WRITELOCK_END - WRITELOCK_START];

File c7/stm/smallmalloc.c

             flprev = fl;
             fl = fl->next;
         }
-        else if (_smallmalloc_sweep_keep(p)) {
+        else if (!_smallmalloc_sweep_keep(p)) {
             /* the location should be freed now */
             if (flprev == NULL) {
                 flprev = (struct small_free_loc_s *)p;
             else {
                 assert(flprev->next == fl);
                 flprev->next = (struct small_free_loc_s *)p;
-                flprev->next->next = fl;
+                flprev = (struct small_free_loc_s *)p;
+                flprev->next = fl;
             }
         }
         else {
 uint64_t _stm_total_allocated(void);
 void _stm_mutex_pages_lock(void);
 void _stm_mutex_pages_unlock(void);
+char *stm_object_pages;
 #endif
 
 #define _STM_GCFLAG_WRITE_BARRIER      0x01

File c7/test/support.py

     ...;
 } stm_thread_local_t;
 
+char *stm_object_pages;
+
 void stm_read(object_t *obj);
 /*void stm_write(object_t *obj); use _checked_stm_write() instead */
 object_t *stm_allocate(ssize_t size_rounded_up);

File c7/test/test_smallmalloc.py

 from support import *
+import random
 
 
 def pageof(p):
         BaseTest.setup_method(self, method)
         @ffi.callback("bool(char *)")
         def keep(data):
-            return data in self.keep_me
+            p = ffi.cast("object_t *", data - lib.stm_object_pages)
+            self.has_been_asked_for.append(p)
+            return p in self.keep_me
         lib._stm_smallmalloc_keep = keep
         self._keepalive_keep_function = keep
         self.keep_me = set()
+        self.has_been_asked_for = []
 
     def test_simple_uniform(self):
         page0 = [stm_allocate_old_small(16) for i in range(0, 4096, 16)]
             assert p == seen[0]
             seen.pop(0)
 
-    def test_sweep_freeing(self):
+    def test_sweep_freeing_simple(self):
         p1 = stm_allocate_old_small(16)
         lib._stm_smallmalloc_sweep()
+
+    def test_sweep_freeing_random_subset(self):
+        for i in range(50):
+            page0 = [stm_allocate_old_small(16) for i in range(0, 4096-16, 16)]
+            assert len(set(map(pageof, page0))) == 1
+            tid = lib._get_type_id(page0[0])
+            while len(page0) > 0:
+                self.keep_me = set(random.sample(page0, len(page0) // 2))
+                self.has_been_asked_for = []
+                lib._stm_smallmalloc_sweep()
+                assert sorted(page0) == self.has_been_asked_for
+                page0r = []
+                for p in page0:
+                    if p in self.keep_me:
+                        assert lib._get_type_id(p) == tid
+                        page0r.append(p)
+                    else:
+                        assert lib._get_type_id(p) != tid
+                page0 = page0r
+                if len(page0) > 10:
+                    p = stm_allocate_old_small(16)
+                    assert pageof(p) == pageof(page0[0])
+                    page0.append(p)