[pypy-commit] stmgc c7: test for tracing objects

Raemi noreply at buildbot.pypy.org
Fri Jan 17 11:34:34 CET 2014


Author: Remi Meier <remi.meier at gmail.com>
Branch: c7
Changeset: r619:70c54b1a942d
Date: 2014-01-17 11:34 +0100
http://bitbucket.org/pypy/stmgc/changeset/70c54b1a942d/

Log:	test for tracing objects

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -37,7 +37,6 @@
 #  define HAVE_FULL_EXCHANGE_INSN
 #endif
 
-typedef TLPREFIX char localchar_t;
 typedef TLPREFIX struct alloc_for_size_s alloc_for_size_t;
 typedef TLPREFIX struct _thread_local2_s _thread_local2_t;
 
@@ -358,6 +357,7 @@
 }
 
 
+
 static void wait_until_updated(void)
 {
     while (pending_updates == _STM_TL2->modified_objects)
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -10,7 +10,7 @@
 typedef TLPREFIX struct _thread_local1_s _thread_local1_t;
 typedef TLPREFIX struct object_s object_t;
 typedef TLPREFIX struct read_marker_s read_marker_t;
-
+typedef TLPREFIX char localchar_t;
 
 /* Structure of objects
    --------------------
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -28,6 +28,7 @@
 ffi.cdef("""
 typedef ... object_t;
 typedef ... jmpbufptr_t;
+#define SIZEOF_MYOBJ ...
 
 void stm_setup(void);
 void stm_setup_thread(void);
@@ -61,6 +62,8 @@
 void stm_push_root(object_t *obj);
 object_t *stm_pop_root(void);
 
+void _set_ptr(object_t *obj, int n, object_t *v);
+object_t * _get_ptr(object_t *obj, int n);
 
 void *memset(void *s, int c, size_t n);
 """)
@@ -76,7 +79,7 @@
     uint32_t type_id;
 };
 typedef TLPREFIX struct myobj_s myobj_t;
-
+#define SIZEOF_MYOBJ sizeof(struct myobj_s)
 
 size_t stm_object_size_rounded_up(object_t * obj) {
     return 16;
@@ -109,7 +112,8 @@
 }
 
 
-void _set_type_id(object_t *obj, uint32_t h) {
+void _set_type_id(object_t *obj, uint32_t h)
+{
     ((myobj_t*)obj)->type_id = h;
 }
 
@@ -117,6 +121,26 @@
     return ((myobj_t*)obj)->type_id;
 }
 
+
+void _set_ptr(object_t *obj, int n, object_t *v)
+{
+    localchar_t *field_addr = ((localchar_t*)obj);
+    field_addr += SIZEOF_MYOBJ; /* header */
+    field_addr += n * sizeof(void*); /* field */
+    object_t * TLPREFIX * field = (object_t * TLPREFIX *)field_addr;
+    *field = v;
+}
+
+object_t * _get_ptr(object_t *obj, int n)
+{
+    localchar_t *field_addr = ((localchar_t*)obj);
+    field_addr += SIZEOF_MYOBJ; /* header */
+    field_addr += n * sizeof(void*); /* field */
+    object_t * TLPREFIX * field = (object_t * TLPREFIX *)field_addr;
+    return *field;
+}
+
+
 size_t stmcb_size(struct object_s *obj)
 {
     struct myobj_s *myobj = (struct myobj_s*)obj;
@@ -156,8 +180,13 @@
      force_generic_engine=True)
 
 
-MAGIC_HEADER = ffi.cast('uint32_t', 42142)
+import sys
+if sys.maxint > 2**32:
+    WORD = 8
+else:
+    WORD = 4
 
+HDR = lib.SIZEOF_MYOBJ
 
 def is_in_nursery(ptr):
     return lib._stm_is_in_nursery(ptr)
@@ -174,6 +203,20 @@
     lib._set_type_id(o, tid)
     return o, lib._stm_real_address(o)
 
+def stm_allocate_refs(n):
+    o = lib.stm_allocate(HDR + n * WORD)
+    tid = 42142 + n
+    lib._set_type_id(o, tid)
+    return o, lib._stm_real_address(o)
+
+def stm_set_ref(obj, idx, ref):
+    stm_write(obj)
+    lib._set_ptr(obj, idx, ref)
+
+def stm_get_ref(obj, idx):
+    stm_read(obj)
+    return lib._get_ptr(obj, idx)
+
 def stm_get_real_address(obj):
     return lib._stm_real_address(ffi.cast('object_t*', obj))
     
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -160,6 +160,29 @@
         assert p2_[8] == 'y'
         stm_stop_transaction()
 
+    def test_simple_refs(self):
+        stm_start_transaction()
+        lp, p = stm_allocate_refs(3)
+        lq, q = stm_allocate(16)
+        lr, r = stm_allocate(16)
+        q[8] = 'x'
+        r[8] = 'y'
+        stm_set_ref(lp, 0, lq)
+        stm_set_ref(lp, 1, lr)
+        stm_push_root(lp)
+        stm_stop_transaction()
+        lp = stm_pop_root()
+        self.switch(1)
+        stm_start_transaction()
+        stm_write(lp)
+        lq = stm_get_ref(lp, 0)
+        lr = stm_get_ref(lp, 1)
+        stm_read(lq)
+        stm_read(lr)
+        assert stm_get_real_address(lq)[8] == 'x'
+        assert stm_get_real_address(lr)[8] == 'y'
+        stm_stop_transaction()
+
 
         
     # def test_read_write_2(self):


More information about the pypy-commit mailing list