[pypy-commit] stmgc c7-refactor: in-progress
arigo
noreply at buildbot.pypy.org
Mon Feb 10 18:12:01 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r720:1da8e9545d83
Date: 2014-02-10 18:11 +0100
http://bitbucket.org/pypy/stmgc/changeset/1da8e9545d83/
Log: in-progress
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -4,6 +4,7 @@
/************************************************************/
+#define NURSERY_START (FIRST_NURSERY_PAGE * 4096UL)
#define NURSERY_SIZE (NB_NURSERY_PAGES * 4096UL)
/* an object larger than LARGE_OBJECT will never be allocated in
@@ -36,6 +37,12 @@
nursery_ctl.used = 0;
}
+bool _stm_in_nursery(object_t *obj)
+{
+ uint64_t p = (uint64_t)obj;
+ return (p - NURSERY_START) < NURSERY_SIZE;
+}
+
static stm_char *allocate_from_nursery(uint64_t bytes)
{
@@ -45,7 +52,7 @@
//major_collection();
abort();
}
- return (stm_char *)(FIRST_NURSERY_PAGE * 4096UL + p);
+ return (stm_char *)(NURSERY_START + p);
}
@@ -53,8 +60,10 @@
{
if (size_rounded_up < MEDIUM_OBJECT) {
/* This is a small object. The current section is simply full.
- Allocate the next section. */
+ Allocate the next section and initialize it with zeroes. */
stm_char *p = allocate_from_nursery(NURSERY_SECTION_SIZE);
+ memset(REAL_ADDRESS(STM_SEGMENT->segment_base, p), 0,
+ NURSERY_SECTION_SIZE);
STM_SEGMENT->nursery_current = p + size_rounded_up;
STM_SEGMENT->nursery_section_end = (uintptr_t)p + NURSERY_SECTION_SIZE;
return p;
diff --git a/c7/stm/sync.c b/c7/stm/sync.c
--- a/c7/stm/sync.c
+++ b/c7/stm/sync.c
@@ -80,3 +80,8 @@
__sync_lock_release(&segments_ctl.in_use[num]);
sem_post(&segments_ctl.semaphore);
}
+
+bool _stm_in_transaction(void)
+{
+ return STM_SEGMENT->running_thread != NULL;
+}
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -69,6 +69,7 @@
bool _stm_was_read(object_t *obj);
bool _stm_was_written(object_t *obj);
bool _stm_in_nursery(object_t *obj);
+bool _stm_in_transaction(void);
char *_stm_real_address(object_t *o);
object_t *_stm_segment_address(char *ptr);
#endif
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -49,11 +49,18 @@
bool _checked_stm_write(object_t *obj);
bool _stm_was_read(object_t *obj);
bool _stm_was_written(object_t *obj);
+bool _stm_in_nursery(object_t *obj);
+char *_stm_real_address(object_t *obj);
+object_t *_stm_segment_address(char *ptr);
+bool _stm_in_transaction(void);
void stm_register_thread_local(stm_thread_local_t *tl);
void stm_unregister_thread_local(stm_thread_local_t *tl);
void stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf);
+
+void _set_type_id(object_t *obj, uint32_t h);
+uint32_t _get_type_id(object_t *obj);
""")
@@ -62,18 +69,11 @@
void stm_commit_transaction(void);
void stm_abort_transaction(void);
void stm_become_inevitable(char* msg);
-bool _stm_in_nursery(object_t *obj);
-char *_stm_real_address(object_t *obj);
-object_t *_stm_segment_address(char *ptr);
void _stm_start_safe_point(uint8_t);
void _stm_stop_safe_point(uint8_t);
bool _stm_check_stop_safe_point(void);
-void _set_type_id(object_t *obj, uint32_t h);
-uint32_t _get_type_id(object_t *obj);
-bool _stm_is_in_transaction(void);
-
void stm_push_root(object_t *obj);
object_t *stm_pop_root(void);
@@ -426,10 +426,14 @@
self.running_transaction.add(n)
def switch(self, thread_num):
+ tr = lib._stm_in_transaction()
+ assert tr == (self.current_thread in self.running_transaction)
assert thread_num != self.current_thread
+ if tr:
+ stm_start_safe_point()
self.current_thread = thread_num
- if lib._stm_is_in_transaction():
- stm_start_safe_point()
lib._stm_restore_local_state(thread_num)
- if lib._stm_is_in_transaction():
+ tr = lib._stm_in_transaction()
+ assert tr == (self.current_thread in self.running_transaction)
+ if tr:
stm_stop_safe_point() # can raise Conflict
More information about the pypy-commit
mailing list