| 19 | | * Aging: objects can be aged within a generation, to avoid premature promotion. In GHC 6.12 and earlier this was implemented by having each generation consist of a runtime-tunable number of ''steps'', so objects would be moved through the list of steps before being promoted to the next highest generation. We found that having 2 steps was almost always the best ''integral'' number of steps, but GHC 6.12 did not support a fractional number of steps. In GHC 6.13 and later, the concept of steps was removed. Aging is still supported, by having each block point to the generation to which objects in that block should be promoted; this lets us provide any fractional number of steps between 1 and 2, while eliminating the infrastructural overhead of steps. |
| | 28 | * Aging: objects can be aged within a generation, to avoid premature promotion. See [wiki:Commentary/Rts/Storage/GC/Aging]. In GHC 6.12 and earlier this was implemented by having each generation consist of a runtime-tunable number of ''steps'', so objects would be moved through the list of steps before being promoted to the next highest generation. We found that having 2 steps was almost always the best ''integral'' number of steps, but GHC 6.12 did not support a fractional number of steps. In GHC 6.13 and later, the concept of steps was removed. Aging is still supported, by having each block point to the generation to which objects in that block should be promoted; this lets us provide any fractional number of steps between 1 and 2, while eliminating the infrastructural overhead of steps. |
| | 33 | |
| | 34 | [[GhcFile(includes/rts/storage/GC.h)]] |
| | 35 | |
| | 36 | === generation === |
| | 37 | |
| | 38 | The main data structure is `generation`, which contains: |
| | 39 | |
| | 40 | `blocks`:: |
| | 41 | a pointer to a list of blocks |
| | 42 | |
| | 43 | `large_objects`:: |
| | 44 | a pointer to a list of blocks containing large objects |
| | 45 | |
| | 46 | `threads`:: |
| | 47 | a list of threads in this generation |
| | 48 | |
| | 49 | `mut_list`:: |
| | 50 | the "remembered set", a list of blocks containing pointers to objects in ''this'' generation that point to objects in ''younger'' generations |
| | 51 | |
| | 52 | and various other administrative fields (see [[GhcFile(includes/rts/storage/GC.h)]] for the details). |
| | 53 | |
| | 54 | Generations are kept in the array `generations[]`, indexed by the generation number. |
| | 55 | |
| | 56 | === nursery === |
| | 57 | |
| | 58 | A `nursery` is a list of blocks into which the mutator allocates new (small) objects. For resaons of locality, we want to re-use the list of blocks for the nursery after each GC, so we keep the nursery blocks rather than freeing and re-allocating a new nursery after GC. |
| | 59 | |
| | 60 | The struct `nursery` contains only two fields |
| | 61 | |
| | 62 | `blocks`:: |
| | 63 | the list of blocks in this nursery |
| | 64 | `n_blocks`:: |
| | 65 | the number of blocks in the above list |
| | 66 | |
| | 67 | In the threaded RTS, there is one nursery per Capability, as each Capability allocates independently into its own allocation area. Nurseries are therefore stored in an array `nurseries[]`, indexed by Capability number. |
| | 68 | |
| | 69 | The blocks of the nursery notionally logically to generation 0, although they are not kept on the list `generations[0].blocks`. The reason is that we want to keep the actual nursery blocks separate from any blocks containing live data in generation 0. Generation 0 may contain live data for two reasons: |
| | 70 | |
| | 71 | * objects live in the nursery are not promoted to generation 1 immediately, instead they are [wiki:Commentary/Rts/Storage/GC/Aging aged], first being copied to generation 0, and then being promoted to generation 1 in the next GC cycle if they are still alive. |
| | 72 | |
| | 73 | * If there is only one generation (generation 0), then live objects in generation 0 are retained in generation 0 after a GC. |
| | 74 | |