[Git][ghc/ghc][wip/heap-rep-decode-tweaks] 2 commits: Remove special case for GHC.ByteCode.Instr

Matthew Pickering gitlab at gitlab.haskell.org
Tue Nov 24 15:58:38 UTC 2020



Matthew Pickering pushed to branch wip/heap-rep-decode-tweaks at Glasgow Haskell Compiler / GHC


Commits:
778af89a by Matthew Pickering at 2020-11-24T15:57:14+00:00
Remove special case for GHC.ByteCode.Instr

This was added in
https://github.com/nomeata/ghc-heap-view/commit/34935206e51b9c86902481d84d2f368a6fd93423

GHC.ByteCode.Instr.BreakInfo no longer exists so the special case is dead code.

Any check like this can be easily dealt with in client code.

- - - - -
4b844a5c by Matthew Pickering at 2020-11-24T15:58:23+00:00
Split Up getClosureDataFromHeapRep

Motivation

1. Don't enforce the repeated decoding of an info table, when the client
can cache it (ghc-debug)
2. Allow the constructor information decoding to be overridden, this
casues segfaults in ghc-debug

- - - - -


1 changed file:

- libraries/ghc-heap/GHC/Exts/Heap.hs


Changes:

=====================================
libraries/ghc-heap/GHC/Exts/Heap.hs
=====================================
@@ -29,6 +29,7 @@ module GHC.Exts.Heap (
     , PrimType(..)
     , HasHeapRep(getClosureData)
     , getClosureDataFromHeapRep
+    , getClosureDataFromHeapRepPrim
 
     -- * Info Table types
     , StgInfoTable(..)
@@ -152,26 +153,34 @@ getClosureDataFromHeapObject x = do
                 STACK -> pure $ UnsupportedClosure infoTable
                 _ -> getClosureDataFromHeapRep heapRep infoTablePtr ptrList
 
+
 -- | Convert an unpacked heap object, to a `GenClosure b`. The inputs to this
 -- function can be generated from a heap object using `unpackClosure#`.
-getClosureDataFromHeapRep
-    :: ByteArray#
+getClosureDataFromHeapRep :: ByteArray# -> Ptr StgInfoTable -> [b] -> IO (GenClosure b)
+getClosureDataFromHeapRep heapRep infoTablePtr pts = do
+  itbl <- peekItbl infoTablePtr
+  getClosureDataFromHeapRepPrim (dataConNames infoTablePtr) itbl heapRep pts
+
+getClosureDataFromHeapRepPrim
+    :: IO (String, String, String)
+    -- ^ A continuation used to decode the constructor description field,
+    -- in ghc-debug this code can lead to segfaults because dataConNames
+    -- will dereference a random part of memory.
+    -> StgInfoTable
+    -- ^ The `StgInfoTable` of the closure, extracted from the heap
+    -- representation.
+    -> ByteArray#
     -- ^ Heap representation of the closure as returned by `unpackClosure#`.
     -- This includes all of the object including the header, info table
     -- pointer, pointer data, and non-pointer data. The ByteArray# may be
     -- pinned or unpinned.
-    -> Ptr StgInfoTable
-    -- ^ Pointer to the `StgInfoTable` of the closure, extracted from the heap
-    -- representation. The info table must not be movable by GC i.e. must be in
-    -- pinned or off-heap memory.
     -> [b]
     -- ^ Pointers in the payload of the closure, extracted from the heap
     -- representation as returned by `collect_pointers()` in `Heap.c`. The type
     -- `b` is some representation of a pointer e.g. `Any` or `Ptr Any`.
     -> IO (GenClosure b)
     -- ^ Heap representation of the closure.
-getClosureDataFromHeapRep heapRep infoTablePtr pts = do
-    itbl <- peekItbl infoTablePtr
+getClosureDataFromHeapRepPrim getConDesc itbl heapRep pts = do
     let -- heapRep as a list of words.
         rawHeapWords :: [Word]
         rawHeapWords = [W# (indexWordArray# heapRep i) | I# i <- [0.. end] ]
@@ -189,10 +198,8 @@ getClosureDataFromHeapRep heapRep infoTablePtr pts = do
         npts = drop (closureTypeHeaderSize (tipe itbl) + length pts) rawHeapWords
     case tipe itbl of
         t | t >= CONSTR && t <= CONSTR_NOCAF -> do
-            (p, m, n) <- dataConNames infoTablePtr
-            if m == "GHC.ByteCode.Instr" && n == "BreakInfo"
-              then pure $ UnsupportedClosure itbl
-              else pure $ ConstrClosure itbl pts npts p m n
+            (p, m, n) <- getConDesc
+            pure $ ConstrClosure itbl pts npts p m n
 
         t | t >= THUNK && t <= THUNK_STATIC -> do
             pure $ ThunkClosure itbl pts npts



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/51e3ecc54142ea04965bf7e2b66622eb118f7ab6...4b844a5c89889fb4f3f21825f50d6281519c84ea

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/51e3ecc54142ea04965bf7e2b66622eb118f7ab6...4b844a5c89889fb4f3f21825f50d6281519c84ea
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/20201124/db86686c/attachment-0001.html>


More information about the ghc-commits mailing list