1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 1998-2008
4  *
5  * Generational garbage collector
6  *
7  * Documentation on the architecture of the Garbage Collector can be
8  * found in the online commentary:
9  *
10  *   https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/storage/gc
11  *
12  * ---------------------------------------------------------------------------*/
13 
14 #pragma once
15 
16 #include "BeginPrivate.h"
17 
18 #include "HeapAlloc.h"
19 
20 void GarbageCollect (uint32_t collect_gen,
21                      bool do_heap_census,
22                      bool deadlock_detect,
23                      uint32_t gc_type,
24                      Capability *cap,
25                      bool idle_cap[]);
26 
27 typedef void (*evac_fn)(void *user, StgClosure **root);
28 
29 StgClosure * isAlive      ( StgClosure *p );
30 void         markCAFs     ( evac_fn evac, void *user );
31 
32 bool doIdleGCWork(Capability *cap, bool all);
33 
34 extern uint32_t N;
35 extern bool major_gc;
36 /* See Note [Deadlock detection under nonmoving collector]. */
37 extern bool deadlock_detect_gc;
38 extern bool unload_mark_needed;
39 
40 extern bdescr *mark_stack_bd;
41 extern bdescr *mark_stack_top_bd;
42 extern StgPtr mark_sp;
43 
44 extern bool work_stealing;
45 
46 #if defined(PROF_SPIN) && defined(THREADED_RTS)
47 extern volatile StgWord64 whitehole_gc_spin;
48 extern volatile StgWord64 waitForGcThreads_spin;
49 extern volatile StgWord64 waitForGcThreads_yield;
50 #endif
51 
52 // mutable list scavenging statistics
53 #if defined(DEBUG)
54 typedef struct {
55     StgWord n_MUTVAR;
56     StgWord n_MUTARR;
57     StgWord n_MVAR;
58     StgWord n_TVAR;
59     StgWord n_TREC_CHUNK;
60     StgWord n_TVAR_WATCH_QUEUE;
61     StgWord n_TREC_HEADER;
62     StgWord n_OTHERS;
63 } MutListScavStats;
64 
65 extern MutListScavStats mutlist_scav_stats;
66 
67 void zeroMutListScavStats(MutListScavStats *src);
68 void addMutListScavStats(const MutListScavStats *src,
69                          MutListScavStats *dest);
70 #endif /* DEBUG */
71 
72 void gcWorkerThread (Capability *cap);
73 void initGcThreads (uint32_t from, uint32_t to);
74 void freeGcThreads (void);
75 
76 void resizeGenerations (void);
77 
78 #if defined(THREADED_RTS)
79 void waitForGcThreads (Capability *cap, bool idle_cap[]);
80 void releaseGCThreads (Capability *cap, bool idle_cap[]);
81 #endif
82 
83 #define WORK_UNIT_WORDS 128
84 
85 #include "EndPrivate.h"
86