rts: Factor out large bitmap walking
authorBen Gamari <ben@well-typed.com>
Tue, 5 Feb 2019 15:59:32 +0000 (10:59 -0500)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sat, 9 Mar 2019 12:30:17 +0000 (07:30 -0500)
This will be needed by the mark phase of the non-moving collector
so let's factor it out.

rts/sm/HeapUtils.h [new file with mode: 0644]
rts/sm/Scav.c

diff --git a/rts/sm/HeapUtils.h b/rts/sm/HeapUtils.h
new file mode 100644 (file)
index 0000000..2e9ca34
--- /dev/null
@@ -0,0 +1,33 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team 1998-2008
+ *
+ * General utilities for walking the heap
+ *
+ * ---------------------------------------------------------------------------*/
+
+#pragma once
+
+typedef void (walk_closures_cb)(StgClosure **, void *);
+
+INLINE_HEADER void
+walk_large_bitmap(walk_closures_cb *cb,
+                  StgClosure **p,
+                  StgLargeBitmap *large_bitmap,
+                  StgWord size,
+                  void *user)
+{
+    uint32_t b = 0;
+
+    for (uint32_t i = 0; i < size; b++) {
+        StgWord bitmap = large_bitmap->bitmap[b];
+        uint32_t j = stg_min(size-i, BITS_IN(W_));
+        i += j;
+        for (; j > 0; j--, p++) {
+            if ((bitmap & 1) == 0) {
+                cb(p, user);
+            }
+            bitmap = bitmap >> 1;
+        }
+    }
+}
index 8bc7029..36592af 100644 (file)
@@ -58,6 +58,7 @@
 #include "Sanity.h"
 #include "Capability.h"
 #include "LdvProfile.h"
+#include "HeapUtils.h"
 #include "Hash.h"
 
 #include "sm/MarkWeak.h"
@@ -77,6 +78,11 @@ static void scavenge_large_bitmap (StgPtr p,
 # define scavenge_capability_mut_lists(cap) scavenge_capability_mut_Lists1(cap)
 #endif
 
+static void do_evacuate(StgClosure **p, void *user STG_UNUSED)
+{
+    evacuate(p);
+}
+
 /* -----------------------------------------------------------------------------
    Scavenge a TSO.
    -------------------------------------------------------------------------- */
@@ -1777,22 +1783,7 @@ scavenge_static(void)
 static void
 scavenge_large_bitmap( StgPtr p, StgLargeBitmap *large_bitmap, StgWord size )
 {
-    uint32_t i, j, b;
-    StgWord bitmap;
-
-    b = 0;
-
-    for (i = 0; i < size; b++) {
-        bitmap = large_bitmap->bitmap[b];
-        j = stg_min(size-i, BITS_IN(W_));
-        i += j;
-        for (; j > 0; j--, p++) {
-            if ((bitmap & 1) == 0) {
-                evacuate((StgClosure **)p);
-            }
-            bitmap = bitmap >> 1;
-        }
-    }
+    walk_large_bitmap(do_evacuate, (StgClosure **) p, large_bitmap, size, NULL);
 }