Author: Remi Meier <[email protected]>
Branch: implement-id
Changeset: r228:d8b5144c17f4
Date: 2013-06-21 16:46 +0200
http://bitbucket.org/pypy/stmgc/changeset/d8b5144c17f4/
Log: add simple tests
diff --git a/c4/demo_random.c b/c4/demo_random.c
--- a/c4/demo_random.c
+++ b/c4/demo_random.c
@@ -13,7 +13,7 @@
#define NUMTHREADS 4
-#define STEPS 100000
+#define STEPS 1000000
#define NUMROOTS 10 // per thread
#define PREBUILT 3 // per thread
#define MAXROOTS 1000
diff --git a/c4/nursery.c b/c4/nursery.c
--- a/c4/nursery.c
+++ b/c4/nursery.c
@@ -102,7 +102,8 @@
if (p->h_original) { /* fast path */
- fprintf(stderr, "stm_id(%p) has orig fst: %p\n", p, p->h_original);
+ fprintf(stderr, "stm_id(%p) has orig fst: %p\n",
+ p, (gcptr)p->h_original);
return p->h_original;
}
else if (!(p->h_tid & GCFLAG_PRIVATE_FROM_PROTECTED)
@@ -122,7 +123,8 @@
*/
if (p->h_original) { /* maybe now? */
result = p->h_original;
- fprintf(stderr, "stm_id(%p) has orig: %p\n", p, p->h_original);
+ fprintf(stderr, "stm_id(%p) has orig: %p\n",
+ p, (gcptr)p->h_original);
}
else if (p->h_tid & GCFLAG_OLD) {
/* it must be this exact object */
@@ -141,7 +143,7 @@
result = (revision_t)B;
fprintf(stderr, "stm_id(%p) young, pfp, use backup %p\n",
- p, p->h_original);
+ p, (gcptr)p->h_original);
}
else {
gcptr O = stmgc_duplicate_old(p);
diff --git a/c4/test/support.py b/c4/test/support.py
--- a/c4/test/support.py
+++ b/c4/test/support.py
@@ -42,6 +42,9 @@
#define PREBUILT_REVISION ...
gcptr stm_allocate(size_t size, unsigned int tid);
+ revision_t stm_hash(gcptr);
+ revision_t stm_id(gcptr);
+ revision_t stm_pointer_equal(gcptr, gcptr);
void stm_push_root(gcptr);
gcptr stm_pop_root(void);
void stm_set_max_aborts(int max_aborts);
@@ -108,6 +111,7 @@
#define GCFLAG_NURSERY_MOVED ...
#define GCFLAG_STUB ...
#define GCFLAG_PRIVATE_FROM_PROTECTED ...
+ #define GCFLAG_HAS_ID ...
#define ABRT_MANUAL ...
typedef struct { ...; } page_header_t;
''')
@@ -607,4 +611,10 @@
assert (r % 4) == 0
return ffi.cast("gcptr", r)
+def follow_original(p):
+ r = p.h_original
+ assert (r % 4) == 0
+ return ffi.cast("gcptr", r)
+
+
nrb_protected = ffi.cast("gcptr", -1)
diff --git a/c4/test/test_et.py b/c4/test/test_et.py
--- a/c4/test/test_et.py
+++ b/c4/test/test_et.py
@@ -198,6 +198,49 @@
assert p4 == p2
assert list_of_read_objects() == [p2]
+
+def test_id_young_to_old():
+ # move out of nursery with shadow original
+ p = nalloc(HDR)
+ assert p.h_original == 0
+ pid = lib.stm_id(p)
+ assert p.h_tid & GCFLAG_HAS_ID
+ porig = follow_original(p)
+ assert porig.h_tid & GCFLAG_OLD
+ lib.stm_push_root(p)
+ minor_collect()
+ p = lib.stm_pop_root()
+ assert not lib.in_nursery(p)
+ assert pid == lib.stm_id(p)
+
+def test_id_private_from_protected():
+ # read and write from protected
+ p = oalloc(HDR)
+ pid = lib.stm_id(p)
+ porig = follow_original(p)
+ # impl detail {
+ # old objects have id==itself, if not set differently
+ assert porig == ffi.NULL
+ assert ffi.cast("gcptr", pid) == p
+ # }
+
+ p1 = oalloc(HDR)
+ p1id = lib.stm_id(p1)
+ p1r = lib.stm_read_barrier(p1)
+ assert lib.stm_id(p1r) == p1id
+ p1w = lib.stm_write_barrier(p1)
+ assert lib.stm_id(p1w) == p1id
+
+ p2 = oalloc(HDR)
+ p2w = lib.stm_write_barrier(p2)
+ p2id = lib.stm_id(p2)
+ assert p2id == lib.stm_id(p2w)
+ # impl detail {
+ assert p2w.h_original == 0
+ assert follow_revision(p2w).h_original == lib.stm_id(p2w)
+ # }
+
+
def test_stealing_old():
p = palloc(HDR + WORD)
plist = [p]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit