summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2020-02-18 09:38:27 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-29 05:08:36 -0500
commitb5fb58fd1a4a24b9273d9d2de65b6347e1654e98 (patch)
treeeec82775f0414f77d5444cd9e25a2885ba378a6e
parenta999ee96a22650b59855609f84e2808b4133e9e0 (diff)
downloadhaskell-b5fb58fd1a4a24b9273d9d2de65b6347e1654e98.tar.gz
Document and refactor a few things around bitmap scavenging
- Added a few comments in StgPAP - Added a few comments and assertions in scavenge_small_bitmap and walk_large_bitmap - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted dead code, used PlatformWordSize type.
-rw-r--r--compiler/GHC/Data/Bitmap.hs43
-rw-r--r--includes/rts/storage/Closures.h6
-rw-r--r--rts/sm/HeapUtils.h4
3 files changed, 17 insertions, 36 deletions
diff --git a/compiler/GHC/Data/Bitmap.hs b/compiler/GHC/Data/Bitmap.hs
index 1b93d6000d..985e74deb9 100644
--- a/compiler/GHC/Data/Bitmap.hs
+++ b/compiler/GHC/Data/Bitmap.hs
@@ -10,16 +10,15 @@
module GHC.Data.Bitmap (
Bitmap, mkBitmap,
- intsToBitmap, intsToReverseBitmap,
+ intsToReverseBitmap,
mAX_SMALL_BITMAP_SIZE,
- seqBitmap,
) where
import GhcPrelude
+import GHC.Platform
import GHC.Runtime.Heap.Layout
import GHC.Driver.Session
-import Util
import Data.Bits
@@ -43,31 +42,6 @@ chunkToBitmap dflags chunk =
oneAt :: Int -> StgWord
oneAt i = toStgWord dflags 1 `shiftL` i
--- | Make a bitmap where the slots specified are the /ones/ in the bitmap.
--- eg. @[0,1,3], size 4 ==> 0xb@.
---
--- The list of @Int@s /must/ be already sorted.
-intsToBitmap :: DynFlags
- -> Int -- ^ size in bits
- -> [Int] -- ^ sorted indices of ones
- -> Bitmap
-intsToBitmap dflags size = go 0
- where
- word_sz = wORD_SIZE_IN_BITS dflags
- oneAt :: Int -> StgWord
- oneAt i = toStgWord dflags 1 `shiftL` i
-
- -- It is important that we maintain strictness here.
- -- See Note [Strictness when building Bitmaps].
- go :: Int -> [Int] -> Bitmap
- go !pos slots
- | size <= pos = []
- | otherwise =
- (foldl' (.|.) (toStgWord dflags 0) (map (\i->oneAt (i - pos)) these)) :
- go (pos + word_sz) rest
- where
- (these,rest) = span (< (pos + word_sz)) slots
-
-- | Make a bitmap where the slots specified are the /zeros/ in the bitmap.
-- eg. @[0,1,3], size 4 ==> 0x4@ (we leave any bits outside the size as zero,
-- just to make the bitmap easier to read).
@@ -101,7 +75,7 @@ intsToReverseBitmap dflags size = go 0
{-
Note [Strictness when building Bitmaps]
-========================================
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
One of the places where @Bitmap@ is used is in in building Static Reference
Tables (SRTs) (in @GHC.Cmm.Info.Build.procpointSRT@). In #7450 it was noticed
@@ -125,10 +99,7 @@ large. This value represents the largest size of bitmap that can be
packed into a single word.
-}
mAX_SMALL_BITMAP_SIZE :: DynFlags -> Int
-mAX_SMALL_BITMAP_SIZE dflags
- | wORD_SIZE dflags == 4 = 27
- | otherwise = 58
-
-seqBitmap :: Bitmap -> a -> a
-seqBitmap = seqList
-
+mAX_SMALL_BITMAP_SIZE dflags =
+ case platformWordSize (targetPlatform dflags) of
+ PW4 -> 27 -- On 32-bit: 5 bits for size, 27 bits for bitmap
+ PW8 -> 58 -- On 64-bit: 6 bits for size, 58 bits for bitmap
diff --git a/includes/rts/storage/Closures.h b/includes/rts/storage/Closures.h
index b2b5eda407..81b6fd1fe1 100644
--- a/includes/rts/storage/Closures.h
+++ b/includes/rts/storage/Closures.h
@@ -104,6 +104,12 @@ typedef struct {
StgClosure *selectee;
} StgSelector;
+/*
+ PAP payload contains pointers and non-pointers interleaved and we only have
+ one info table for PAPs (stg_PAP_info). To visit pointers in a PAP payload we
+ use the `fun`s bitmap. For a PAP with n_args arguments the first n_args bits
+ in the fun's bitmap tell us which payload locations contain pointers.
+*/
typedef struct {
StgHeader header;
StgHalfWord arity; /* zero if it is an AP */
diff --git a/rts/sm/HeapUtils.h b/rts/sm/HeapUtils.h
index 2e9ca34f73..aa3321e5dc 100644
--- a/rts/sm/HeapUtils.h
+++ b/rts/sm/HeapUtils.h
@@ -17,6 +17,10 @@ walk_large_bitmap(walk_closures_cb *cb,
StgWord size,
void *user)
{
+ // Bitmap may have more bits than `size` when scavenging PAP payloads. See
+ // comments around StgPAP.
+ ASSERT(large_bitmap->size >= size);
+
uint32_t b = 0;
for (uint32_t i = 0; i < size; b++) {