Commit 9baaba7aa86 by Armin Rigo

Move the code to a new directory "c4" as I need it.

parent 69fa4d0304c
......@@ -192,10 +192,13 @@ gcptr stm_DirectReadBarrier(gcptr G)
}
else
{
abort(); // stealing
/* stealing */
fprintf(stderr, "read_barrier: %p -> stealing %p...", G, (gcptr)v);
abort();
}
}
#if 0
static gcptr _latest_gcptr(gcptr R)
{
/* don't use, for tests only */
......@@ -270,6 +273,7 @@ gcptr _stm_nonrecord_barrier(gcptr obj, int *result)
return obj;
}
}
#endif
#if 0
void *stm_DirectReadBarrierFromR(void *G1, void *R_Container1, size_t offset)
......@@ -294,6 +298,14 @@ gcptr stm_RepeatReadBarrier(gcptr O)
#endif
}
gcptr stmgc_duplicate(gcptr P)
{
size_t size = stmcb_size(P);
gcptr L = stm_malloc(size);
memcpy(L, P, size);
return L;
}
static gcptr LocalizeProtected(struct tx_descriptor *d, gcptr P)
{
gcptr B;
......@@ -307,7 +319,7 @@ static gcptr LocalizeProtected(struct tx_descriptor *d, gcptr P)
if (P->h_revision & 1)
{
/* does not have a backup yet */
B = stmgc_duplicate(P, 0);
B = stmgc_duplicate(P);
B->h_tid |= GCFLAG_BACKUP_COPY;
}
else
......@@ -338,7 +350,7 @@ static gcptr LocalizePublic(struct tx_descriptor *d, gcptr R)
R->h_tid |= GCFLAG_PUBLIC_TO_PRIVATE;
not_found:;
gcptr L = stmgc_duplicate(R, 0);
gcptr L = stmgc_duplicate(R);
assert(!(L->h_tid & GCFLAG_BACKUP_COPY));
assert(!(L->h_tid & GCFLAG_STOLEN));
assert(!(L->h_tid & GCFLAG_STUB));
......@@ -556,7 +568,7 @@ void AbortTransaction(int num)
gcptrlist_clear(&d->list_of_read_objects);
g2l_clear(&d->private_to_backup);
stmgc_abort_transaction(d);
abort();//stmgc_abort_transaction(d);
fprintf(stderr,
"\n"
......@@ -620,7 +632,7 @@ static void init_transaction(struct tx_descriptor *d)
}
assert(d->list_of_read_objects.size == 0);
assert(!g2l_any_entry(&d->private_to_backup));
stmgc_start_transaction(d);
assert(!g2l_any_entry(&d->public_to_private));
d->count_reads = 1;
fxcache_clear(&d->recent_reads_cache);
......@@ -750,10 +762,10 @@ static void UpdateChainHeads(struct tx_descriptor *d, revision_t cur_time,
gcptr R = item->addr;
revision_t v = (revision_t)item->val;
assert(R->h_tid & GCFLAG_PUBLIC);
assert(R->h_tid & GCFLAG_PUBLIC_TO_PRIVATE);
assert(!(R->h_tid & GCFLAG_NURSERY_MOVED));
assert(!(R->h_tid & GCFLAG_STOLEN));
assert(!is_young(R));
assert(R->h_revision != localrev);
/* XXX compactify and don't leak! */
......@@ -773,6 +785,7 @@ static void UpdateChainHeads(struct tx_descriptor *d, revision_t cur_time,
#endif
ACCESS_ONCE(R->h_revision) = w;
#if 0
if (R->h_tid & GCFLAG_PREBUILT_ORIGINAL)
{
/* cannot possibly get here more than once for a given value of R */
......@@ -781,12 +794,14 @@ static void UpdateChainHeads(struct tx_descriptor *d, revision_t cur_time,
pthread_mutex_unlock(&mutex_prebuilt_gcroots);
/*mark*/
}
#endif
} G2L_LOOP_END;
g2l_clear(&d->public_to_private);
}
#if 0
void UpdateProtectedChainHeads(struct tx_descriptor *d, revision_t cur_time,
revision_t localrev)
{
......@@ -805,6 +820,7 @@ void UpdateProtectedChainHeads(struct tx_descriptor *d, revision_t cur_time,
L->h_revision = new_revision;
}
}
#endif
void TurnPrivateWithBackupToProtected(struct tx_descriptor *d,
revision_t cur_time)
......@@ -829,7 +845,7 @@ void CommitTransaction(void)
struct tx_descriptor *d = thread_descriptor;
assert(d->active >= 1);
stmgc_stop_transaction(d);
spinlock_acquire(d->collection_lock, 'C'); /* committing */
AcquireLocks(d);
if (is_inevitable(d))
......@@ -851,10 +867,10 @@ void CommitTransaction(void)
if (cur_time & 1)
{ // there is another inevitable transaction
CancelLocks(d);
stmgc_suspend_commit_transaction(d);
spinlock_release(d->collection_lock);
inev_mutex_acquire(); // wait until released
inev_mutex_release();
stmgc_stop_transaction(d);
spinlock_acquire(d->collection_lock, 'C');
AcquireLocks(d);
continue;
}
......@@ -879,8 +895,8 @@ void CommitTransaction(void)
TurnPrivateWithBackupToProtected(d, cur_time);
revision_t localrev = stm_private_rev_num;
UpdateProtectedChainHeads(d, cur_time, localrev);
smp_wmb();
//UpdateProtectedChainHeads(d, cur_time, localrev);
//smp_wmb();
revision_t newrev = -(cur_time + 1);
assert(newrev & 1);
......@@ -890,7 +906,7 @@ void CommitTransaction(void)
UpdateChainHeads(d, cur_time, localrev);
stmgc_committed_transaction(d);
spinlock_release(d->collection_lock);
d->num_commits++;
d->active = 0;
stm_stop_sharedlock();
......@@ -1107,6 +1123,7 @@ void DescriptorDone(void)
thread_descriptor = NULL;
g2l_delete(&d->public_to_private);
g2l_delete(&d->private_to_backup);
gcptrlist_delete(&d->list_of_read_objects);
gcptrlist_delete(&d->abortinfo);
......
......@@ -13,6 +13,7 @@
#define LOCKED ((INTPTR_MAX - 0xffff) | 1)
#define WORD sizeof(gcptr)
#define HANDLE_BLOCK_SIZE (2 * WORD)
/* Description of the flags
......@@ -100,11 +101,13 @@
#define SPINLOOP_REASONS 4
struct tx_descriptor {
NURSERY_FIELDS_DECL
local_gcpages_t *local_gcpages;
jmp_buf *setjmp_buf;
revision_t start_time;
revision_t my_lock;
revision_t collection_lock;
gcptr *shadowstack;
gcptr **shadowstack_end_ref;
long atomic; /* 0 = not atomic, > 0 atomic */
unsigned long count_reads;
unsigned long reads_size_limit; /* see should_break_tr. */
......@@ -119,6 +122,7 @@ struct tx_descriptor {
struct GcPtrList list_of_read_objects;
struct GcPtrList abortinfo;
struct G2L private_to_backup;
struct G2L public_to_private;
char *longest_abort_info;
long long longest_abort_info_time;
struct FXCache recent_reads_cache;
......
......@@ -30,8 +30,6 @@
#include "fprintcolor.h"
#include "lists.h"
#include "dbgmem.h"
#include "nursery.h"
#include "gcpage.h"
#include "et.h"
#include "stmsync.h"
......
......@@ -59,19 +59,19 @@ void stm_initialize(void)
{
int r = DescriptorInit();
assert(r == 1);
stmgc_init_tls();
//stmgc_init_tls();
init_shadowstack();
stmgcpage_init_tls();
//stmgcpage_init_tls();
BeginInevitableTransaction();
}
void stm_finalize(void)
{
stmgc_minor_collect(); /* force everything out of the nursery */
//stmgc_minor_collect(); /* force everything out of the nursery */
CommitTransaction();
stmgcpage_done_tls();
//stmgcpage_done_tls();
done_shadowstack();
stmgc_done_tls();
//stmgc_done_tls();
DescriptorDone();
}
......@@ -95,18 +95,16 @@ gcptr stm_write_barrier(gcptr obj)
gcptr stm_allocate(size_t size, unsigned long tid)
{
gcptr result = stm_allocate_object_of_size(size);
gcptr result = stm_malloc(size);
assert(tid == (tid & STM_USER_TID_MASK));
result->h_tid = tid;
result->h_revision = stm_private_rev_num;
return result;
}
gcptr _stm_allocate_old(size_t size, unsigned long tid)
{
gcptr result = _stm_allocate_object_of_size_old(size);
assert(tid == (tid & STM_USER_TID_MASK));
result->h_tid = tid | GCFLAG_OLD;
return result;
abort();
}
/************************************************************/
......@@ -237,12 +235,12 @@ void stm_start_sharedlock(void)
{
int err = pthread_rwlock_rdlock(&rwlock_shared);
assert(err == 0);
assert(stmgc_nursery_hiding(thread_descriptor, 0));
//assert(stmgc_nursery_hiding(thread_descriptor, 0));
}
void stm_stop_sharedlock(void)
{
assert(stmgc_nursery_hiding(thread_descriptor, 1));
//assert(stmgc_nursery_hiding(thread_descriptor, 1));
int err = pthread_rwlock_unlock(&rwlock_shared);
assert(err == 0);
}
......@@ -303,3 +301,15 @@ void stm_possible_safe_point(void)
which takes priority here */
stm_start_sharedlock();
}
/************************************************************/
void stm_clear_between_tests(void)
{
fprintf(stderr, "\n"
"===============================================================\n"
"========================[ START ]============================\n"
"===============================================================\n"
"\n");
//gcptrlist_clear(&stm_prebuilt_gcroots);
}
......@@ -11,4 +11,6 @@ void stm_stop_single_thread(void);
void stm_possible_safe_point(void);
void stm_clear_between_tests(void);
#endif
......@@ -5,11 +5,11 @@ import os, cffi, thread, sys
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
header_files = [os.path.join(parent_dir, _n) for _n in
"et.h lists.h nursery.h gcpage.h "
"et.h lists.h "
"stmsync.h dbgmem.h fprintcolor.h "
"stmgc.h stmimpl.h atomic_ops.h".split()]
source_files = [os.path.join(parent_dir, _n) for _n in
"et.c lists.c nursery.c gcpage.c "
"et.c lists.c "
"stmsync.c dbgmem.c fprintcolor.c".split()]
_pycache_ = os.path.join(parent_dir, 'test', '__pycache__')
......@@ -40,7 +40,7 @@ ffi.cdef('''
#define PREBUILT_FLAGS ...
#define PREBUILT_REVISION ...
gcptr stm_allocate_object_of_size(size_t size);
//gcptr stm_allocate_object_of_size(size_t size);
gcptr stm_allocate(size_t size, unsigned long tid);
void stm_push_root(gcptr);
gcptr stm_pop_root(void);
......@@ -55,15 +55,15 @@ ffi.cdef('''
void stm_set_transaction_length(long length_max);
/* extra non-public code */
gcptr stmgcpage_malloc(size_t size);
void stmgcpage_free(gcptr obj);
long stmgcpage_count(int quantity);
void stmgcpage_possibly_major_collect(int);
//gcptr stmgcpage_malloc(size_t size);
//void stmgcpage_free(gcptr obj);
//long stmgcpage_count(int quantity);
//void stmgcpage_possibly_major_collect(int);
revision_t stm_global_cur_time(void);
void stmgcpage_add_prebuilt_root(gcptr);
//void stmgcpage_add_prebuilt_root(gcptr);
void stm_clear_between_tests(void);
void stmgc_minor_collect(void);
gcptr _stm_nonrecord_barrier(gcptr, int *);
//void stmgc_minor_collect(void);
//gcptr _stm_nonrecord_barrier(gcptr, int *);
int stm_dbgmem_is_active(void *p, int allow_outside);
void stm_start_sharedlock(void);
void stm_stop_sharedlock(void);
......@@ -86,8 +86,8 @@ ffi.cdef('''
revision_t get_start_time(void);
revision_t get_my_lock(void);
gcptr *addr_of_thread_local(void);
int in_nursery(gcptr);
//gcptr *addr_of_thread_local(void);
//int in_nursery(gcptr);
void stm_initialize_tests(int max_aborts);
/* some constants normally private that are useful in the tests */
......@@ -106,22 +106,20 @@ ffi.cdef('''
#define GCFLAG_STOLEN ...
#define GCFLAG_STUB ...
#define ABRT_MANUAL ...
typedef struct { ...; } page_header_t;
//typedef struct { ...; } page_header_t;
''')
lib = ffi.verify(r'''
#include "stmgc.h"
#include "stmimpl.h"
extern gcptr stmgcpage_malloc(size_t size);
extern void stmgcpage_free(gcptr obj);
extern long stmgcpage_count(int quantity);
extern void stmgcpage_possibly_major_collect(int);
//extern gcptr stmgcpage_malloc(size_t size);
//extern void stmgcpage_free(gcptr obj);
//extern long stmgcpage_count(int quantity);
//extern void stmgcpage_possibly_major_collect(int);
extern revision_t stm_global_cur_time(void);
extern void stmgcpage_add_prebuilt_root(gcptr);
extern void stm_clear_between_tests(void);
//extern void stmgcpage_add_prebuilt_root(gcptr);
extern revision_t get_private_rev_num(void);
extern local_gcpages_t *stm_local_gcpages(void);
int gettid(gcptr obj)
{
......@@ -214,17 +212,17 @@ lib = ffi.verify(r'''
return thread_descriptor->my_lock;
}
gcptr *addr_of_thread_local(void)
/*gcptr *addr_of_thread_local(void)
{
return &stm_thread_local_obj;
}
}*/
int in_nursery(gcptr obj)
/*int in_nursery(gcptr obj)
{
assert(stm_dbgmem_is_active(obj, 1));
struct tx_descriptor *d = thread_descriptor;
return (d->nursery <= (char*)obj && ((char*)obj) < d->nursery_end);
}
}*/
void stm_initialize_tests(int max_aborts)
{
......@@ -275,7 +273,7 @@ lib = ffi.verify(r'''
HDR = ffi.sizeof("struct stm_object_s")
WORD = lib.WORD
PAGE_ROOM = lib.GC_PAGE_SIZE - ffi.sizeof("page_header_t")
#PAGE_ROOM = lib.GC_PAGE_SIZE - ffi.sizeof("page_header_t")
for name in lib.__dict__:
if name.startswith('GCFLAG_') or name.startswith('PREBUILT_'):
globals()[name] = getattr(lib, name)
......@@ -416,7 +414,7 @@ def oalloc(size):
lib.settid(p, 42 + size)
return p
ofree = lib.stmgcpage_free
#ofree = lib.stmgcpage_free
def oalloc_refs(nrefs):
"Allocate an 'old' object, i.e. outside any nursery, with nrefs pointers"
......
......@@ -223,3 +223,15 @@ def test_read_barrier_handle_private():
p4 = lib.stm_read_barrier(p)
assert p4 == p2
assert list_of_read_objects() == [p2]
def test_stealing_protected_without_backup():
p = palloc(HDR + WORD)
def f1(r):
lib.setlong(p, 0, 2782172)
lib.stm_commit_transaction()
lib.stm_begin_inevitable_transaction()
r.set(2)
def f2(r):
r.wait(2)
assert lib.getlong(p, 0) == 2782172
run_parallel(f1, f2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment