Author: Armin Rigo <[email protected]>
Branch: c7
Changeset: r707:e6bce725abb4
Date: 2014-02-07 13:43 +0100
http://bitbucket.org/pypy/stmgc/changeset/e6bce725abb4/
Log: Try to be extra careful around the "lock" in nursery_current
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -175,7 +175,7 @@
_stm_restore_local_state(thread_num);
_STM_TL->nursery_current = (localchar_t*)(FIRST_NURSERY_PAGE * 4096);
-
memset((void*)real_address((object_t*)CLEAR_SYNC_REQUEST(_STM_TL->nursery_current)),
+ memset((void*)real_address((object_t*)NURSERY_CURRENT(_STM_TL)),
0x0, (FIRST_AFTER_NURSERY_PAGE - FIRST_NURSERY_PAGE) * 4096); /*
clear nursery */
_STM_TL->shadow_stack = NULL;
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -5,6 +5,20 @@
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
+#include <limits.h>
+
+#if LONG_MAX == 2147483647
+# error "Requires a 64-bit environment"
+#endif
+
+#if BYTE_ORDER == 1234
+# define LENDIAN 1 // little endian
+#elif BYTE_ORDER == 4321
+# define LENDIAN 0 // big endian
+#else
+# error "Unsupported endianness"
+#endif
+
#define NB_PAGES (6*256*256) // 6*256MB
#define NB_THREADS 2
diff --git a/c7/nursery.c b/c7/nursery.c
--- a/c7/nursery.c
+++ b/c7/nursery.c
@@ -166,8 +166,8 @@
/* clear nursery */
localchar_t *nursery_base = (localchar_t*)(FIRST_NURSERY_PAGE * 4096);
memset((void*)real_address((object_t*)nursery_base), 0x0,
- CLEAR_SYNC_REQUEST(_STM_TL->nursery_current) - nursery_base);
- _STM_TL->nursery_current = nursery_base;
+ NURSERY_CURRENT(_STM_TL) - nursery_base);
+ SET_NURSERY_CURRENT(_STM_TL, nursery_base);
}
void _stm_minor_collect()
@@ -180,9 +180,9 @@
localchar_t *new_current = _STM_TL->nursery_current;
while (((uintptr_t)new_current > FIRST_AFTER_NURSERY_PAGE * 4096)
- && _STM_TL->nursery_current_halfwords[1]) {
+ && _STM_TL->nursery_current_halfwords[LENDIAN]) {
- _STM_TL->nursery_current_halfwords[1] = 0;
+ _STM_TL->nursery_current_halfwords[LENDIAN] = 0;
_stm_start_safe_point(0);
/* no collect, it would mess with nursery_current */
_stm_stop_safe_point(0);
@@ -196,15 +196,16 @@
}
/* reset nursery_current (left invalid by the caller) */
- _STM_TL->nursery_current -= size;
+ SET_NURSERY_CURRENT(_STM_TL, new_current - size);
minor_collect();
/* XXX: if we_want_major_collect: acquire EXCLUSIVE & COLLECT lock
and do it */
- localchar_t *current = CLEAR_SYNC_REQUEST(_STM_TL->nursery_current);
- _STM_TL->nursery_current = current + size;
+ localchar_t *current = NURSERY_CURRENT(_STM_TL);
+ assert((uintptr_t)current + size <= FIRST_AFTER_NURSERY_PAGE * 4096);
+ SET_NURSERY_CURRENT(_STM_TL, current + size);
return current;
}
@@ -240,7 +241,7 @@
localchar_t *current = _STM_TL->nursery_current;
localchar_t *new_current = current + size;
- _STM_TL->nursery_current = new_current;
+ SET_NURSERY_CURRENT(_STM_TL, new_current);
if ((uintptr_t)new_current > FIRST_AFTER_NURSERY_PAGE * 4096) {
current = collect_and_reserve(size);
@@ -321,8 +322,8 @@
/* clear the nursery */
localchar_t *nursery_base = (localchar_t*)(FIRST_NURSERY_PAGE * 4096);
memset((void*)real_address((object_t*)nursery_base), 0x0,
- CLEAR_SYNC_REQUEST(_STM_TL->nursery_current) - nursery_base);
- _STM_TL->nursery_current = nursery_base;
+ NURSERY_CURRENT(_STM_TL) - nursery_base);
+ SET_NURSERY_CURRENT(_STM_TL, nursery_base);
/* reset the alloc-pages to the state at the start of the transaction */
diff --git a/c7/stmsync.c b/c7/stmsync.c
--- a/c7/stmsync.c
+++ b/c7/stmsync.c
@@ -108,7 +108,7 @@
assert(!_STM_TL->active);
/* assert(!_STM_TL->need_abort); may happen, but will be cleared by
start_transaction() */
- assert(CLEAR_SYNC_REQUEST(_STM_TL->nursery_current) ==
(localchar_t*)(FIRST_NURSERY_PAGE * 4096));
+ assert(NURSERY_CURRENT(_STM_TL) == (localchar_t*)(FIRST_NURSERY_PAGE *
4096));
}
void _stm_acquire_tl_segment()
@@ -301,6 +301,6 @@
void stm_request_safe_point(int thread_num)
{
struct _thread_local1_s* other_tl = _stm_dbg_get_tl(thread_num);
- other_tl->nursery_current_halfwords[1] = 1;
+ other_tl->nursery_current_halfwords[LENDIAN] = 1;
}
diff --git a/c7/stmsync.h b/c7/stmsync.h
--- a/c7/stmsync.h
+++ b/c7/stmsync.h
@@ -20,5 +20,11 @@
void stm_request_safe_point(int thread_num);
-#define CLEAR_SYNC_REQUEST(nursery_current)
((localchar_t*)(((uintptr_t)(nursery_current)) & 0xffffffff))
+#define NURSERY_CURRENT(tls) \
+ ((localchar_t *)(uintptr_t)( \
+ (tls)->nursery_current_halfwords[1-LENDIAN]))
+
+#define SET_NURSERY_CURRENT(tls, new_value) \
+ ((tls)->nursery_current_halfwords[1-LENDIAN] = \
+ (uintptr_t)(new_value))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit