summaryrefslogtreecommitdiff
path: root/rts/sm/MarkWeak.c
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2015-06-01 21:34:02 +0100
committerSimon Marlow <marlowsd@gmail.com>2015-06-01 21:34:02 +0100
commitdfdc50d666498c5a1118557d67209fe067c61cc1 (patch)
tree0009f57ff2a980d636ac4730368485a0fa06711a /rts/sm/MarkWeak.c
parentf82e866504259c674d6fb3f66e67ae943a688b3f (diff)
downloadhaskell-dfdc50d666498c5a1118557d67209fe067c61cc1.tar.gz
Don't call DEAD_WEAK finalizer again on shutdown (#7170)
Summary: There's a race condition like this: # A foreign pointer gets promoted to the last generation # It has its finalizer called manually # We start shutting down the runtime in `hs_exit_` from the main thread # A minor GC starts running (`scheduleDoGC`) on one of the threads # The minor GC notices that we're in `SCHED_INTERRUPTING` state and advances to `SCHED_SHUTTING_DOWN` # The main thread tries to do major GC (with `scheduleDoGC`), but it exits early because we're in `SCHED_SHUTTING_DOWN` state # We end up with a `DEAD_WEAK` left on the list of weak pointers of the last generation, because it relied on major GC removing it from that list This change: * Ignores DEAD_WEAK finalizers when shutting down * Makes the major GC on shutdown more likely * Fixes a bogus assert Test Plan: before this diff https://ghc.haskell.org/trac/ghc/ticket/7170#comment:5 reproduced and after it doesn't Reviewers: ezyang, austin, simonmar Reviewed By: simonmar Subscribers: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D921 GHC Trac Issues: #7170
Diffstat (limited to 'rts/sm/MarkWeak.c')
-rw-r--r--rts/sm/MarkWeak.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/rts/sm/MarkWeak.c b/rts/sm/MarkWeak.c
index c5a107c480..60ac53f4b0 100644
--- a/rts/sm/MarkWeak.c
+++ b/rts/sm/MarkWeak.c
@@ -348,7 +348,8 @@ static void checkWeakPtrSanity(StgWeak *hd, StgWeak *tl)
{
StgWeak *w, *prev;
for (w = hd; w != NULL; prev = w, w = w->link) {
- ASSERT(INFO_PTR_TO_STRUCT(UNTAG_CLOSURE((StgClosure*)w)->header.info)->type == WEAK);
+ ASSERT(INFO_PTR_TO_STRUCT(UNTAG_CLOSURE((StgClosure*)w)->header.info)->type == WEAK
+ || UNTAG_CLOSURE((StgClosure*)w)->header.info == &stg_DEAD_WEAK_info);
checkClosure((StgClosure*)w);
}
if (tl != NULL) {