2 * sgen-conf.h: Tunable parameters and debugging switches.
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
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;
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.
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.
22 #ifndef __MONO_SGENCONF_H__
23 #define __MONO_SGENCONF_H__
27 /*Basic defines and static tunables */
29 #if SIZEOF_VOID_P == 4
30 typedef guint32 mword;
32 typedef guint64 mword;
37 * Turning on heavy statistics will turn off the managed allocator and
38 * the managed write barrier.
40 // #define HEAVY_STATISTICS
42 #ifdef HEAVY_STATISTICS
43 #define HEAVY_STAT(x) x
49 * Define this to allow the user to change the nursery size by
50 * specifying its value in the MONO_GC_PARAMS environmental
51 * variable. See mono_gc_base_init for details.
57 * If this is set, the nursery is aligned to an address aligned to its size, ie.
58 * a 1MB nursery will be aligned to an address divisible by 1MB. This allows us to
59 * speed up ptr_in_nursery () checks which are very frequent. This requires the
60 * nursery size to be a compile time constant.
62 #define SGEN_ALIGN_NURSERY 1
65 * The binary protocol enables logging a lot of the GC ativity in a way that is not very
66 * intrusive and produces a compact file that can be searched using a custom tool. This
67 * option enables very fine-grained binary protocol events, which will make the GC a tiny
68 * bit less efficient even if no binary protocol file is generated.
70 //#define SGEN_HEAVY_BINARY_PROTOCOL
73 * This enables checks whenever objects are enqueued in gray queues.
74 * Right now the only check done is that we never enqueue nursery
75 * pointers in the concurrent collector.
77 //#define SGEN_CHECK_GRAY_OBJECT_ENQUEUE
80 * This keeps track of where a gray object queue section is and
81 * whether it is where it should be.
83 //#define SGEN_CHECK_GRAY_OBJECT_SECTIONS
86 * Enable this to check every reference update for null references and whether the update is
87 * made in a worker thread. In only a few cases do we potentially update references by
88 * writing nulls, so we assert in all the cases where it's not allowed. The concurrent
89 * collector's worker thread is not allowed to update references at all, so we also assert
90 * that we're not in the worker thread.
92 //#define SGEN_CHECK_UPDATE_REFERENCE
95 * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
96 * have cross-domain checks in the write barrier.
98 //#define XDOMAIN_CHECKS_IN_WBARRIER
101 * Define this to get number of objects marked information in the
102 * concurrent GC DTrace probes. Has a small performance impact, so
103 * it's disabled by default.
105 //#define SGEN_COUNT_NUMBER_OF_MAJOR_OBJECTS_MARKED
108 * Object layout statistics gather a histogram of reference locations
109 * over all scanned objects. We use this information to improve GC
110 * descriptors to speed up scanning. This does not provide any
111 * troubleshooting assistance (unless you are troubled in highly
112 * unusual ways) and makes scanning slower.
114 //#define SGEN_OBJECT_LAYOUT_STATISTICS
116 #ifndef SGEN_HEAVY_BINARY_PROTOCOL
117 #ifndef HEAVY_STATISTICS
118 #define MANAGED_ALLOCATION
119 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
120 #define MANAGED_WBARRIER
126 * Maximum level of debug to enable on this build.
127 * Making this a constant enables us to put logging in a lot of places and
128 * not pay its cost on release builds.
130 #define SGEN_MAX_DEBUG_LEVEL 2
133 * Maximum level of asserts to enable on this build.
134 * FIXME replace all magic numbers with defines.
136 #define SGEN_MAX_ASSERT_LEVEL 5
139 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
141 /*Size of the section used by the copying GC. */
142 #define SGEN_SIZEOF_GC_MEM_SECTION ((sizeof (GCMemSection) + 7) & ~7)
145 * to quickly find the head of an object pinned by a conservative
146 * address we keep track of the objects allocated for each
147 * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
148 * sections. Larger values have less memory overhead and bigger
149 * runtime cost. 4-8 KB are reasonable values.
151 #define SGEN_SCAN_START_SIZE (4096*2)
154 * Objects bigger then this go into the large object space. This size has a few
155 * constraints. At least two of them must fit into a major heap block. It must also play
156 * well with the run length GC descriptor, which encodes the object size.
158 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
161 * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
162 * Wastage comes in thre forms:
164 * -when building the nursery fragment list, small regions are discarded;
165 * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
166 * -when allocating a new tlab, we discard the remaining space of the old one
168 * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
169 * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
170 * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much.
172 #define SGEN_MAX_NURSERY_WASTE 512
176 * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
178 * We allow at least this much allocation to happen to the major heap from multiple
179 * minor collections before triggering a major collection.
181 * Bigger values increases throughput by allowing more garbage to sit in the major heap.
182 * Smaller values leads to better memory effiency but more frequent major collections.
184 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
186 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
187 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
190 * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
192 * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
194 * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
195 * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
196 * sizes as they will use a small fraction only.
199 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
201 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
202 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0
205 * Configurable cementing parameters.
207 * If there are too many pinned nursery objects with many references
208 * from the major heap, the hash table size must be increased.
210 * The threshold is the number of references from the major heap to a
211 * pinned nursery object which triggers cementing: if there are more
212 * than that number of references, the pinned object is cemented until
213 * the next major collection.
215 #define SGEN_CEMENT_HASH_SHIFT 6
216 #define SGEN_CEMENT_HASH_SIZE (1 << SGEN_CEMENT_HASH_SHIFT)
217 #define SGEN_CEMENT_HASH(hv) (((hv) ^ ((hv) >> SGEN_CEMENT_HASH_SHIFT)) & (SGEN_CEMENT_HASH_SIZE - 1))
218 #define SGEN_CEMENT_THRESHOLD 1000