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