[wasm] Implement GC support. Embedder must provide main loop pumping function request...
[mono.git] / mono / sgen / sgen-conf.h
1 /**
2  * \file
3  * Tunable parameters and debugging switches.
4  *
5  * Copyright 2001-2003 Ximian, Inc
6  * Copyright 2003-2010 Novell, Inc.
7  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
8  * Copyright (C) 2012 Xamarin Inc
9  *
10  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12 #ifndef __MONO_SGENCONF_H__
13 #define __MONO_SGENCONF_H__
14
15 #include <glib.h>
16
17 /*Basic defines and static tunables */
18
19 #if SIZEOF_VOID_P == 4
20 typedef guint32 mword;
21 #else
22 typedef guint64 mword;
23 #endif
24
25 typedef mword SgenDescriptor;
26 #define SGEN_DESCRIPTOR_NULL    0
27
28 /*
29  * Turning on heavy statistics will turn off the managed allocator and
30  * the managed write barrier.
31  */
32 // #define HEAVY_STATISTICS
33
34 #ifdef HEAVY_STATISTICS
35 #define HEAVY_STAT(x)   x
36 #else
37 #define HEAVY_STAT(x)
38 #endif
39
40 /*
41  * The binary protocol enables logging a lot of the GC ativity in a way that is not very
42  * intrusive and produces a compact file that can be searched using a custom tool.  This
43  * option enables very fine-grained binary protocol events, which will make the GC a tiny
44  * bit less efficient even if no binary protocol file is generated.
45  */
46 //#define SGEN_HEAVY_BINARY_PROTOCOL
47
48 /*
49  * This extends the heavy binary protocol to record the provenance of an object
50  * for every allocation.
51  */
52 //#define SGEN_OBJECT_PROVENANCE
53
54 /*
55  * This enables checks whenever objects are enqueued in gray queues.
56  * Right now the only check done is that we never enqueue nursery
57  * pointers in the concurrent collector.
58  */
59 //#define SGEN_CHECK_GRAY_OBJECT_ENQUEUE
60
61 /*
62  * This keeps track of where a gray object queue section is and
63  * whether it is where it should be.
64  */
65 //#define SGEN_CHECK_GRAY_OBJECT_SECTIONS
66
67 /*
68  * Enable this to check every reference update for null references and whether the update is
69  * made in a worker thread.  In only a few cases do we potentially update references by
70  * writing nulls, so we assert in all the cases where it's not allowed.  The concurrent
71  * collector's worker thread is not allowed to update references at all, so we also assert
72  * that we're not in the worker thread.
73  */
74 //#define SGEN_CHECK_UPDATE_REFERENCE
75
76 /*
77  * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
78  * have cross-domain checks in the write barrier.
79  */
80 //#define XDOMAIN_CHECKS_IN_WBARRIER
81
82 /*
83  * Define this to get number of objects marked information in the
84  * concurrent GC DTrace probes.  Has a small performance impact, so
85  * it's disabled by default.
86  */
87 //#define SGEN_COUNT_NUMBER_OF_MAJOR_OBJECTS_MARKED
88
89 /*
90  * Object layout statistics gather a histogram of reference locations
91  * over all scanned objects.  We use this information to improve GC
92  * descriptors to speed up scanning.  This does not provide any
93  * troubleshooting assistance (unless you are troubled in highly
94  * unusual ways) and makes scanning slower.
95  */
96 //#define SGEN_OBJECT_LAYOUT_STATISTICS
97
98 #ifndef SGEN_HEAVY_BINARY_PROTOCOL
99 #ifndef HEAVY_STATISTICS
100 #define MANAGED_ALLOCATION
101 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
102 #define MANAGED_WBARRIER
103 #endif
104 #endif
105 #endif
106
107 #if defined (HOST_WASM)
108 #define DEFAULT_MAJOR SGEN_MAJOR_SERIAL
109 #define DEFAULT_SWEEP_MODE SGEN_SWEEP_SERIAL
110 #elif defined(HAVE_CONC_GC_AS_DEFAULT)
111 /* Use concurrent major on deskstop platforms */
112 #define DEFAULT_MAJOR SGEN_MAJOR_CONCURRENT
113 #define DEFAULT_SWEEP_MODE SGEN_SWEEP_CONCURRENT
114 #else
115 #define DEFAULT_MAJOR SGEN_MAJOR_SERIAL
116 #define DEFAULT_SWEEP_MODE SGEN_SWEEP_CONCURRENT
117 #endif
118
119
120
121 /*
122  * Maximum level of debug to enable on this build.
123  * Making this a constant enables us to put logging in a lot of places and
124  * not pay its cost on release builds.
125  */
126 #define SGEN_MAX_DEBUG_LEVEL 2
127
128 /*
129  * Maximum level of asserts to enable on this build.
130  * FIXME replace all magic numbers with defines.
131  */
132 #define SGEN_MAX_ASSERT_LEVEL 5
133
134
135 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
136
137 /*Size of the section used by the copying GC. */
138 #define SGEN_SIZEOF_GC_MEM_SECTION      ((sizeof (GCMemSection) + 7) & ~7)
139
140 /*
141  * to quickly find the head of an object pinned by a conservative
142  * address we keep track of the objects allocated for each
143  * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
144  * sections. Larger values have less memory overhead and bigger
145  * runtime cost. 4-8 KB are reasonable values.
146  */
147 #define SGEN_SCAN_START_SIZE (4096*2)
148
149 /*
150  * Objects bigger then this go into the large object space.  This size has a few
151  * constraints.  At least two of them must fit into a major heap block.  It must also play
152  * well with the run length GC descriptor, which encodes the object size.
153  */
154 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
155
156 /*
157  * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
158  * Wastage comes in thre forms:
159  *
160  * -when building the nursery fragment list, small regions are discarded;
161  * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
162  * -when allocating a new tlab, we discard the remaining space of the old one
163  *
164  * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
165  * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
166  * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much. 
167 */
168 #define SGEN_MAX_NURSERY_WASTE 512
169
170
171 /*
172  * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
173  *
174  * We allow at least this much allocation to happen to the major heap from multiple
175  * minor collections before triggering a major collection.
176  *
177  * Bigger values increases throughput by allowing more garbage to sit in the major heap.
178  * Smaller values leads to better memory effiency but more frequent major collections.
179  */
180 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
181
182 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
183 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
184
185 /*
186  * How much more we allow the heap to grow before triggering another major collection
187  */
188 #define SGEN_DEFAULT_ALLOWANCE_HEAP_SIZE_RATIO 0.33
189
190 /*
191  * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
192  *
193  * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
194  *
195  * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
196  * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
197  * sizes as they will use a small fraction only.
198  *
199  */
200 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
201
202 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
203 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0
204
205 /*
206  * Configurable cementing parameters.
207  *
208  * If there are too many pinned nursery objects with many references
209  * from the major heap, the hash table size must be increased.
210  *
211  * The threshold is the number of references from the major heap to a
212  * pinned nursery object which triggers cementing: if there are more
213  * than that number of references, the pinned object is cemented until
214  * the next major collection.
215  */
216 #define SGEN_CEMENT_HASH_SHIFT  6
217 #define SGEN_CEMENT_HASH_SIZE   (1 << SGEN_CEMENT_HASH_SHIFT)
218 #define SGEN_CEMENT_HASH(hv)    (((hv) ^ ((hv) >> SGEN_CEMENT_HASH_SHIFT)) & (SGEN_CEMENT_HASH_SIZE - 1))
219 #define SGEN_CEMENT_THRESHOLD   1000
220
221 /*
222  * Default values for the nursery size
223  */
224 #define SGEN_DEFAULT_NURSERY_MIN_SIZE   (1 << 19)
225 #define SGEN_DEFAULT_NURSERY_SIZE       (1 << 22)
226 #define SGEN_DEFAULT_NURSERY_MAX_SIZE   (1 << 25)
227
228 /*
229  * We are trying to keep pauses lower than this (ms). We use it for dynamic nursery
230  * sizing heuristics. We are keeping leeway in order to be prepared for work-load
231  * variations.
232  */
233 #define SGEN_DEFAULT_MAX_PAUSE_TIME 30
234 #define SGEN_DEFAULT_MAX_PAUSE_MARGIN 0.66f
235
236
237 #define SGEN_PAUSE_MODE_MAX_PAUSE_MARGIN 0.5f
238
239 /*
240  * In practice, for nurseries smaller than this, the parallel minor tends to be
241  * ineffective, even leading to regressions. Avoid using it for smaller nurseries.
242  */
243 #define SGEN_PARALLEL_MINOR_MIN_NURSERY_SIZE (1 << 24)
244
245 #endif