[Git][ghc/ghc][wip/decode_cloned_stack] Document entertainGC in test

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Sat Aug 5 07:29:50 UTC 2023



Sven Tennie pushed to branch wip/decode_cloned_stack at Glasgow Haskell Compiler / GHC


Commits:
533adb92 by Sven Tennie at 2023-08-05T09:26:55+02:00
Document entertainGC in test

It wasn't obvious why it's there and what its role is.

Also, increase the "entertainment level" a bit.

I checked in STG and Cmm dumps that this really generates closures (and
is not e.g. constant folded away.)

- - - - -


1 changed file:

- libraries/ghc-heap/tests/stack_misc_closures.hs


Changes:

=====================================
libraries/ghc-heap/tests/stack_misc_closures.hs
=====================================
@@ -327,13 +327,13 @@ type SetupFunction = State# RealWorld -> (# State# RealWorld, StackSnapshot# #)
 test :: HasCallStack => SetupFunction -> (StackFrame -> IO ()) -> IO ()
 test setup assertion = do
   stackSnapshot <- getStackSnapshot setup
-  performGC
-  traceM $ "entertainGC - " ++ entertainGC 100
+  traceM $ "entertainGC - " ++ entertainGC 10000
   -- Run garbage collection now, to prevent later surprises: It's hard to debug
   -- when the GC suddenly does it's work and there were bad closures or pointers.
   -- Better fail early, here.
   performGC
   stackClosure <- decodeStack stackSnapshot
+  traceM $ "entertainGC - " ++ entertainGC 10000
   performGC
   let stack = ssc_stack stackClosure
   performGC
@@ -345,9 +345,19 @@ test setup assertion = do
       assertEqual (length stack) 2
       assertion $ head stack
 
+-- | Generate some bogus closures to give the GC work
+--
+-- There are thresholds in the GC when it starts working. We want to force this
+-- to show that the decoding code is GC-save (updated pointers/references are a
+-- big topic here as the GC cares about references to the StgStack itself, but
+-- not to its frames.)
+--
+-- The "level of entertainment" x is a bit arbitrarily choosen: A future
+-- performace improvement may be to reduce it to a smaller number.
 entertainGC :: Int -> String
 entertainGC 0 = "0"
 entertainGC x = show x ++ entertainGC (x - 1)
+{-# NOINLINE entertainGC #-}
 
 testSize :: HasCallStack => SetupFunction -> Int -> IO ()
 testSize setup expectedSize = do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/533adb921479336572cd83e0e3400f0c10b4b4e8

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/533adb921479336572cd83e0e3400f0c10b4b4e8
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/20230805/0d0e158c/attachment-0001.html>


More information about the ghc-commits mailing list