summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-11-16 09:48:19 -0500
committerBen Gamari <ben@smart-cactus.org>2023-04-12 07:42:54 -0400
commitafe42ad150083ede8792dfc31ffc8399fbbc88aa (patch)
tree0792f369372893cd3f352dcadf1a38feea9f549d
parentd0455950f0599e01ab6913e494083f2e92428fd1 (diff)
downloadhaskell-afe42ad150083ede8792dfc31ffc8399fbbc88aa.tar.gz
nonmoving: Fix race in shortcutting
We must use an acquire load to read the info table pointer since if we find an indirection we must be certain that we see the indirectee. (cherry picked from commit b6a3ab00712ca40acd1d91ba910e18c972a345a8)
-rw-r--r--rts/include/rts/storage/ClosureMacros.h6
-rw-r--r--rts/sm/NonMovingShortcut.c3
2 files changed, 8 insertions, 1 deletions
diff --git a/rts/include/rts/storage/ClosureMacros.h b/rts/include/rts/storage/ClosureMacros.h
index 2ba84d1279..b1be8bf462 100644
--- a/rts/include/rts/storage/ClosureMacros.h
+++ b/rts/include/rts/storage/ClosureMacros.h
@@ -87,6 +87,12 @@ EXTERN_INLINE const StgInfoTable *get_itbl(const StgClosure *c)
return INFO_PTR_TO_STRUCT(RELAXED_LOAD(&c->header.info));
}
+EXTERN_INLINE const StgInfoTable *get_itbl_acquire(const StgClosure *c);
+EXTERN_INLINE const StgInfoTable *get_itbl_acquire(const StgClosure *c)
+{
+ return INFO_PTR_TO_STRUCT(ACQUIRE_LOAD(&c->header.info));
+}
+
EXTERN_INLINE const StgRetInfoTable *get_ret_itbl(const StgClosure *c);
EXTERN_INLINE const StgRetInfoTable *get_ret_itbl(const StgClosure *c)
{
diff --git a/rts/sm/NonMovingShortcut.c b/rts/sm/NonMovingShortcut.c
index 83c4857677..ee97ba1b70 100644
--- a/rts/sm/NonMovingShortcut.c
+++ b/rts/sm/NonMovingShortcut.c
@@ -153,7 +153,8 @@ selectee_changed:
// Selectee is a non-moving object, mark it.
markQueuePushClosure(queue, selectee, NULL);
- const StgInfoTable *selectee_info_tbl = get_itbl(selectee);
+ // This may synchronize with the release in updateWithIndirection.
+ const StgInfoTable *selectee_info_tbl = get_itbl_acquire(selectee);
switch (selectee_info_tbl->type) {
case WHITEHOLE: {
// Probably a loop. Abort.