Author: Remi Meier <meier...@student.ethz.ch> Branch: implement-id Changeset: r227:17d1d1ba2d0d Date: 2013-06-21 15:11 +0200 http://bitbucket.org/pypy/stmgc/changeset/17d1d1ba2d0d/
Log: fix issue when HAS_ID flag gets removed * updated demo_random diff --git a/c4/demo_random.c b/c4/demo_random.c --- a/c4/demo_random.c +++ b/c4/demo_random.c @@ -262,7 +262,7 @@ num = get_rand(SHARED_ROOTS); _sr = shared_roots[num]; - k = get_rand(16); + k = get_rand(17); switch (k) { case 0: // remove a root @@ -324,7 +324,7 @@ pop_roots(); p = NULL; break; - case 15: + case 15: /* test stm_id on non-shared roots */ w_r = (nodeptr)read_barrier(_r); if (w_r->id) { assert(w_r->id == stm_id((gcptr)w_r)); @@ -335,6 +335,17 @@ w_r->id = stm_id((gcptr)w_r); assert(w_r->id == stm_id((gcptr)_r)); } + case 16: /* test stm_id on shared roots */ + w_sr = (nodeptr)read_barrier(_sr); + if (w_sr->id) { + assert(w_sr->id == stm_id((gcptr)w_sr)); + assert(w_sr->id == stm_id((gcptr)_sr)); + } + else { + w_sr = (nodeptr)write_barrier(_sr); + w_sr->id = stm_id((gcptr)w_sr); + assert(w_sr->id == stm_id((gcptr)_sr)); + } } return p; } diff --git a/c4/nursery.c b/c4/nursery.c --- a/c4/nursery.c +++ b/c4/nursery.c @@ -100,24 +100,34 @@ struct tx_descriptor *d = thread_descriptor; revision_t result; + if (p->h_original) { /* fast path */ + fprintf(stderr, "stm_id(%p) has orig fst: %p\n", p, p->h_original); return p->h_original; + } + else if (!(p->h_tid & GCFLAG_PRIVATE_FROM_PROTECTED) + && (p->h_tid & GCFLAG_OLD)) { + /* we can be sure that p->h_original doesn't + get set during the if and the else-if */ + fprintf(stderr, "stm_id(%p) is old, orig=0 fst: %p\n", p, p); + return (revision_t)p; } spinlock_acquire(d->public_descriptor->collection_lock, 'I'); - if (p->h_original) { /* maybe now? */ - spinlock_release(d->public_descriptor->collection_lock); - return p->h_original; - } - /* old objects must have an h_original OR be + /* old objects must have an h_original xOR be the original itself. if some thread stole p when it was still young, it must have set h_original. stealing an old obj makes the old obj "original". */ - if (p->h_tid & GCFLAG_OLD) { + if (p->h_original) { /* maybe now? */ + result = p->h_original; + fprintf(stderr, "stm_id(%p) has orig: %p\n", p, p->h_original); + } + else if (p->h_tid & GCFLAG_OLD) { /* it must be this exact object */ result = (revision_t)p; + fprintf(stderr, "stm_id(%p) is old, orig=0: %p\n", p, p); } else { /* must create shadow original object or use @@ -130,6 +140,8 @@ // B->h_tid |= GCFLAG_PUBLIC; done by CommitPrivateFromProtected result = (revision_t)B; + fprintf(stderr, "stm_id(%p) young, pfp, use backup %p\n", + p, p->h_original); } else { gcptr O = stmgc_duplicate_old(p); @@ -138,6 +150,7 @@ O->h_tid |= GCFLAG_PUBLIC; result = (revision_t)O; + fprintf(stderr, "stm_id(%p) young, make shadow %p\n", p, O); } } @@ -147,7 +160,9 @@ revision_t stm_pointer_equal(gcptr p1, gcptr p2) { - /* XXX: */ + /* types must be the same */ + if ((p1->h_tid & STM_USER_TID_MASK) != (p2->h_tid & STM_USER_TID_MASK)) + return 0; return stm_id(p1) == stm_id(p2); } diff --git a/c4/steal.c b/c4/steal.c --- a/c4/steal.c +++ b/c4/steal.c @@ -195,7 +195,11 @@ if needed */ O = stmgc_duplicate_old(L); L->h_revision = (revision_t)O; - L->h_original = (revision_t)O; + + /* young and without original? + we may lose the HAS_ID flag like above */ + if (!(L->h_original)) + L->h_original = (revision_t)O; } L->h_tid |= GCFLAG_PUBLIC | GCFLAG_NURSERY_MOVED; _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit