Author: Armin Rigo <[email protected]>
Branch:
Changeset: r966:d0f79129cbb7
Date: 2014-03-06 17:37 +0100
http://bitbucket.org/pypy/stmgc/changeset/d0f79129cbb7/
Log: Add stm_can_move().
diff --git a/c7/stm/list.h b/c7/stm/list.h
--- a/c7/stm/list.h
+++ b/c7/stm/list.h
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdbool.h>
/************************************************************/
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -48,8 +48,9 @@
tree_contains(STM_PSEGMENT->young_outside_nursery, (uintptr_t)obj));
}
-bool _stm_in_nursery(object_t *obj)
+long stm_can_move(object_t *obj)
{
+ /* 'long' return value to avoid using 'bool' in the public interface */
return _is_in_nursery(obj);
}
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -9,7 +9,6 @@
#include <stddef.h>
#include <stdint.h>
-#include <stdbool.h>
#include <assert.h>
#include <limits.h>
#include <unistd.h>
@@ -72,10 +71,10 @@
object_t *_stm_allocate_old(ssize_t size_rounded_up);
char *_stm_real_address(object_t *o);
#ifdef STM_TESTS
+#include <stdbool.h>
bool _stm_was_read(object_t *obj);
bool _stm_was_written(object_t *obj);
uint8_t _stm_get_page_flag(uintptr_t index);
-bool _stm_in_nursery(object_t *obj);
bool _stm_in_transaction(stm_thread_local_t *tl);
char *_stm_get_segment_base(long index);
void _stm_test_switch(stm_thread_local_t *tl);
@@ -108,8 +107,8 @@
#else
#define OPT_ASSERT(cond) assert(cond)
#endif
-#define LIKELY(x) __builtin_expect(x, true)
-#define UNLIKELY(x) __builtin_expect(x, false)
+#define LIKELY(x) __builtin_expect(x, 1)
+#define UNLIKELY(x) __builtin_expect(x, 0)
#define IMPLY(a, b) (!(a) || (b))
@@ -269,6 +268,10 @@
long stm_id(object_t *obj);
void stm_set_prebuilt_identityhash(object_t *obj, uint64_t hash);
+/* Returns 1 if the object can still move (it's in the nursery), or 0
+ otherwise. After a minor collection no object can move any more. */
+long stm_can_move(object_t *);
+
/* ==================== END ==================== */
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -33,7 +33,6 @@
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);
char *_stm_get_segment_base(long index);
bool _stm_in_transaction(stm_thread_local_t *tl);
@@ -78,6 +77,8 @@
long stm_identityhash(object_t *obj);
long stm_id(object_t *obj);
void stm_set_prebuilt_identityhash(object_t *obj, uint64_t hash);
+
+int stm_can_move(object_t *);
""")
@@ -269,7 +270,7 @@
pass
def is_in_nursery(o):
- return lib._stm_in_nursery(o)
+ return lib.stm_can_move(o)
def stm_allocate_old(size):
o = lib._stm_allocate_old(size)
diff --git a/c7/test/test_nursery.py b/c7/test/test_nursery.py
--- a/c7/test/test_nursery.py
+++ b/c7/test/test_nursery.py
@@ -184,3 +184,16 @@
stm_write(old) # old objs to trace
stm_set_char(old, 'y')
self.commit_transaction()
+
+ def test_can_move(self):
+ self.start_transaction()
+ new = stm_allocate(16)
+ assert lib.stm_can_move(new) == 1
+ self.push_root(new)
+ stm_minor_collect()
+ old = self.pop_root()
+ assert lib.stm_can_move(old) == 0
+ self.commit_transaction()
+
+ self.start_transaction()
+ assert lib.stm_can_move(old) == 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit