Merge pull request #376 from atomia/master
[mono.git] / mono / metadata / sgen-conf.h
1 /*
2  * Copyright 2001-2003 Ximian, Inc
3  * Copyright 2003-2010 Novell, Inc.
4  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  * 
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef __MONO_SGENCONF_H__
26 #define __MONO_SGENCONF_H__
27
28 /*Basic defines and static tunables */
29
30 #if SIZEOF_VOID_P == 4
31 typedef guint32 mword;
32 #else
33 typedef guint64 mword;
34 #endif
35
36
37 /*
38  * Turning on heavy statistics will turn off the managed allocator and
39  * the managed write barrier.
40  */
41 //#define HEAVY_STATISTICS
42
43 /*
44  * Define this to allow the user to change the nursery size by
45  * specifying its value in the MONO_GC_PARAMS environmental
46  * variable. See mono_gc_base_init for details.
47  */
48 #define USER_CONFIG 1
49
50
51 /*
52  * If this is set, the nursery is aligned to an address aligned to its size, ie.
53  * a 1MB nursery will be aligned to an address divisible by 1MB. This allows us to
54  * speed up ptr_in_nursery () checks which are very frequent. This requires the
55  * nursery size to be a compile time constant.
56  */
57 #define SGEN_ALIGN_NURSERY 1
58
59 /*
60  * The binary protocol enables logging a lot of the GC ativity in a way that is not very
61  * intrusive and produce a compact file that can be searched using a custom tool.
62  *
63  */
64 //#define SGEN_BINARY_PROTOCOL
65
66 /*
67  * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
68  * have cross-domain checks in the write barrier.
69  */
70 //#define XDOMAIN_CHECKS_IN_WBARRIER
71
72 #ifndef SGEN_BINARY_PROTOCOL
73 #ifndef HEAVY_STATISTICS
74 #define MANAGED_ALLOCATION
75 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
76 #define MANAGED_WBARRIER
77 #endif
78 #endif
79 #endif
80
81 /*
82  * Maximum level of debug to enable on this build.
83  * Making this a static variable enables us to put logging in a lot of places.
84  * FIXME decouple logging from assertions
85  */
86 #define SGEN_MAX_DEBUG_LEVEL 2
87
88
89 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
90
91 /*Size of the section used by the copying GC. */
92 #define SGEN_SIZEOF_GC_MEM_SECTION      ((sizeof (GCMemSection) + 7) & ~7)
93
94 /*
95  * to quickly find the head of an object pinned by a conservative
96  * address we keep track of the objects allocated for each
97  * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
98  * sections. Larger values have less memory overhead and bigger
99  * runtime cost. 4-8 KB are reasonable values.
100  */
101 #define SGEN_SCAN_START_SIZE (4096*2)
102
103 /*
104  * Objects bigger then this go into the large object space.  This size
105  * has a few constraints.  It must fit into the major heap, which in
106  * the case of the copying collector means that it must fit into a
107  * pinned chunk.  It must also play well with the GC descriptors, some
108  * of which (DESC_TYPE_RUN_LENGTH, DESC_TYPE_SMALL_BITMAP) encode the
109  * object size.
110  */
111 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
112
113 /*
114  * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
115  * Wastage comes in thre forms:
116  *
117  * -when building the nursery fragment list, small regions are discarded;
118  * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
119  * -when allocating a new tlab, we discard the remaining space of the old one
120  *
121  * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
122  * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
123  * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much. 
124 */
125 #define SGEN_MAX_NURSERY_WASTE 512
126
127
128 /* This is also the MAJOR_SECTION_SIZE for the copying major
129    collector */
130 #define SGEN_PINNED_CHUNK_SIZE  (128 * 1024)
131
132 /*
133  * Number of entries of a sequential store buffer.
134  * This number represents how frequently we'll have to alloc
135  * a new buffer, so it's a tradeoff of potential wasted space and
136  * increased performance.
137  * 
138  * The current value of 1024 was probably selected because it fits a x86 page.
139  * There's no history on the why's of this value besides this.
140  */
141 #define DEFAULT_REMSET_SIZE 1024
142
143
144 /*
145  * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
146  *
147  * We allow at least this much allocation to happen to the major heap from multiple
148  * minor collections before triggering a major collection.
149  *
150  * Bigger values increases throughput by allowing more garbage to sit in the major heap.
151  * Smaller values leads to better memory effiency but more frequent major collections.
152  */
153 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
154
155 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
156 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
157
158 /*
159  * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
160  *
161  * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
162  *
163  * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
164  * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
165  * sizes as they will use a small fraction only.
166  *
167  */
168 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
169
170 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
171 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0
172
173 #endif