Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r891:6b8ac788b8c0
Date: 2014-02-27 16:44 +0100
http://bitbucket.org/pypy/stmgc/changeset/6b8ac788b8c0/

Log:    Start adapting test_gcpage

diff --git a/c7/stm/misc.c b/c7/stm/misc.c
--- a/c7/stm/misc.c
+++ b/c7/stm/misc.c
@@ -41,6 +41,11 @@
 }
 
 #ifdef STM_TESTS
+uint8_t _stm_get_page_flag(uintptr_t index)
+{
+    return flag_page_private[index];
+}
+
 long _stm_count_modified_old_objects(void)
 {
     if (STM_PSEGMENT->modified_old_objects == NULL)
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -74,7 +74,7 @@
 #ifdef STM_TESTS
 bool _stm_was_read(object_t *obj);
 bool _stm_was_written(object_t *obj);
-uint8_t _stm_creation_marker(object_t *obj);
+uint8_t _stm_get_page_flag(uintptr_t index);
 bool _stm_in_nursery(object_t *obj);
 bool _stm_in_transaction(stm_thread_local_t *tl);
 char *_stm_get_segment_base(long index);
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -10,6 +10,7 @@
 typedef ... stm_jmpbuf_t;
 #define SIZEOF_MYOBJ ...
 #define _STM_FAST_ALLOC ...
+#define _STM_GCFLAG_WRITE_BARRIER ...
 
 typedef struct {
     object_t **shadowstack, **shadowstack_base;
@@ -36,6 +37,8 @@
 char *_stm_get_segment_base(long index);
 bool _stm_in_transaction(stm_thread_local_t *tl);
 void _stm_test_switch(stm_thread_local_t *tl);
+uint8_t _stm_get_page_flag(uintptr_t index);
+int _stm_get_flags(object_t *obj);
 
 void _stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf);
 bool _check_commit_transaction(void);
@@ -70,6 +73,11 @@
 """)
 
 
+GC_N_SMALL_REQUESTS = 36      # from gcpage.c
+SHARED_PAGE         = 1       # from pages.h
+PRIVATE_PAGE        = 3       # from pages.h
+
+
 lib = ffi.verify('''
 #include <stdlib.h>
 #include <string.h>
@@ -85,7 +93,7 @@
 #define SIZEOF_MYOBJ sizeof(struct myobj_s)
 
 
-uint8_t _stm_get_flags(object_t *obj) {
+int _stm_get_flags(object_t *obj) {
     return obj->stm_flags;
 }
 
@@ -231,7 +239,9 @@
 ''', sources=source_files,
      define_macros=[('STM_TESTS', '1'),
                     ('STM_NO_COND_WAIT', '1'),
-                    ('STM_DEBUGPRINT', '1')],
+                    ('STM_DEBUGPRINT', '1'),
+                    ('GC_N_SMALL_REQUESTS', str(GC_N_SMALL_REQUESTS)), #check
+                    ],
      undef_macros=['NDEBUG'],
      include_dirs=[parent_dir],
      extra_compile_args=['-g', '-O0', '-Werror', '-ferror-limit=1'],
@@ -241,6 +251,7 @@
 WORD = 8
 HDR = lib.SIZEOF_MYOBJ
 assert HDR == 8
+GCFLAG_WRITE_BARRIER = lib._STM_GCFLAG_WRITE_BARRIER
 
 
 class Conflict(Exception):
@@ -331,7 +342,7 @@
     lib.stm_collect(0)
 
 def stm_get_page_flag(pagenum):
-    return lib.stm_get_page_flag(pagenum)
+    return lib._stm_get_page_flag(pagenum)
 
 def stm_get_obj_size(o):
     return lib.stmcb_size_rounded_up(stm_get_real_address(o))
diff --git a/c7/test/test_gcpage.py b/c7/test/test_gcpage.py
--- a/c7/test/test_gcpage.py
+++ b/c7/test/test_gcpage.py
@@ -1,55 +1,40 @@
+from support import *
+import py
 
-
-class DISABLED:
+class TestGCPage(BaseTest):
 
     def test_large_obj_alloc(self):
         # test obj which doesn't fit into the size_classes
         # for now, we will still allocate it in the nursery.
-        # expects: LARGE_OBJECT_WORDS  36
+        # expects: GC_N_SMALL_REQUESTS  36
         size_class = 1000 # too big
         obj_size = size_class * 8
         assert obj_size > 4096 # we want more than 1 page
-        assert obj_size < 4096 * 1024 # in the nursery
+        assert obj_size < lib._STM_FAST_ALLOC # in the nursery
 
         self.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)
         self.push_root(new)
         stm_minor_collect()
         new = self.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 ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+                == [SHARED_PAGE]*2)
 
         assert not is_in_nursery(new)
+        stm_write(new)
+        self.commit_transaction()
 
-    def test_large_obj_write(self):
-        # test obj which doesn't fit into the size_classes
-        # expects: LARGE_OBJECT_WORDS  36
-        size_class = 1000 # too big
-        obj_size = size_class * 8
-        assert obj_size > 4096 # we want more than 1 page
-        assert obj_size < 4096 * 1024 # in the nursery
-
+        # now proceed to write into the object in a new transaction
         self.start_transaction()
-        new = stm_allocate(obj_size)
-        assert is_in_nursery(new)
-        self.push_root(new)
-        self.commit_transaction()
-        new = self.pop_root()
-
         assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
-                == [lib.SHARED_PAGE]*2)
-
-        self.start_transaction()
+                == [SHARED_PAGE]*2)
         stm_write(new)
         assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
-                == [lib.PRIVATE_PAGE]*2)
-        
+                == [PRIVATE_PAGE]*2)
+
         # write to 2nd page of object!!
         wnew = stm_get_real_address(new)
         wnew[4097] = 'x'
@@ -59,19 +44,29 @@
         stm_read(new)
         rnew = stm_get_real_address(new)
         assert rnew[4097] == '\0'
-        
+        self.abort_transaction()
+
+        self.switch(0)
+        self.abort_transaction()
+        assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+                == [PRIVATE_PAGE]*2)
+
     def test_partial_alloced_pages(self):
         self.start_transaction()
         new = stm_allocate(16)
         self.push_root(new)
         stm_minor_collect()
         new = self.pop_root()
-        # assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == 
lib.UNCOMMITTED_SHARED_PAGE
-        # assert not (stm_get_flags(new) & lib.GCFLAG_NOT_COMMITTED)
+
+        assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == SHARED_PAGE
+        assert stm_get_flags(new) & GCFLAG_WRITE_BARRIER
+
+        stm_write(new)
+        assert not (stm_get_flags(new) & GCFLAG_WRITE_BARRIER)
 
         self.commit_transaction()
-        assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == lib.SHARED_PAGE
-        assert not (stm_get_flags(new) & lib.GCFLAG_NOT_COMMITTED)
+        assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == SHARED_PAGE
+        assert stm_get_flags(new) & GCFLAG_WRITE_BARRIER
 
         self.start_transaction()
         newer = stm_allocate(16)
@@ -79,15 +74,16 @@
         stm_minor_collect()
         newer = self.pop_root()
         # 'new' is still in shared_page and committed
-        assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == lib.SHARED_PAGE
-        assert not (stm_get_flags(new) & lib.GCFLAG_NOT_COMMITTED)
+        assert stm_get_page_flag(stm_get_obj_pages(new)[0]) == SHARED_PAGE
+        assert stm_get_flags(new) & GCFLAG_WRITE_BARRIER
         # 'newer' is now part of the SHARED page with 'new', but
-        # marked as UNCOMMITTED, so no privatization has to take place:
+        # uncommitted, so no privatization has to take place:
         assert stm_get_obj_pages(new) == stm_get_obj_pages(newer)
-        assert stm_get_flags(newer) & lib.GCFLAG_NOT_COMMITTED
+        assert stm_get_flags(newer) & GCFLAG_WRITE_BARRIER
         stm_write(newer) # does not privatize
-        assert stm_get_page_flag(stm_get_obj_pages(newer)[0]) == 
lib.SHARED_PAGE
+        assert not (stm_get_flags(newer) & GCFLAG_WRITE_BARRIER)
+        assert stm_get_page_flag(stm_get_obj_pages(newer)[0]) == SHARED_PAGE
         self.commit_transaction()
-        
-        assert stm_get_page_flag(stm_get_obj_pages(newer)[0]) == 
lib.SHARED_PAGE
-        assert not (stm_get_flags(newer) & lib.GCFLAG_NOT_COMMITTED)
+
+        assert stm_get_page_flag(stm_get_obj_pages(newer)[0]) == SHARED_PAGE
+        assert stm_get_flags(newer) & GCFLAG_WRITE_BARRIER
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to