|
|
# GHC Commentary: The Runtime System
|
|
|
|
|
|
|
|
|
GHC's runtime system is a slightly scary beast: 50,000 lines of C and C-- code, much of which seems at first glance to be completely obscure. What on earth does the RTS *do*? Here are the highlights:
|
|
|
|
|
|
- It includes all the bits required to execute Haskell code that aren't compiled into the code itself.
|
|
|
For example, the RTS contains the code that knows how to raise an exception when you call `error`,
|
|
|
and code to implement the multi-precision `Integer` operations (via the GMP library).
|
|
|
|
|
|
- It includes a sophisticated storage manager, including a multi-generational garbage collector with copying
|
|
|
and compacting strategies.
|
|
|
|
|
|
- It includes a user-space scheduler for Haskell threads, together with support for scheduling Haskell threads
|
|
|
across multiple CPUs, and allowing Haskell threads to call foreign functions in separate OS threads.
|
|
|
|
|
|
- There's a byte-code interpreter for GHCi, and a dynamic linker for loading up object code into a GHCi session.
|
|
|
|
|
|
- Heap-profiling (of various kinds) and time-profiling of Haskell code are included.
|
|
|
|
|
|
- Support for Software Transactional Memory is now included...
|
|
|
|
|
|
|
|
|
Next, we try to make sense of how it all fits together.
|
|
|
|
|
|
## Block Diagram
|
|
|
|
|
|
[](/trac/ghc/attachment/wiki/Commentary/Rts/rts-overview.png)
|
|
|
|
|
|
## What the hell is a `.cmm` file?
|
|
|
|
|
|
## Layout of heap objects
|
|
|
|
|
|
## Haskell Execution
|
|
|
|
|
|
## The Scheduler
|
|
|
|
|
|
## The Storage Manager
|
|
|
|
|
|
## So how does `foreign import "wrapper"` work?
|
|
|
|
|
|
## GHCi support: the byte-code interpreter and dynamic linker
|
|
|
|
|
|
## Asynchronous exceptions
|
|
|
|
|
|
## Software Transactional Memory (STM) |
|
|
\ No newline at end of file |