Changes between Initial Version and Version 1 of Commentary/Rts/Storage/GC/CAFs


Ignore:
Timestamp:
Dec 7, 2009 9:36:05 AM (4 years ago)
Author:
simonmar
Comment:

moed from Commentary/Storage?/CAFs

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/Storage/GC/CAFs

    v1 v1  
     1 
     2 
     3= GHC Commentary: Garbage Collecting CAFs = 
     4 
     5Files: [[GhcFile(rts/sm/GC.c)]], function scavange_srt in [[GhcFile(rts/sm/Scav.h)]] 
     6 
     7Constant Applicative Forms, or CAFs for short, are top-level values defined in a program. 
     8Essentially, they are objects that are not allocated dynamically at run-time but, instead, 
     9are part of the static data of the program.  Sometimes, a CAF may refer to many values in the heap.  To avoid memory leaks in such situations, we need to know when a CAF is never going to be used 
     10again, and so we can deallocate the values that it refers to. 
     11 
     12 
     13== Static Reference Tables == 
     14File: [[GhcFile(includes/rts/storage/InfoTables.h)]] 
     15 
     16The info table of various closures may contain information about what static objects are 
     17references by the closure.  This information is stored in two parts: 
     18  1. a static reference table (SRT), which is an array of references to static objects 
     19  2. a bitmask which specifies which of the objects are actually used by the closure. 
     20 
     21There are two different ways to access this information depending on the size of the SRT: 
     22  * "small": if {{{srt_bitmap}}} is a small bitmap, not all 1s, then GET_FUN?_SRT contains the SRT. 
     23  * "large": if {{{srt_bitmap}}} is all 1s, then GET_FUN?_SRT contains a large bitmap, and the actual SRT. 
     24 
     25 
     26== Evacuating Static Objects == 
     27Files: [[GhcFile(rts/sm/GCThread.h)]], [[GhcFile(rts/sm/Evac.c)]], [[GhcFile(rts/sm/GC.c)]] 
     28 
     29While scavenging objects, we also process (aka "evacuate") any static objects that need to be kept alive.  When a GC thread discovers a live static object, it places it on its {{{static_objects}}} 
     30list.  Later, this list is used to scavange the static objects, potentially finding more live objects. 
     31Note that this process might find more static objects, and thus further extend the {{{static_objects}}} list. 
     32 
     33When a static object is scavenged, it is removed from {{{static_objects}}} and placed on another list, called {{{scavenged_static_objects}}}.  Later, we use this list to "clean up" the liveness markers from these static objects, so that we can repeat the process on the next garbage collection. 
     34Note that we can't "clean up" the liveness markers as we go along because we use them to notice 
     35cycles among the static objects.