ghc-heap-8.6.5: Functions for walking GHC's heap

Copyright(c) 2012 Joachim Breitner
LicenseBSD3
MaintainerJoachim Breitner <mail@joachim-breitner.de>
Safe HaskellNone
LanguageHaskell2010

GHC.Exts.Heap

Contents

Description

With this module, you can investigate the heap representation of Haskell values, i.e. to investigate sharing and lazy evaluation.

Synopsis

Closure types

data GenClosure b Source #

This is the representation of a Haskell value on the heap. It reflects http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/Closures.h

The data type is parametrized by the type to store references in. Usually this is a Box with the type synonym Closure.

All Heap objects have the same basic layout. A header containing a pointer to the info table and a payload with various fields. The info field below always refers to the info table pointed to by the header. The remaining fields are the payload.

See https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/HeapObjects for more information.

Constructors

ConstrClosure

A data constructor

Fields

FunClosure

A function

Fields

ThunkClosure

A thunk, an expression not obviously in head normal form

Fields

SelectorClosure

A thunk which performs a simple selection operation

Fields

PAPClosure

An unsaturated function application

Fields

APClosure

A function application

Fields

APStackClosure

A suspended thunk evaluation

Fields

IndClosure

A pointer to another closure, introduced when a thunk is updated to point at its value

Fields

BCOClosure

A byte-code object (BCO) which can be interpreted by GHC's byte-code interpreter (e.g. as used by GHCi)

Fields

  • info :: !StgInfoTable
     
  • instrs :: !b

    A pointer to an ArrWords of instructions

  • literals :: !b

    A pointer to an ArrWords of literals

  • bcoptrs :: !b

    A pointer to an ArrWords of byte code objects

  • arity :: !HalfWord

    Arity of the partial application

  • size :: !HalfWord

    The size of this BCO in words

  • bitmap :: ![Word]

    An StgLargeBitmap describing the pointerhood of its args/free vars

BlackholeClosure

A thunk under evaluation by another thread

Fields

ArrWordsClosure

A ByteArray#

Fields

MutArrClosure

A MutableByteArray#

Fields

MVarClosure

An MVar#, with a queue of thread state objects blocking on them

Fields

MutVarClosure

A MutVar#

Fields

BlockingQueueClosure

An STM blocking queue.

Fields

IntClosure

Primitive Int

Fields

WordClosure

Primitive Word

Fields

Int64Closure

Primitive Int64

Fields

Word64Closure

Primitive Word64

Fields

AddrClosure

Primitive Addr

Fields

FloatClosure

Primitive Float

Fields

DoubleClosure

Primitive Double

Fields

OtherClosure

Another kind of closure

Fields

UnsupportedClosure 

Fields

Instances
Show b => Show (GenClosure b) # 
Instance details

Defined in GHC.Exts.Heap.Closures

data ClosureType Source #

data PrimType Source #

Instances
Eq PrimType # 
Instance details

Defined in GHC.Exts.Heap.Closures

Show PrimType # 
Instance details

Defined in GHC.Exts.Heap.Closures

class HasHeapRep (a :: TYPE rep) where Source #

Instances
HasHeapRep (a :: Type) # 
Instance details

Defined in GHC.Exts.Heap

HasHeapRep (a :: TYPE UnliftedRep) # 
Instance details

Defined in GHC.Exts.Heap

Int# ~ a => HasHeapRep (a :: TYPE IntRep) # 
Instance details

Defined in GHC.Exts.Heap

Word# ~ a => HasHeapRep (a :: TYPE WordRep) # 
Instance details

Defined in GHC.Exts.Heap

Int64# ~ a => HasHeapRep (a :: TYPE Int64Rep) # 
Instance details

Defined in GHC.Exts.Heap

Word64# ~ a => HasHeapRep (a :: TYPE Word64Rep) # 
Instance details

Defined in GHC.Exts.Heap

Addr# ~ a => HasHeapRep (a :: TYPE AddrRep) # 
Instance details

Defined in GHC.Exts.Heap

Float# ~ a => HasHeapRep (a :: TYPE FloatRep) # 
Instance details

Defined in GHC.Exts.Heap

Double# ~ a => HasHeapRep (a :: TYPE DoubleRep) # 
Instance details

Defined in GHC.Exts.Heap

Info Table types

data StgInfoTable Source #

This is a somewhat faithful representation of an info table. See http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/InfoTables.h for more details on this data structure.

type EntryFunPtr = FunPtr (Ptr () -> IO (Ptr ())) Source #

itblSize :: Int Source #

Size in bytes of a standard InfoTable

peekItbl :: Ptr StgInfoTable -> IO StgInfoTable Source #

Read an InfoTable from the heap into a haskell type. WARNING: This code assumes it is passed a pointer to a "standard" info table. If tables_next_to_code is enabled, it will look 1 byte before the start for the entry field.

Closure inspection

getBoxedClosureData :: Box -> IO Closure Source #

Like getClosureData, but taking a Box, so it is easier to work with.

allClosures :: GenClosure b -> [b] Source #

For generic code, this function returns all referenced closures.

Boxes

data Box Source #

An arbitrary Haskell value in a safe Box. The point is that even unevaluated thunks can safely be moved around inside the Box, and when required, e.g. in getBoxedClosureData, the function knows how far it has to evaluate the argument.

Constructors

Box Any 
Instances
Show Box # 
Instance details

Defined in GHC.Exts.Heap.Closures

asBox :: a -> Box Source #

This takes an arbitrary value and puts it into a box. Note that calls like

asBox (head list)

will put the thunk "head list" into the box, not the element at the head of the list. For that, use careful case expressions:

case list of x:_ -> asBox x

areBoxesEqual :: Box -> Box -> IO Bool Source #

Boxes can be compared, but this is not pure, as different heap objects can, after garbage collection, become the same object.