Author: Remi Meier
Branch: c7
Changeset: r656:51d9b831ecdb
Date: 2014-01-21 10:42 +0100
http://bitbucket.org/pypy/stmgc/changeset/51d9b831ecdb/
Log: fix some page flags
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -66,21 +66,6 @@
};
#define _STM_TL2 ((_thread_local2_t *)_STM_TL1)
-enum {
- /* unprivatized page seen by all threads */
- SHARED_PAGE=0,
-
- /* page being in the process of privatization */
- REMAPPING_PAGE,
-
- /* page private for each thread */
- PRIVATE_PAGE,
-
- /* set for SHARED pages that only contain objects belonging
- to the current transaction, so the whole page is not
- visible yet for other threads */
- UNCOMMITTED_SHARED_PAGE,
-}; /* flag_page_private */
static char *object_pages;
@@ -96,6 +81,11 @@
localchar_t *_stm_alloc_next_page(size_t i);
void mark_page_as_uncommitted(uintptr_t pagenum);
+uint8_t _stm_get_page_flag(int pagenum)
+{
+ return flag_page_private[pagenum];
+}
+
static void spin_loop(void)
{
asm("pause" : : : "memory");
@@ -438,6 +428,13 @@
if (size_class >= LARGE_OBJECT_WORDS) {
result = (localchar_t*)_stm_allocate_old(size);
((object_t*)result)->stm_flags &= ~GCFLAG_WRITE_BARRIER; /* added by
_stm_allocate_old... */
+
+ int page = ((uintptr_t)result) / 4096;
+ int pages = (size + 4095) / 4096;
+ int i;
+ for (i = 0; i < pages; i++) {
+ flag_page_private[page + i] = UNCOMMITTED_SHARED_PAGE;
+ }
} else {
alloc_for_size_t *alloc = &_STM_TL2->alloc[size_class];
@@ -668,6 +665,10 @@
}
}
+ for (i = FIRST_NURSERY_PAGE; i < FIRST_AFTER_NURSERY_PAGE; i++)
+ flag_page_private[i] = PRIVATE_PAGE; /* nursery is private.
+ or should it be UNCOMMITTED???
*/
+
num_threads_started = 0;
index_page_never_used = FIRST_AFTER_NURSERY_PAGE;
pending_updates = NULL;
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -43,6 +43,23 @@
GCFLAG_MOVED = (1 << 2),
};
+enum {
+ /* unprivatized page seen by all threads */
+ SHARED_PAGE=0,
+
+ /* page being in the process of privatization */
+ REMAPPING_PAGE,
+
+ /* page private for each thread */
+ PRIVATE_PAGE,
+
+ /* set for SHARED pages that only contain objects belonging
+ to the current transaction, so the whole page is not
+ visible yet for other threads */
+ UNCOMMITTED_SHARED_PAGE,
+}; /* flag_page_private */
+
+
struct object_s {
uint8_t stm_flags; /* reserved for the STM library */
uint8_t stm_write_lock; /* 1 if writeable by some thread */
@@ -126,7 +143,7 @@
void stm_abort_transaction(void);
void _stm_minor_collect();
-
+uint8_t _stm_get_page_flag(int pagenum);
#define stm_become_inevitable(msg) /* XXX implement me! */
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -71,6 +71,16 @@
bool _stm_check_abort_transaction(void);
void *memset(void *s, int c, size_t n);
+extern size_t stmcb_size(struct object_s *);
+extern void stmcb_trace(struct object_s *, void (object_t **));
+
+enum {
+ SHARED_PAGE=0,
+ REMAPPING_PAGE,
+ PRIVATE_PAGE,
+ UNCOMMITTED_SHARED_PAGE,
+}; /* flag_page_private */
+uint8_t _stm_get_page_flag(int pagenum);
""")
lib = ffi.verify('''
@@ -306,6 +316,17 @@
def stm_minor_collect():
lib._stm_minor_collect()
+def stm_get_page_flag(pagenum):
+ return lib._stm_get_page_flag(pagenum)
+
+def stm_get_obj_size(o):
+ return lib.stmcb_size(stm_get_real_address(o))
+
+def stm_get_obj_pages(o):
+ start = int(ffi.cast('uintptr_t', o))
+ startp = start // 4096
+ return range(startp, startp + stm_get_obj_size(o) // 4096 + 1)
+
class BaseTest(object):
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -345,10 +345,17 @@
stm_start_transaction()
new = stm_allocate(obj_size)
assert is_in_nursery(new)
+ assert len(stm_get_obj_pages(new)) == 2
+ assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+ == [lib.PRIVATE_PAGE]*2)
stm_push_root(new)
stm_minor_collect()
new = stm_pop_root()
+ assert len(stm_get_obj_pages(new)) == 2
+ assert ([stm_get_page_flag(p) for p in stm_get_obj_pages(new)]
+ == [lib.UNCOMMITTED_SHARED_PAGE]*2)
+
assert not is_in_nursery(new)
def test_large_obj_write(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit