Author: Remi Meier <[email protected]>
Branch: c7
Changeset: r624:6d1c731e3872
Date: 2014-01-17 14:38 +0100
http://bitbucket.org/pypy/stmgc/changeset/6d1c731e3872/
Log: failing abort cleanup test
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -164,18 +164,18 @@
abort();
}
-static void stm_start_exclusive_lock(void)
+void stm_start_exclusive_lock(void)
{
int err = pthread_rwlock_wrlock(&rwlock_shared);
if (err != 0)
abort();
- if (_STM_TL2->need_abort) {
+ if (_STM_TL2->need_abort)
stm_abort_transaction();
- }
}
void _stm_start_safe_point(void)
{
+ assert(!_STM_TL2->need_abort);
stm_stop_lock();
}
@@ -375,17 +375,19 @@
/* privatize if SHARED_PAGE */
_stm_privatize(pagenum);
- obj->stm_flags &= ~GCFLAG_WRITE_BARRIER;
-
/* lock the object for writing in thread 0's page */
uintptr_t t0_offset = (uintptr_t)obj;
char* t0_addr = get_thread_base(0) + t0_offset;
struct object_s *t0_obj = (struct object_s *)t0_addr;
- int previous = __sync_lock_test_and_set(&t0_obj->stm_write_lock, 1);
- if (previous)
+ int previous;
+ while ((previous = __sync_lock_test_and_set(&t0_obj->stm_write_lock, 1))) {
stm_abort_transaction();
+ /* XXX: only abort if we are younger */
+ spin_loop();
+ }
+ obj->stm_flags &= ~GCFLAG_WRITE_BARRIER;
stm_read(obj);
_STM_TL2->modified_objects = stm_list_append
@@ -581,7 +583,7 @@
void stm_setup(void)
-{
+{
pthread_rwlockattr_t attr;
pthread_rwlockattr_init(&attr);
pthread_rwlockattr_setkind_np(&attr,
@@ -912,16 +914,28 @@
void stm_abort_transaction(void)
{
assert(_STM_TL2->running_transaction);
- // XXX copy back the modified objects!!
- long j;
- for (j = 2; j < LARGE_OBJECT_WORDS; j++) {
- alloc_for_size_t *alloc = &_STM_TL2->alloc[j];
- uint16_t num_allocated = ((uintptr_t)alloc->next) - alloc->start;
- alloc->next -= num_allocated;
- }
+
+ // XXX reset all the modified objects!!
+ stm_list_clear(_STM_TL2->modified_objects);
+
+ /* re-add GCFLAG_WRITE_BARRIER */
+ stm_list_clear(_STM_TL2->old_objects_to_trace);
+
+ /* clear the nursery */
+
+ /* unreserve uncommitted_pages */
+
+ /* XXX: forget about GCFLAG_UNCOMMITTED objects */
+
+ /* long j; */
+ /* for (j = 2; j < LARGE_OBJECT_WORDS; j++) { */
+ /* alloc_for_size_t *alloc = &_STM_TL2->alloc[j]; */
+ /* uint16_t num_allocated = ((uintptr_t)alloc->next) - alloc->start; */
+ /* alloc->next -= num_allocated; */
+ /* } */
/* stm_list_clear(_STM_TL2->new_object_ranges); */
- stm_list_clear(_STM_TL2->modified_objects);
- stm_list_clear(_STM_TL2->old_objects_to_trace);
+
+
assert(_STM_TL1->jmpbufptr != NULL);
assert(_STM_TL1->jmpbufptr != (jmpbufptr_t *)-1); /* for tests only */
_STM_TL2->running_transaction = 0;
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -120,6 +120,8 @@
void _stm_start_safe_point(void);
void _stm_stop_safe_point(void);
+
+void stm_abort_transaction(void);
#endif
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -66,6 +66,9 @@
void _set_ptr(object_t *obj, int n, object_t *v);
object_t * _get_ptr(object_t *obj, int n);
+
+bool _stm_check_abort_transaction(void);
+
void *memset(void *s, int c, size_t n);
""")
@@ -126,6 +129,19 @@
return 1;
}
+bool _stm_check_abort_transaction(void) {
+ jmpbufptr_t here;
+ if (__builtin_setjmp(here) == 0) { // returned directly
+ assert(_STM_TL1->jmpbufptr == (jmpbufptr_t*)-1);
+ _STM_TL1->jmpbufptr = &here;
+ stm_abort_transaction();
+ _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1;
+ return 0;
+ }
+ _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1;
+ return 1;
+}
+
void _set_type_id(object_t *obj, uint32_t h)
{
@@ -275,6 +291,9 @@
if lib._stm_stop_transaction():
raise Conflict()
+def stm_abort_transaction():
+ return lib._stm_check_abort_transaction()
+
def stm_start_safe_point():
lib._stm_start_safe_point()
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
@@ -84,7 +84,6 @@
stm_write(lp1)
assert stm_get_char(lp1) == 'a'
stm_set_char(lp1, 'b')
-
#
self.switch(0)
stm_start_transaction()
@@ -289,13 +288,28 @@
stm_push_root(lp1)
stm_stop_transaction()
lp1 = stm_pop_root()
+
stm_start_transaction()
- stm_write(lp1)
+ stm_write(lp1) # acquire lock
#
self.switch(1)
stm_start_transaction()
py.test.raises(Conflict, stm_write, lp1) # write-write conflict
+ def test_abort_cleanup(self):
+ stm_start_transaction()
+ lp1 = stm_allocate(16)
+ stm_set_char(lp1, 'a')
+ stm_push_root(lp1)
+ stm_stop_transaction()
+ lp1 = stm_pop_root()
+
+ stm_start_transaction()
+ stm_set_char(lp1, 'x')
+ assert stm_abort_transaction()
+
+ stm_start_transaction()
+ assert stm_get_char(lp1) == 'a'
# def test_resolve_write_write_no_conflict(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit