Skip to content
Commits on Sep 11, 2015
  1. @siddhanathan @thoughtpolice


    siddhanathan committed with thoughtpolice
    Rename StgArrWords to StgArrBytes (see Trac #8552)
    Reviewed By: austin
    Differential Revision:
    GHC Trac Issues: #8552
Commits on Aug 20, 2014
  1. @thoughtpolice

    [ci skip] includes: detabify/dewhitespace rts/storage/Closures.h

    thoughtpolice committed
    Signed-off-by: Austin Seipp <>
Commits on Mar 29, 2014
  1. @tibbe

    Add SmallArray# and SmallMutableArray# types

    tibbe committed
    These array types are smaller than Array# and MutableArray# and are
    faster when the array size is small, as they don't have the overhead
    of a card table. Having no card table reduces the closure size with 2
    words in the typical small array case and leads to less work when
    updating or GC:ing the array.
    Reduces both the runtime and memory allocation by 8.8% on my insert
    benchmark for the HashMap type in the unordered-containers package,
    which makes use of lots of small arrays. With tuned GC settings
    (i.e. `+RTS -A6M`) the runtime reduction is 15%.
    Fixes #8923.
Commits on Nov 22, 2013
  1. @Tarrasch @thoughtpolice

    Comment on StgArrWords vs StgArrBytes

    Tarrasch committed with thoughtpolice
    See #8552
    Signed-off-by: Arash Rouhani <>
    Reviewed-by: Austin Seipp <>
Commits on Jun 15, 2013
  1. @takano-akio @igfoo

    Allow multiple C finalizers to be attached to a Weak#

    takano-akio committed with igfoo
    The commit replaces mkWeakForeignEnv# with addCFinalizerToWeak#.
    This new primop mutates an existing Weak# object and adds a new
    C finalizer to it.
    This change removes an invariant in MarkWeak.c, namely that the relative
    order of Weak# objects in the list needs to be preserved across GC. This
    makes it easier to split the list into per-generation structures.
    The patch also removes a race condition between two threads calling
    finalizeWeak# on the same WEAK object at that same time.
Commits on May 21, 2013
  1. @simonmar

    fix comment (#7907)

    simonmar committed
Commits on Nov 1, 2012
  1. @simonmar

    The shape of StgTVar should not depend on THREADED_RTS

    simonmar committed
    By shear luck I think this didn't lead to any actual runtime crashes,
    but it did cause some problems for debugging.
Commits on Oct 8, 2012
  1. @simonmar

    Produce new-style Cmm from the Cmm parser

    simonmar committed
    The main change here is that the Cmm parser now allows high-level cmm
    code with argument-passing and function calls.  For example:
    foo ( gcptr a, bits32 b )
      if (b > 0) {
         // we can make tail calls passing arguments:
         jump stg_ap_0_fast(a);
      return (x,y);
    More details on the new cmm syntax are in Note [Syntax of .cmm files]
    in CmmParse.y.
    The old syntax is still more-or-less supported for those occasional
    code fragments that really need to explicitly manipulate the stack.
    However there are a couple of differences: it is now obligatory to
    give a list of live GlobalRegs on every jump, e.g.
      jump %ENTRY_CODE(Sp(0)) [R1];
    Again, more details in Note [Syntax of .cmm files].
    I have rewritten most of the .cmm files in the RTS into the new
    syntax, except for AutoApply.cmm which is generated by the genapply
    program: this file could be generated in the new syntax instead and
    would probably be better off for it, but I ran out of enthusiasm.
    Some other changes in this batch:
     - The PrimOp calling convention is gone, primops now use the ordinary
       NativeNodeCall convention.  This means that primops and "foreign
       import prim" code must be written in high-level cmm, but they can
       now take more than 10 arguments.
     - CmmSink now does constant-folding (should fix #7219)
     - .cmm files now go through the cmmPipeline, and as a result we
       generate better code in many cases.  All the object files generated
       for the RTS .cmm files are now smaller.  Performance should be
       better too, but I haven't measured it yet.
     - RET_DYN frames are removed from the RTS, lots of code goes away
     - we now have some more canned GC points to cover unboxed-tuples with
       2-4 pointers, which will reduce code size a little.
Commits on Feb 2, 2011
  1. @simonmar

    add a const

    simonmar committed
Commits on Dec 15, 2010
  1. @simonmar

    Implement stack chunks and separate TSO/STACK objects

    simonmar committed
    This patch makes two changes to the way stacks are managed:
    1. The stack is now stored in a separate object from the TSO.
    This means that it is easier to replace the stack object for a thread
    when the stack overflows or underflows; we don't have to leave behind
    the old TSO as an indirection any more.  Consequently, we can remove
    ThreadRelocated and deRefTSO(), which were a pain.
    This is obviously the right thing, but the last time I tried to do it
    it made performance worse.  This time I seem to have cracked it.
    2. Stacks are now represented as a chain of chunks, rather than
       a single monolithic object.
    The big advantage here is that individual chunks are marked clean or
    dirty according to whether they contain pointers to the young
    generation, and the GC can avoid traversing clean stack chunks during
    a young-generation collection.  This means that programs with deep
    stacks will see a big saving in GC overhead when using the default GC
    A secondary advantage is that there is much less copying involved as
    the stack grows.  Programs that quickly grow a deep stack will see big
    In some ways the implementation is simpler, as nothing special needs
    to be done to reclaim stack as the stack shrinks (the GC just recovers
    the dead stack chunks).  On the other hand, we have to manage stack
    underflow between chunks, so there's a new stack frame
    (UNDERFLOW_FRAME), and we now have separate TSO and STACK objects.
    The total amount of code is probably about the same as before.
    There are new RTS flags:
       -ki<size> Sets the initial thread stack size (default 1k)  Egs: -ki4k -ki2m
       -kc<size> Sets the stack chunk size (default 32k)
       -kb<size> Sets the stack chunk buffer size (default 1k)
    -ki was previously called just -k, and the old name is still accepted
    for backwards compatibility.  These new options are documented.
Commits on Jul 8, 2010
  1. @simonmar

    New asynchronous exception control API (ghc parts)

    simonmar committed
    As discussed on the libraries/haskell-cafe mailing lists
    This is a replacement for block/unblock in the asychronous exceptions
    API to fix a problem whereby a function could unblock asynchronous
    exceptions even if called within a blocked context.
    The new terminology is "mask" rather than "block" (to avoid confusion
    due to overloaded meanings of the latter).
    In GHC, we changed the names of some primops:
      blockAsyncExceptions#   -> maskAsyncExceptions#
      unblockAsyncExceptions# -> unmaskAsyncExceptions#
      asyncExceptionsBlocked# -> getMaskingState#
    and added one new primop:
    See the accompanying patch to libraries/base for the API changes.
Commits on Apr 1, 2010
  1. @simonmar

    Change the representation of the MVar blocked queue

    simonmar committed
    The list of threads blocked on an MVar is now represented as a list of
    separately allocated objects rather than being linked through the TSOs
    themselves.  This lets us remove a TSO from the list in O(1) time
    rather than O(n) time, by marking the list object.  Removing this
    linear component fixes some pathalogical performance cases where many
    threads were blocked on an MVar and became unreachable simultaneously
    (nofib/smp/threads007), or when sending an asynchronous exception to a
    TSO in a long list of thread blocked on an MVar.
    MVar performance has actually improved by a few percent as a result of
    this change, slightly to my surprise.
    This is the final cleanup in the sequence, which let me remove the old
    way of waking up threads (unblockOne(), MSG_WAKEUP) in favour of the
    new way (tryWakeupThread and MSG_TRY_WAKEUP, which is idempotent).  It
    is now the case that only the Capability that owns a TSO may modify
    its state (well, almost), and this simplifies various things.  More of
    the RTS is based on message-passing between Capabilities now.
Commits on Mar 29, 2010
  1. @simonmar

    New implementation of BLACKHOLEs

    simonmar committed
    This replaces the global blackhole_queue with a clever scheme that
    enables us to queue up blocked threads on the closure that they are
    blocked on, while still avoiding atomic instructions in the common
     - gets rid of a locked global data structure and some tricky GC code
       (replacing it with some per-thread data structures and different
       tricky GC code :)
     - wakeups are more prompt: parallel/concurrent performance should
       benefit.  I haven't seen anything dramatic in the parallel
       benchmarks so far, but a couple of threading benchmarks do improve
       a bit.
     - waking up a thread blocked on a blackhole is now O(1) (e.g. if
       it is the target of throwTo).
     - less sharing and better separation of Capabilities: communication
       is done with messages, the data structures are strictly owned by a
       Capability and cannot be modified except by sending messages.
     - this change will utlimately enable us to do more intelligent
       scheduling when threads block on each other.  This is what started
       off the whole thing, but it isn't done yet (#3838).
    I'll be documenting all this on the wiki in due course.
Commits on Mar 11, 2010
  1. @simonmar

    Use message-passing to implement throwTo in the RTS

    simonmar committed
    This replaces some complicated locking schemes with message-passing
    in the implementation of throwTo. The benefits are
     - previously it was impossible to guarantee that a throwTo from
       a thread running on one CPU to a thread running on another CPU
       would be noticed, and we had to rely on the GC to pick up these
       forgotten exceptions. This no longer happens.
     - the locking regime is simpler (though the code is about the same
     - threads can be unblocked from a blocked_exceptions queue without
       having to traverse the whole queue now.  It's a rare case, but
       replaces an O(n) operation with an O(1).
     - generally we move in the direction of sharing less between
       Capabilities (aka HECs), which will become important with other
       changes we have planned.
    Also in this patch I replaced several STM-specific closure types with
    a generic MUT_PRIM closure type, which allowed a lot of code in the GC
    and other places to go away, hence the line-count reduction.  The
    message-passing changes resulted in about a net zero line-count
Commits on Jan 1, 2010
  1. @aslatter
Commits on Dec 17, 2009
  1. @simonmar

    Fix #650: use a card table to mark dirty sections of mutable arrays

    simonmar committed
    The card table is an array of bytes, placed directly following the
    actual array data.  This means that array reading is unaffected, but
    array writing needs to read the array size from the header in order to
    find the card table.
    We use a bytemap rather than a bitmap, because updating the card table
    must be multi-thread safe.  Each byte refers to 128 entries of the
    array, but this is tunable by changing the constant
    MUT_ARR_PTRS_CARD_BITS in includes/Constants.h.
Commits on Aug 2, 2009
  1. @simonmar

    RTS tidyup sweep, first phase

    simonmar committed
    The first phase of this tidyup is focussed on the header files, and in
    particular making sure we are exposinng publicly exactly what we need
    to, and no more.
     - Rts.h now includes everything that the RTS exposes publicly,
       rather than a random subset of it.
     - Most of the public header files have moved into subdirectories, and
       many of them have been renamed.  But clients should not need to
       include any of the other headers directly, just #include the main
       public headers: Rts.h, HsFFI.h, RtsAPI.h.
     - All the headers needed for via-C compilation have moved into the
       stg subdirectory, which is self-contained.  Most of the headers for
       the rest of the RTS APIs have moved into the rts subdirectory.
     - I left MachDeps.h where it is, because it is so widely used in
       Haskell code.
     - I left a deprecated stub for RtsFlags.h in place.  The flag
       structures are now exposed by Rts.h.
     - Various internal APIs are no longer exposed by public header files.
     - Various bits of dead code and declarations have been removed
     - More gcc warnings are turned on, and the RTS code is more
     - More source files #include "PosixSource.h", and hence only use
       standard POSIX (1003.1c-1995) interfaces.
    There is a lot more tidying up still to do, this is just the first
    pass.  I also intend to standardise the names for external RTS APIs
    (e.g use the rts_ prefix consistently), and declare the internal APIs
    as hidden for shared libraries.
Something went wrong with that request. Please try again.