[pypy-commit] stmgc c7-refactor: Replace stm_allocate_prebuilt() with stm_copy_prebuilt_objects()
arigo
noreply at buildbot.pypy.org
Tue Feb 11 15:50:15 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r726:a73a0beed91e
Date: 2014-02-11 15:49 +0100
http://bitbucket.org/pypy/stmgc/changeset/a73a0beed91e/
Log: Replace stm_allocate_prebuilt() with stm_copy_prebuilt_objects()
which is probably a better fit for PyPy.
diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c
--- a/c7/stm/gcpage.c
+++ b/c7/stm/gcpage.c
@@ -9,11 +9,6 @@
(NB_PAGES - END_NURSERY_PAGE) * 4096UL);
}
-object_t *stm_allocate_prebuilt(ssize_t size_rounded_up)
-{
- abort();
-}
-
object_t *_stm_allocate_old(ssize_t size_rounded_up)
{
char *addr = large_malloc(size_rounded_up);
diff --git a/c7/stm/prebuilt.c b/c7/stm/prebuilt.c
new file mode 100644
--- /dev/null
+++ b/c7/stm/prebuilt.c
@@ -0,0 +1,41 @@
+#ifndef _STM_CORE_H_
+# error "must be compiled via stmgc.c"
+#endif
+
+
+void stm_copy_prebuilt_objects(object_t *target, char *source, ssize_t size)
+{
+ /* Initialize a region of 'size' bytes at the 'target' address,
+ containing prebuilt objects copied from 'source'. The caller
+ must ensure that the 'target' address is valid. It might be
+ called several times but care must be taken not to overlap the
+ ranges. The exact rules are a bit complicated:
+
+ - the range [target, target + size] must be inside the
+ range [131072, FIRST_READMARKER_PAGE*4096]
+
+ - the range [target / 16, (target + size) / 16] will be
+ used by read markers, so it must be fully before the
+ range [target, target + size].
+
+ The objects themselves can contain more pointers to other
+ prebuilt objects. Their stm_flags field must be initialized
+ with STM_FLAGS_PREBUILT.
+ */
+
+ uintptr_t utarget = (uintptr_t)target;
+ if (utarget / 16 < 8192 ||
+ utarget + size > FIRST_READMARKER_PAGE * 4096UL ||
+ (utarget + size + 15) / 16 > utarget) {
+ fprintf(stderr,
+ "stm_copy_prebuilt_objects: invalid range (%ld, %ld)",
+ (long)utarget, (long)size);
+ abort();
+ }
+ uintptr_t start_page = utarget / 4096;
+ uintptr_t end_page = (utarget + size + 4095) / 4096;
+ pages_initialize_shared(start_page, end_page - start_page);
+
+ char *segment_base = get_segment_base(0);
+ memcpy(REAL_ADDRESS(segment_base, utarget), source, size);
+}
diff --git a/c7/stmgc.c b/c7/stmgc.c
--- a/c7/stmgc.c
+++ b/c7/stmgc.c
@@ -7,6 +7,7 @@
#include "stm/misc.c"
#include "stm/pages.c"
+#include "stm/prebuilt.c"
#include "stm/gcpage.c"
#include "stm/largemalloc.c"
#include "stm/nursery.c"
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -78,6 +78,7 @@
#endif
#define _STM_GCFLAG_WRITE_BARRIER 0x01
+#define STM_FLAGS_PREBUILT _STM_GCFLAG_WRITE_BARRIER
/* ==================== HELPERS ==================== */
@@ -140,12 +141,11 @@
return (object_t *)p;
}
-object_t *stm_allocate_prebuilt(ssize_t size_rounded_up);
-
void stm_setup(void);
void stm_teardown(void);
void stm_register_thread_local(stm_thread_local_t *tl);
void stm_unregister_thread_local(stm_thread_local_t *tl);
+void stm_copy_prebuilt_objects(object_t *target, char *source, ssize_t size);
void stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf);
void stm_start_inevitable_transaction(stm_thread_local_t *tl);
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -41,11 +41,13 @@
void stm_read(object_t *obj);
/*void stm_write(object_t *obj); use _checked_stm_write() instead */
object_t *stm_allocate(ssize_t size_rounded_up);
-object_t *stm_allocate_prebuilt(ssize_t size_rounded_up);
object_t *_stm_allocate_old(ssize_t size_rounded_up);
void stm_setup(void);
void stm_teardown(void);
+void stm_register_thread_local(stm_thread_local_t *tl);
+void stm_unregister_thread_local(stm_thread_local_t *tl);
+void stm_copy_prebuilt_objects(object_t *target, char *source, ssize_t size);
bool _checked_stm_write(object_t *obj);
bool _stm_was_read(object_t *obj);
@@ -56,9 +58,6 @@
bool _stm_in_transaction(stm_thread_local_t *tl);
void _stm_test_switch(stm_thread_local_t *tl);
-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 stm_commit_transaction(void);
bool _check_abort_transaction(void);
More information about the pypy-commit
mailing list