Commit b5fb58fd authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan Committed by Marge Bot

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.
parent a999ee96
Pipeline #16335 passed with stages
in 521 minutes and 55 seconds
......@@ -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
......@@ -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 */
......
......@@ -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++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment