[Git][ghc/ghc][wip/T19146] 2 commits: rts: Don't sanity-check StgTSO.global_link
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Wed May 3 13:10:04 UTC 2023
Ben Gamari pushed to branch wip/T19146 at Glasgow Haskell Compiler / GHC
Commits:
b7999e92 by Ben Gamari at 2023-05-03T09:10:00-04:00
rts: Don't sanity-check StgTSO.global_link
See Note [Avoid dangling global_link pointers].
Fixes #19146.
- - - - -
c69e7e6d by Ben Gamari at 2023-05-03T09:10:00-04:00
rts: Introduce printGlobalThreads
- - - - -
3 changed files:
- rts/Threads.c
- rts/Threads.h
- rts/sm/Sanity.c
Changes:
=====================================
rts/Threads.c
=====================================
@@ -1008,6 +1008,20 @@ printAllThreads(void)
}
}
+void
+printGlobalThreads(void)
+{
+ for (uint32_t g = 0; g < RtsFlags.GcFlags.generations; g++) {
+ debugBelch("\ngen %d\n", g);
+ for (StgTSO *t = generations[g].threads; t != END_TSO_QUEUE; t = t->global_link) {
+ debugBelch("thread %p (id=%lu)\n", t, t->id);
+ }
+ for (StgTSO *t = generations[g].old_threads; t != END_TSO_QUEUE; t = t->global_link) {
+ debugBelch("thread %p (id=%lu) (old)\n", t, t->id);
+ }
+ }
+}
+
// useful from gdb
void
printThreadQueue(StgTSO *t)
=====================================
rts/Threads.h
=====================================
@@ -46,6 +46,7 @@ bool performTryPutMVar(Capability *cap, StgMVar *mvar, StgClosure *value);
void printThreadBlockage (StgTSO *tso);
void printThreadStatus (StgTSO *t);
void printAllThreads (void);
+void printGlobalThreads(void);
void printThreadQueue (StgTSO *t);
#endif
=====================================
rts/sm/Sanity.c
=====================================
@@ -737,6 +737,27 @@ checkSTACK (StgStack *stack)
checkStackChunk(sp, stack_end);
}
+/*
+ * Note [Sanity-checking global_link]
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * TSOs are a bit odd in that they have a global_link pointer field
+ * which is not scavenged by the GC. This field is used to track the
+ * generations[_].[old_]threads lists and is ultimately updated by
+ * MarkWeak.c:tidyThreadList.
+
+ * Typically the fact that this field is not scavenged is fine as all reachable
+ * TSOs on the heap are guaranteed to be on some generation's thread list and
+ * therefore will be scavenged by tidyThreadList. However, the sanity checker
+ * poses a bit of a challenge here as it walks heap blocks directly and
+ * therefore may encounter TSOs which aren't reachable via the heap.
+ * For this reason, checkTSO does not check global_link. Instead, we only do
+ * so in checkGlobalTSOList, which by definition will only look at
+ * threads which are reachable via a thread list (and therefore must have won
+ * the forwarding-pointer race).
+ *
+ * See #19146.
+ */
+
void
checkTSO(StgTSO *tso)
{
@@ -761,9 +782,11 @@ checkTSO(StgTSO *tso)
ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->bq));
ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->blocked_exceptions));
ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->stackobj));
- ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->global_link) &&
- (tso->global_link == END_TSO_QUEUE ||
- get_itbl((StgClosure*)tso->global_link)->type == TSO));
+
+ // This assertion is sadly not viable. See Note [Sanity-checking global_link].
+ //ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->global_link) &&
+ // (tso->global_link == END_TSO_QUEUE ||
+ // get_itbl((StgClosure*)tso->global_link)->type == TSO));
if (tso->label) {
ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso->label));
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a786945f3b976bcb451476f8b1710c4cc313fa4d...c69e7e6d86c7528d6cb321bb24be52633560acfb
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a786945f3b976bcb451476f8b1710c4cc313fa4d...c69e7e6d86c7528d6cb321bb24be52633560acfb
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230503/fac3f4a1/attachment-0001.html>
More information about the ghc-commits
mailing list