blob: 5e5545a4eb875f8f2ecc937443bb33f67bdb58dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
-- A reduced test case for #11627
import GHC.Prim
import GHC.Types (Int(..),IO(..))
import System.Mem
main :: IO ()
main = do
-- Allocate a large object (size >= 8/10 of one block = 8/10 * 4096 B)
let nBytes = 123 * 4096
b <- newBlob nBytes
-- Shrink it by at least one word
let delta = 100
shrinkBlob b $ nBytes - delta
-- Perform a heap census (assumes we are running with -i0, so a census is
-- run after every GC)
performGC
-- Hold on to b so it is not GCed before the census
shrinkBlob b $ nBytes - delta
------------------------------------------------------------------------------
data Blob = Blob# !(MutableByteArray# RealWorld)
newBlob :: Int -> IO Blob
newBlob (I# n#) =
IO $ \s -> case newByteArray# n# s of
(# s', mba# #) -> (# s', Blob# mba# #)
shrinkBlob :: Blob -> Int -> IO ()
shrinkBlob (Blob# mba#) (I# n#) =
IO $ \s -> case shrinkMutableByteArray# mba# n# s of
s' -> (# s', () #)
|