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;
31 #define MWORD_MAX_VALUE ((uint32_t) 0xffffffff)
33 typedef guint64 mword;
34 #define MWORD_MAX_VALUE (G_MAXUINT64)
39 * Turning on heavy statistics will turn off the managed allocator and
40 * the managed write barrier.
42 // #define HEAVY_STATISTICS
45 * Define this to allow the user to change the nursery size by
46 * specifying its value in the MONO_GC_PARAMS environmental
47 * variable. See mono_gc_base_init for details.
53 * If this is set, the nursery is aligned to an address aligned to its size, ie.
54 * a 1MB nursery will be aligned to an address divisible by 1MB. This allows us to
55 * speed up ptr_in_nursery () checks which are very frequent. This requires the
56 * nursery size to be a compile time constant.
58 #define SGEN_ALIGN_NURSERY 1
61 * The binary protocol enables logging a lot of the GC ativity in a way that is not very
62 * intrusive and produces a compact file that can be searched using a custom tool. This
63 * option enables very fine-grained binary protocol events, which will make the GC a tiny
64 * bit less efficient even if no binary protocol file is generated.
66 //#define SGEN_HEAVY_BINARY_PROTOCOL
69 * This enables checks whenever objects are enqueued in gray queues.
70 * Right now the only check done is that we never enqueue nursery
71 * pointers in the concurrent collector.
73 //#define SGEN_CHECK_GRAY_OBJECT_ENQUEUE
76 * This keeps track of where a gray object queue section is and
77 * whether it is where it should be.
79 //#define SGEN_CHECK_GRAY_OBJECT_SECTIONS
82 * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
83 * have cross-domain checks in the write barrier.
85 //#define XDOMAIN_CHECKS_IN_WBARRIER
88 * Define this to get number of objects marked information in the
89 * concurrent GC DTrace probes. Has a small performance impact, so
90 * it's disabled by default.
92 //#define SGEN_COUNT_NUMBER_OF_MAJOR_OBJECTS_MARKED
95 * Object layout statistics gather a histogram of reference locations
96 * over all scanned objects. We use this information to improve GC
97 * descriptors to speed up scanning. This does not provide any
98 * troubleshooting assistance (unless you are troubled in highly
99 * unusual ways) and makes scanning slower.
101 //#define SGEN_OBJECT_LAYOUT_STATISTICS
103 #ifndef SGEN_HEAVY_BINARY_PROTOCOL
104 #ifndef HEAVY_STATISTICS
105 #define MANAGED_ALLOCATION
106 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
107 #define MANAGED_WBARRIER
113 * Maximum level of debug to enable on this build.
114 * Making this a constant enables us to put logging in a lot of places and
115 * not pay its cost on release builds.
117 #define SGEN_MAX_DEBUG_LEVEL 2
120 * Maximum level of asserts to enable on this build.
121 * FIXME replace all magic numbers with defines.
123 #define SGEN_MAX_ASSERT_LEVEL 5
126 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
128 /*Size of the section used by the copying GC. */
129 #define SGEN_SIZEOF_GC_MEM_SECTION ((sizeof (GCMemSection) + 7) & ~7)
132 * to quickly find the head of an object pinned by a conservative
133 * address we keep track of the objects allocated for each
134 * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
135 * sections. Larger values have less memory overhead and bigger
136 * runtime cost. 4-8 KB are reasonable values.
138 #define SGEN_SCAN_START_SIZE (4096*2)
141 * Objects bigger then this go into the large object space. This size
142 * has a few constraints. It must fit into the major heap, which in
143 * the case of the copying collector means that it must fit into a
144 * pinned chunk. It must also play well with the GC descriptors, some
145 * of which (DESC_TYPE_RUN_LENGTH, DESC_TYPE_SMALL_BITMAP) encode the
148 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
151 * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
152 * Wastage comes in thre forms:
154 * -when building the nursery fragment list, small regions are discarded;
155 * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
156 * -when allocating a new tlab, we discard the remaining space of the old one
158 * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
159 * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
160 * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much.
162 #define SGEN_MAX_NURSERY_WASTE 512
166 * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
168 * We allow at least this much allocation to happen to the major heap from multiple
169 * minor collections before triggering a major collection.
171 * Bigger values increases throughput by allowing more garbage to sit in the major heap.
172 * Smaller values leads to better memory effiency but more frequent major collections.
174 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
176 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
177 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
180 * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
182 * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
184 * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
185 * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
186 * sizes as they will use a small fraction only.
189 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
191 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
192 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0
195 * Configurable cementing parameters.
197 * The hash table size should be a prime. If there are too many
198 * pinned nursery objects with many references from the major heap,
199 * this number must be increased.
201 * The threshold is the number of references from the major heap to a
202 * pinned nursery object which triggers cementing: if there are more
203 * than that number of references, the pinned object is cemented until
204 * the next major collection.
206 #define SGEN_CEMENT_HASH_SIZE 61
207 #define SGEN_CEMENT_THRESHOLD 1000