Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r69927:d9489fac1c0e
Date: 2014-03-13 10:41 +0100
http://bitbucket.org/pypy/pypy/changeset/d9489fac1c0e/
Log: import stmgc/ae62acdb5d7c
diff --git a/rpython/translator/stm/src_stm/revision
b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-c6ed145863b4
+ae62acdb5d7c
diff --git a/rpython/translator/stm/src_stm/stm/core.c
b/rpython/translator/stm/src_stm/stm/core.c
--- a/rpython/translator/stm/src_stm/stm/core.c
+++ b/rpython/translator/stm/src_stm/stm/core.c
@@ -181,6 +181,7 @@
}
assert(list_is_empty(STM_PSEGMENT->modified_old_objects));
+ assert(list_is_empty(STM_PSEGMENT->young_weakrefs));
assert(tree_is_cleared(STM_PSEGMENT->young_outside_nursery));
assert(tree_is_cleared(STM_PSEGMENT->nursery_objects_shadows));
assert(tree_is_cleared(STM_PSEGMENT->callbacks_on_abort));
@@ -484,6 +485,7 @@
/* reset these lists to NULL too on abort */
LIST_FREE(pseg->objects_pointing_to_nursery);
LIST_FREE(pseg->large_overflow_objects);
+ list_clear(pseg->young_weakrefs);
}
static void abort_with_mutex(void)
diff --git a/rpython/translator/stm/src_stm/stm/core.h
b/rpython/translator/stm/src_stm/stm/core.h
--- a/rpython/translator/stm/src_stm/stm/core.h
+++ b/rpython/translator/stm/src_stm/stm/core.h
@@ -62,7 +62,7 @@
current transaction that have been flushed out of the nursery,
which occurs if the same transaction allocates too many objects.
*/
- GCFLAG_OVERFLOW_NUMBER_bit0 = 0x08 /* must be last */
+ GCFLAG_OVERFLOW_NUMBER_bit0 = 0x8 /* must be last */
};
@@ -106,6 +106,15 @@
next minor collection. */
struct tree_s *nursery_objects_shadows;
+ /* List of all young weakrefs to check in minor collections. These
+ are the only weakrefs that may point to young objects and never
+ contain NULL. */
+ struct list_s *young_weakrefs;
+
+ /* List of all old weakrefs to check in major collections. These
+ weakrefs never point to young objects and never contain NULL. */
+ struct list_s *old_weakrefs;
+
/* Tree of 'key->callback' associations from stm_call_on_abort() */
struct tree_s *callbacks_on_abort;
diff --git a/rpython/translator/stm/src_stm/stm/gcpage.c
b/rpython/translator/stm/src_stm/stm/gcpage.c
--- a/rpython/translator/stm/src_stm/stm/gcpage.c
+++ b/rpython/translator/stm/src_stm/stm/gcpage.c
@@ -451,7 +451,11 @@
/* 'objects_pointing_to_nursery' should be empty, but isn't
necessarily because it also lists objects that have been
written to but don't actually point to the nursery. Clear
- it up and set GCFLAG_WRITE_BARRIER again on the objects. */
+ it up and set GCFLAG_WRITE_BARRIER again on the objects.
+ This is the case for transactions where
+ MINOR_NOTHING_TO_DO() == false
+ but they still did write-barriers on objects
+ */
lst = pseg->objects_pointing_to_nursery;
if (lst != NULL) {
LIST_FOREACH_R(lst, uintptr_t /*item*/,
@@ -538,6 +542,9 @@
mark_visit_from_roots();
LIST_FREE(mark_objects_to_trace);
+ /* weakrefs: */
+ stm_visit_old_weakrefs();
+
/* cleanup */
clean_up_segment_lists();
diff --git a/rpython/translator/stm/src_stm/stm/nursery.c
b/rpython/translator/stm/src_stm/stm/nursery.c
--- a/rpython/translator/stm/src_stm/stm/nursery.c
+++ b/rpython/translator/stm/src_stm/stm/nursery.c
@@ -300,6 +300,9 @@
collect_oldrefs_to_nursery();
+ /* now all surviving nursery objects have been moved out */
+ stm_move_young_weakrefs();
+
throw_away_nursery(get_priv_segment(STM_SEGMENT->segment_num));
assert(MINOR_NOTHING_TO_DO(STM_PSEGMENT));
diff --git a/rpython/translator/stm/src_stm/stm/setup.c
b/rpython/translator/stm/src_stm/stm/setup.c
--- a/rpython/translator/stm/src_stm/stm/setup.c
+++ b/rpython/translator/stm/src_stm/stm/setup.c
@@ -58,6 +58,8 @@
pr->objects_pointing_to_nursery = NULL;
pr->large_overflow_objects = NULL;
pr->modified_old_objects = list_create();
+ pr->young_weakrefs = list_create();
+ pr->old_weakrefs = list_create();
pr->young_outside_nursery = tree_create();
pr->nursery_objects_shadows = tree_create();
pr->callbacks_on_abort = tree_create();
@@ -96,6 +98,8 @@
assert(pr->objects_pointing_to_nursery == NULL);
assert(pr->large_overflow_objects == NULL);
list_free(pr->modified_old_objects);
+ list_free(pr->young_weakrefs);
+ list_free(pr->old_weakrefs);
tree_free(pr->young_outside_nursery);
tree_free(pr->nursery_objects_shadows);
tree_free(pr->callbacks_on_abort);
diff --git a/rpython/translator/stm/src_stm/stmgc.c
b/rpython/translator/stm/src_stm/stmgc.c
--- a/rpython/translator/stm/src_stm/stmgc.c
+++ b/rpython/translator/stm/src_stm/stmgc.c
@@ -13,6 +13,7 @@
#include "stm/contention.h"
#include "stm/extra.h"
#include "stm/fprintcolor.h"
+#include "stm/weakref.h"
#include "stm/misc.c"
#include "stm/list.c"
@@ -29,3 +30,4 @@
#include "stm/contention.c"
#include "stm/extra.c"
#include "stm/fprintcolor.c"
+#include "stm/weakref.c"
diff --git a/rpython/translator/stm/src_stm/stmgc.h
b/rpython/translator/stm/src_stm/stmgc.h
--- a/rpython/translator/stm/src_stm/stmgc.h
+++ b/rpython/translator/stm/src_stm/stmgc.h
@@ -195,6 +195,17 @@
return (object_t *)p;
}
+/* Allocate a weakref object. Weakref objects have a
+ reference to an object at the byte-offset
+ stmcb_size_rounded_up(obj) - sizeof(void*)
+ You must assign the reference before the next collection may happen.
+ After that, you must not mutate the reference anymore. However,
+ it can become NULL after any GC if the reference dies during that
+ collection.
+ NOTE: For performance, we assume stmcb_size_rounded_up(weakref)==16
+*/
+object_t *stm_allocate_weakref(ssize_t size_rounded_up);
+
/* stm_setup() needs to be called once at the beginning of the program.
stm_teardown() can be called at the end, but that's not necessary
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit