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