[Git][ghc/ghc][wip/T22264-9.2] 2 commits: nonmoving: Deduplicate assertion

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Fri Oct 21 04:57:25 UTC 2022



Ben Gamari pushed to branch wip/T22264-9.2 at Glasgow Haskell Compiler / GHC


Commits:
f0b6a6bc by Ben Gamari at 2022-10-21T04:10:29+00:00
nonmoving: Deduplicate assertion

- - - - -
4ea1cf12 by Ben Gamari at 2022-10-21T04:11:01+00:00
nonmoving: Fix and tighten up weak pointer assertions

Previously we were relying on nonmovingIsMarkedThisCycle on pointers
that may be large objects.

- - - - -


3 changed files:

- rts/sm/MarkWeak.c
- rts/sm/NonMoving.h
- rts/sm/NonMovingMark.c


Changes:

=====================================
rts/sm/MarkWeak.c
=====================================
@@ -88,10 +88,14 @@ static void    tidyThreadList (generation *gen);
  * When using the non-moving GC we defer weak pointer processing
  * until after marking. Here we take advantage of the fact that it is
  * impossible for a Weak# object to hold references to an younger object
- * (except in the case where a C finalizerswas added, in which case the Weak#
+ * (except in the case where a C finalizer was added, in which case the Weak#
  * will be on the generational remembered set).
  *
- * TODO
+ * Since we cannot yet process weak pointers in the preparatory collection,
+ * we instead keep all weak pointers on oldest_gen->weak_ptr_list, where
+ * nonmovingCollect will find them. From there they will be moved to
+ * nonmoving_old_weak_ptr_list. During the mark loop we will move weaks with
+ * reachable keys to nonmoving_weak_ptr_list
  */
 
 /*
@@ -283,6 +287,7 @@ static bool tidyWeakList(generation *gen)
 {
     if (RtsFlags.GcFlags.useNonmoving && gen == oldest_gen) {
         // See Note [Weak pointer processing and the non-moving GC].
+        ASSERT(gen->old_weak_ptr_list == NULL);
         return false;
     }
 


=====================================
rts/sm/NonMoving.h
=====================================
@@ -256,15 +256,22 @@ INLINE_HEADER struct NonmovingSegment *nonmovingGetSegment_unchecked(StgPtr p)
     return (struct NonmovingSegment *) (((uintptr_t) p) & mask);
 }
 
+INLINE_HEADER bool nonmovingIsInSegment(StgPtr p)
+{
+    bdescr *bd = Bdescr(p);
+    return HEAP_ALLOCED_GC(p) &&
+        (bd->flags & BF_NONMOVING) &&
+        !(bd->flags & BF_LARGE);
+}
+
 INLINE_HEADER struct NonmovingSegment *nonmovingGetSegment(StgPtr p)
 {
-    ASSERT(HEAP_ALLOCED_GC(p) && (Bdescr(p)->flags & BF_NONMOVING));
+    ASSERT(nonmovingIsInSegment(p));
     return nonmovingGetSegment_unchecked(p);
 }
 
 INLINE_HEADER nonmoving_block_idx nonmovingGetBlockIdx(StgPtr p)
 {
-    ASSERT(HEAP_ALLOCED_GC(p) && (Bdescr(p)->flags & BF_NONMOVING));
     struct NonmovingSegment *seg = nonmovingGetSegment(p);
     ptrdiff_t blk0 = (ptrdiff_t)nonmovingSegmentGetBlock(seg, 0);
     ptrdiff_t offset = (ptrdiff_t)p - blk0;
@@ -289,7 +296,6 @@ INLINE_HEADER void nonmovingSetClosureMark(StgPtr p)
     nonmovingSetMark(nonmovingGetSegment(p), nonmovingGetBlockIdx(p));
 }
 
-// TODO: Audit the uses of these
 /* Was the given closure marked this major GC cycle? */
 INLINE_HEADER bool nonmovingClosureMarkedThisCycle(StgPtr p)
 {


=====================================
rts/sm/NonMovingMark.c
=====================================
@@ -1843,8 +1843,10 @@ bool nonmovingTidyWeaks (struct MarkQueue_ *queue)
         ASSERT(w->header.info == &stg_WEAK_info);
 
         // See Note [Aging under the non-moving collector].
-        bool in_nonmoving = Bdescr((StgPtr) w->key)->flags & BF_NONMOVING;
-        if (!in_nonmoving || nonmovingIsNowAlive(w->key)) {
+        bool key_in_nonmoving = Bdescr((StgPtr) w->key)->flags & BF_NONMOVING;
+        ASSERT(key_in_nonmoving);
+
+        if (nonmovingIsNowAlive(w->key)) {
             nonmovingMarkLiveWeak(queue, w);
             did_work = true;
 
@@ -1874,7 +1876,7 @@ void nonmovingMarkDeadWeak (struct MarkQueue_ *queue, StgWeak *w)
 
 void nonmovingMarkLiveWeak (struct MarkQueue_ *queue, StgWeak *w)
 {
-    ASSERT(nonmovingClosureMarkedThisCycle((P_)w));
+    ASSERT(nonmovingIsNowAlive((P_)w));
     markQueuePushClosure_(queue, w->value);
     markQueuePushClosure_(queue, w->finalizer);
     markQueuePushClosure_(queue, w->cfinalizers);
@@ -1888,9 +1890,9 @@ void nonmovingMarkDeadWeaks (struct MarkQueue_ *queue, StgWeak **dead_weaks)
 {
     StgWeak *next_w;
     for (StgWeak *w = nonmoving_old_weak_ptr_list; w; w = next_w) {
-        ASSERT(!nonmovingClosureMarkedThisCycle((P_)(w->key)));
+        ASSERT(!nonmovingIsNowAlive((P_)(w->key)));
         nonmovingMarkDeadWeak(queue, w);
-        next_w = w ->link;
+        next_w = w->link;
         w->link = *dead_weaks;
         *dead_weaks = w;
     }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c9f6042e8213b825247e23d04e8ee0b4661cab9a...4ea1cf1279ac82a18a492ec7cb6616bc57853b8e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c9f6042e8213b825247e23d04e8ee0b4661cab9a...4ea1cf1279ac82a18a492ec7cb6616bc57853b8e
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/20221021/962b6b77/attachment-0001.html>


More information about the ghc-commits mailing list