Author: Remi Meier <[email protected]>
Branch: c8-small-uniform
Changeset: r1386:a1300b7dd558
Date: 2014-09-16 13:40 +0200
http://bitbucket.org/pypy/stmgc/changeset/a1300b7dd558/
Log: use small obj allocation (not yet synchronizing to other segments on
commit)
diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -246,7 +246,11 @@
realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
obj_size = stmcb_size_rounded_up((struct object_s *)realobj);
/* get the last page containing data from the object */
- end_page = (((uintptr_t)obj) + obj_size - 1) / 4096UL;
+ if (LIKELY(is_small_uniform(obj))) {
+ end_page = first_page;
+ } else {
+ end_page = (((uintptr_t)obj) + obj_size - 1) / 4096UL;
+ }
/* add to read set: */
stm_read(obj);
@@ -256,10 +260,9 @@
memcpy(bk_obj, realobj, obj_size);
/* if there are shared pages, privatize them */
-
- uintptr_t page;
+ uintptr_t page = first_page;
for (page = first_page; page <= end_page; page++) {
- if (is_shared_log_page(page)) {
+ if (UNLIKELY(is_shared_log_page(page))) {
long i;
for (i = 0; i < NB_SEGMENTS; i++) {
acquire_privatization_lock(i);
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -88,10 +88,20 @@
realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
size = stmcb_size_rounded_up((struct object_s *)realobj);
- /* XXX: small objs */
- char *allocated = allocate_outside_nursery_large(size);
- nobj = (object_t *)(allocated - stm_object_pages);
+ if (size > GC_LAST_SMALL_SIZE) {
+ /* case 1: object is not small enough.
+ Ask gcpage.c for an allocation via largemalloc. */
+ char *allocated = allocate_outside_nursery_large(size);
+ nobj = (object_t *)(allocated - stm_object_pages);
+ }
+ else {
+ /* case "small enough" */
+ char *allocated = allocate_outside_nursery_small(size);
+ dprintf(("outside small %p or %p, sz=%lu\n", allocated, allocated
- stm_object_pages, size));
+ nobj = (object_t *)(allocated - stm_object_pages);
+ }
+ /* copy the object */
copy_large_object:;
char *realnobj = REAL_ADDRESS(STM_SEGMENT->segment_base, nobj);
memcpy(realnobj, realobj, size);
diff --git a/c8/test/test_nursery.py b/c8/test/test_nursery.py
--- a/c8/test/test_nursery.py
+++ b/c8/test/test_nursery.py
@@ -252,3 +252,31 @@
# if the read marker is not cleared, we get false conflicts
# with later transactions using the same large-malloced slot
# as our outside-nursery-obj
+
+ def test_synchronize_small_obj(self):
+ # make a shared page, and privatize it
+ self.start_transaction()
+ new = stm_allocate(16)
+ self.push_root(new)
+ self.commit_transaction()
+ new = self.pop_root()
+ self.push_root(new)
+
+ self.start_transaction()
+ stm_set_char(new, 'A')
+ self.commit_transaction()
+
+ # make a new object of the same size, which should end in the
+ # same page
+ self.start_transaction()
+ new2 = stm_allocate(16)
+ stm_set_char(new2, 'a')
+ self.push_root(new2)
+ self.commit_transaction()
+ new2 = self.pop_root()
+ print "new2", new2
+
+ # check that this new object was correctly sychronized
+ self.switch(1)
+ self.start_transaction()
+ assert stm_get_char(new2) == 'a'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit