Author: Armin Rigo <[email protected]>
Branch: c7-refactor
Changeset: r744:27b37f2a4cb3
Date: 2014-02-15 23:53 +0100
http://bitbucket.org/pypy/stmgc/changeset/27b37f2a4cb3/
Log: Port some more tests
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -1,5 +1,5 @@
import os
-import cffi
+import cffi, weakref
import sys
assert sys.maxint == 9223372036854775807, "requires a 64-bit environment"
@@ -75,9 +75,6 @@
void stm_start_inevitable_transaction(stm_thread_local_t *tl);
void stm_become_inevitable(char* msg);
-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);
@@ -347,12 +344,6 @@
def stm_was_written(o):
return lib._stm_was_written(o)
-def stm_push_root(o):
- return lib.stm_push_root(o)
-
-def stm_pop_root():
- return lib.stm_pop_root()
-
def stm_stop_transaction():
if lib._stm_stop_transaction():
raise Conflict()
@@ -386,8 +377,15 @@
def stm_get_flags(o):
return lib._stm_get_flags(o)
+SHADOWSTACK_LENGTH = 100
+_keepalive = weakref.WeakKeyDictionary()
+
def _allocate_thread_local():
tl = ffi.new("stm_thread_local_t *")
+ ss = ffi.new("object_t *[]", SHADOWSTACK_LENGTH)
+ _keepalive[tl] = ss
+ tl.shadowstack = ss
+ tl.shadowstack_base = ss
lib.stm_register_thread_local(tl)
return tl
@@ -446,3 +444,18 @@
if lib._stm_in_transaction(tl2):
lib._stm_test_switch(tl2)
stm_stop_safe_point() # can raise Conflict
+
+ def push_root(self, o):
+ assert ffi.typeof(o) == ffi.typeof("object_t *")
+ tl = self.tls[self.current_thread]
+ curlength = tl.shadowstack - tl.shadowstack_base
+ assert 0 <= curlength < SHADOWSTACK_LENGTH
+ tl.shadowstack[0] = ffi.cast("object_t *", o)
+ tl.shadowstack += 1
+
+ def pop_root(self):
+ tl = self.tls[self.current_thread]
+ curlength = tl.shadowstack - tl.shadowstack_base
+ assert 0 < curlength <= SHADOWSTACK_LENGTH
+ tl.shadowstack -= 1
+ return ffi.cast("object_t *", tl.shadowstack[0])
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
@@ -102,9 +102,9 @@
lp = stm_allocate(16)
stm_set_char(lp, 'u')
p = stm_get_real_address(lp)
- stm_push_root(lp)
+ self.push_root(lp)
self.commit_transaction()
- lp = stm_pop_root()
+ lp = self.pop_root()
p1 = stm_get_real_address(lp)
assert p != p1
@@ -131,11 +131,11 @@
stm_write(lp2) # test not crash
stm_read(lp) # test not crash
stm_read(lp2) # test not crash
- stm_push_root(lp)
- stm_push_root(lp2)
+ self.push_root(lp)
+ self.push_root(lp2)
self.commit_transaction()
- lp2 = stm_pop_root()
- lp = stm_pop_root()
+ lp2 = self.pop_root()
+ lp = self.pop_root()
self.switch(0)
@@ -165,9 +165,9 @@
stm_set_char(lr, 'y')
stm_set_ref(lp, 0, lq)
stm_set_ref(lp, 1, lr)
- stm_push_root(lp)
+ self.push_root(lp)
self.commit_transaction()
- lp = stm_pop_root()
+ lp = self.pop_root()
self.switch(1)
@@ -187,9 +187,9 @@
self.start_transaction()
lp1 = stm_allocate(16)
stm_set_char(lp1, 'a')
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
#
self.switch(1)
self.start_transaction()
@@ -218,9 +218,9 @@
lp1 = stm_allocate(16)
p1 = stm_get_real_address(lp1)
p1[HDR] = 'a'
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
# 'a' in SHARED_PAGE
self.start_transaction()
@@ -247,9 +247,9 @@
self.start_transaction()
lp1 = stm_allocate(16)
stm_set_char(lp1, 'a')
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
self.start_transaction()
stm_read(lp1)
@@ -268,9 +268,9 @@
self.start_transaction()
lp1 = stm_allocate(16)
stm_set_char(lp1, 'a')
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
self.start_transaction()
#
@@ -287,9 +287,9 @@
self.start_transaction()
lp1 = stm_allocate(16)
stm_set_char(lp1, 'a')
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
self.start_transaction()
stm_write(lp1) # acquire lock
@@ -302,9 +302,9 @@
self.start_transaction()
lp1 = stm_allocate(16)
stm_set_char(lp1, 'a')
- stm_push_root(lp1)
+ self.push_root(lp1)
self.commit_transaction()
- lp1 = stm_pop_root()
+ lp1 = self.pop_root()
self.start_transaction()
stm_set_char(lp1, 'x')
@@ -320,12 +320,12 @@
self.start_transaction()
for i in range(num):
new = stm_allocate(obj_size)
- stm_push_root(new)
+ self.push_root(new)
old = []
young = []
for _ in range(num):
- r = stm_pop_root()
+ r = self.pop_root()
if is_in_nursery(r):
young.append(r)
else:
@@ -357,9 +357,9 @@
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)
+ self.push_root(new)
stm_minor_collect()
- new = stm_pop_root()
+ 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)]
@@ -378,9 +378,9 @@
self.start_transaction()
new = stm_allocate(obj_size)
assert is_in_nursery(new)
- stm_push_root(new)
+ self.push_root(new)
self.commit_transaction()
- new = stm_pop_root()
+ new = self.pop_root()
assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
== [lib.SHARED_PAGE]*2)
@@ -403,9 +403,9 @@
def test_partial_alloced_pages(self):
self.start_transaction()
new = stm_allocate(16)
- stm_push_root(new)
+ self.push_root(new)
stm_minor_collect()
- new = stm_pop_root()
+ 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)
@@ -415,9 +415,9 @@
self.start_transaction()
newer = stm_allocate(16)
- stm_push_root(newer)
+ self.push_root(newer)
stm_minor_collect()
- newer = stm_pop_root()
+ 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)
@@ -436,41 +436,41 @@
self.start_transaction()
new = stm_allocate(16)
stm_set_char(new, 'a')
- stm_push_root(new)
+ self.push_root(new)
stm_minor_collect()
- new = stm_pop_root()
+ new = self.pop_root()
stm_abort_transaction()
self.start_transaction()
newer = stm_allocate(16)
- stm_push_root(newer)
+ self.push_root(newer)
stm_minor_collect()
- newer = stm_pop_root()
+ newer = self.pop_root()
assert stm_get_real_address(new) == stm_get_real_address(newer)
assert stm_get_char(newer) == '\0'
def test_reuse_page(self):
self.start_transaction()
new = stm_allocate(16)
- stm_push_root(new)
+ self.push_root(new)
stm_minor_collect()
- new = stm_pop_root()
+ new = self.pop_root()
# assert stm_get_page_flag(stm_get_obj_pages(new)[0]) ==
lib.UNCOMMITTED_SHARED_PAGE
stm_abort_transaction()
self.start_transaction()
newer = stm_allocate(16)
- stm_push_root(newer)
+ self.push_root(newer)
stm_minor_collect()
- newer = stm_pop_root()
+ newer = self.pop_root()
assert new == newer
def test_write_to_old_after_minor(self):
self.start_transaction()
new = stm_allocate(16)
- stm_push_root(new)
+ self.push_root(new)
stm_minor_collect()
- old = stm_pop_root()
+ old = self.pop_root()
self.commit_transaction()
self.start_transaction()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit