Commits

Remi Meier committed 51d9b83

fix some page flags

  • Participants
  • Parent commits 0624b1c
  • Branches c7

Comments (0)

Files changed (4)

 };
 #define _STM_TL2            ((_thread_local2_t *)_STM_TL1)
 
-enum {
-    /* unprivatized page seen by all threads */
-    SHARED_PAGE=0,
-
-    /* page being in the process of privatization */
-    REMAPPING_PAGE,
-
-    /* page private for each thread */
-    PRIVATE_PAGE,
-
-    /* set for SHARED pages that only contain objects belonging
-       to the current transaction, so the whole page is not
-       visible yet for other threads */
-    UNCOMMITTED_SHARED_PAGE,
-};  /* flag_page_private */
 
 
 static char *object_pages;
 localchar_t *_stm_alloc_next_page(size_t i);
 void mark_page_as_uncommitted(uintptr_t pagenum);
 
+uint8_t _stm_get_page_flag(int pagenum)
+{
+    return flag_page_private[pagenum];
+}
+
 static void spin_loop(void)
 {
     asm("pause" : : : "memory");
     if (size_class >= LARGE_OBJECT_WORDS) {
         result = (localchar_t*)_stm_allocate_old(size);
         ((object_t*)result)->stm_flags &= ~GCFLAG_WRITE_BARRIER; /* added by _stm_allocate_old... */
+
+        int page = ((uintptr_t)result) / 4096;
+        int pages = (size + 4095) / 4096;
+        int i;
+        for (i = 0; i < pages; i++) {
+            flag_page_private[page + i] = UNCOMMITTED_SHARED_PAGE;
+        }
     } else { 
         alloc_for_size_t *alloc = &_STM_TL2->alloc[size_class];
         
         }
     }
 
+    for (i = FIRST_NURSERY_PAGE; i < FIRST_AFTER_NURSERY_PAGE; i++)
+        flag_page_private[i] = PRIVATE_PAGE; /* nursery is private.
+                                                or should it be UNCOMMITTED??? */
+    
     num_threads_started = 0;
     index_page_never_used = FIRST_AFTER_NURSERY_PAGE;
     pending_updates = NULL;
     GCFLAG_MOVED = (1 << 2),
 };
 
+enum {
+    /* unprivatized page seen by all threads */
+    SHARED_PAGE=0,
+
+    /* page being in the process of privatization */
+    REMAPPING_PAGE,
+
+    /* page private for each thread */
+    PRIVATE_PAGE,
+
+    /* set for SHARED pages that only contain objects belonging
+       to the current transaction, so the whole page is not
+       visible yet for other threads */
+    UNCOMMITTED_SHARED_PAGE,
+};  /* flag_page_private */
+
+
 struct object_s {
     uint8_t stm_flags;            /* reserved for the STM library */
     uint8_t stm_write_lock;       /* 1 if writeable by some thread */
 void stm_abort_transaction(void);
 
 void _stm_minor_collect();
-
+uint8_t _stm_get_page_flag(int pagenum);
 #define stm_become_inevitable(msg)   /* XXX implement me! */
 
 

File c7/test/support.py

 bool _stm_check_abort_transaction(void);
 
 void *memset(void *s, int c, size_t n);
+extern size_t stmcb_size(struct object_s *);
+extern void stmcb_trace(struct object_s *, void (object_t **));
+
+enum {
+    SHARED_PAGE=0,
+    REMAPPING_PAGE,
+    PRIVATE_PAGE,
+    UNCOMMITTED_SHARED_PAGE,
+};  /* flag_page_private */
+uint8_t _stm_get_page_flag(int pagenum);
 """)
 
 lib = ffi.verify('''
 def stm_minor_collect():
     lib._stm_minor_collect()
 
+def stm_get_page_flag(pagenum):
+    return lib._stm_get_page_flag(pagenum)
+
+def stm_get_obj_size(o):
+    return lib.stmcb_size(stm_get_real_address(o))
+
+def stm_get_obj_pages(o):
+    start = int(ffi.cast('uintptr_t', o))
+    startp = start // 4096
+    return range(startp, startp + stm_get_obj_size(o) // 4096 + 1)
+
 
 class BaseTest(object):
 

File c7/test/test_basic.py

         stm_start_transaction()
         new = stm_allocate(obj_size)
         assert is_in_nursery(new)
+        assert len(stm_get_obj_pages(new)) == 2
+        assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+                == [lib.PRIVATE_PAGE]*2)
         stm_push_root(new)
         stm_minor_collect()
         new = stm_pop_root()
 
+        assert len(stm_get_obj_pages(new)) == 2
+        assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+                == [lib.UNCOMMITTED_SHARED_PAGE]*2)
+
         assert not is_in_nursery(new)
 
     def test_large_obj_write(self):