Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,828
    • Issues 4,828
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 446
    • Merge requests 446
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Wiki
  • Commentary
  • rts

Last edited by Takenobu Tani Jun 15, 2019
Page history New page

rts

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, code to allocate Array# objects, and code to implement takeMVar#.

  • 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), time-profiling and code coverage of Haskell code are included.

  • Support for Software Transactional Memory.

Next, we try to make sense of how it all fits together.

Block Diagram

Find your way around the code

  • Coding conventions in the RTS
  • the layout of header files in includes/

Basics you should know about

  • RTS Configurations
  • The Word
  • What on earth is a .cmm file? and Cmm syntax

Major subsystems

  • Storage: memory layout and garbage collection
  • Haskell Execution: how Haskell code is executed
  • The Scheduler: threads, multi-processor support, FFI

Other topics

  • Sanity Checking
  • So how does foreign import "wrapper" work?
  • GHCi support: the byte-code interpreter and dynamic linker
  • Asynchronous exceptions
  • Software Transactional Memory (STM)
  • Weak Pointers and Finalizers
  • How Signals are handled
  • The IO Manager thread
  • The HEAP_ALLOCED macro
  • Memory ordering

Also check the list of cross-cutting concerns in Commentary.

External documentation

  • Blog posts by Edsko de Vries: Understanding the Stack and Understanding the RealWorld
Clone repository Edit sidebar

GHC Home
GHC User's Guide

Joining In

Newcomers info
Mailing Lists & IRC
The GHC Team

Documentation

GHC Status Info
Working conventions
Building Guide
Debugging
Commentary

Wiki

Title Index
Recent Changes