Author: Remi Meier <[email protected]>
Branch: use-gcc
Changeset: r1954:8cba33de2246
Date: 2015-09-08 11:43 +0200
http://bitbucket.org/pypy/stmgc/changeset/8cba33de2246/
Log: avoid losing entries in a major gc
directly after looking up an entry in a hashtable, a major GC would
get rid of it. This may be surprising, so work around it by always
doing a read barrier in lookup() (seems to be the common use-case
anyway).
diff --git a/c8/stm/hashtable.c b/c8/stm/hashtable.c
--- a/c8/stm/hashtable.c
+++ b/c8/stm/hashtable.c
@@ -227,8 +227,10 @@
i = index & mask;
entry = VOLATILE_TABLE(table)->items[i];
if (entry != NULL) {
- if (entry->index == index)
+ if (entry->index == index) {
+ stm_read((object_t*)entry);
return entry; /* found at the first try */
+ }
uintptr_t perturb = index;
while (1) {
@@ -236,8 +238,10 @@
i &= mask;
entry = VOLATILE_TABLE(table)->items[i];
if (entry != NULL) {
- if (entry->index == index)
+ if (entry->index == index) {
+ stm_read((object_t*)entry);
return entry; /* found */
+ }
}
else
break;
@@ -335,6 +339,7 @@
table->items[i] = entry;
write_fence(); /* make sure 'table->items' is written here */
VOLATILE_TABLE(table)->resize_counter = rc - 6; /* unlock */
+ stm_read((object_t*)entry);
return entry;
}
else {
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -725,6 +725,9 @@
stm_hashtable_t *stm_hashtable_create(void);
void stm_hashtable_free(stm_hashtable_t *);
+/* lookup returns a reference to an entry. This entry is only valid
+ in the current transaction and needs to be looked up again if there
+ may have been a break inbetween. */
stm_hashtable_entry_t *stm_hashtable_lookup(object_t *, stm_hashtable_t *,
uintptr_t key);
object_t *stm_hashtable_read(object_t *, stm_hashtable_t *, uintptr_t key);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit