8221812cc895a93096e3901b71c268aa2cad2d7a
[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 #define MWORD_MAX_VALUE ((uint32_t) 0xffffffff)
33 #else
34 typedef guint64 mword;
35 #define MWORD_MAX_VALUE (G_MAXUINT64)
36 #endif
37
38
39 /*
40  * Turning on heavy statistics will turn off the managed allocator and
41  * the managed write barrier.
42  */
43 //#define HEAVY_STATISTICS
44
45 /*
46  * Define this to allow the user to change the nursery size by
47  * specifying its value in the MONO_GC_PARAMS environmental
48  * variable. See mono_gc_base_init for details.
49  */
50 #define USER_CONFIG 1
51
52
53 /*
54  * If this is set, the nursery is aligned to an address aligned to its size, ie.
55  * a 1MB nursery will be aligned to an address divisible by 1MB. This allows us to
56  * speed up ptr_in_nursery () checks which are very frequent. This requires the
57  * nursery size to be a compile time constant.
58  */
59 #define SGEN_ALIGN_NURSERY 1
60
61 /*
62  * The binary protocol enables logging a lot of the GC ativity in a way that is not very
63  * intrusive and produce a compact file that can be searched using a custom tool.
64  *
65  */
66 //#define SGEN_BINARY_PROTOCOL
67
68 /*
69  * Define this and use the "xdomain-checks" MONO_GC_DEBUG option to
70  * have cross-domain checks in the write barrier.
71  */
72 //#define XDOMAIN_CHECKS_IN_WBARRIER
73
74 #ifndef SGEN_BINARY_PROTOCOL
75 #ifndef HEAVY_STATISTICS
76 #define MANAGED_ALLOCATION
77 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
78 #define MANAGED_WBARRIER
79 #endif
80 #endif
81 #endif
82
83 /*
84  * Maximum level of debug to enable on this build.
85  * Making this a constant enables us to put logging in a lot of places and
86  * not pay its cost on release builds.
87  */
88 #define SGEN_MAX_DEBUG_LEVEL 2
89
90 /*
91  * Maximum level of asserts to enable on this build.
92  * FIXME replace all magic numbers with defines.
93  */
94 #define SGEN_MAX_ASSERT_LEVEL 2
95
96
97 #define GC_BITS_PER_WORD (sizeof (mword) * 8)
98
99 /*Size of the section used by the copying GC. */
100 #define SGEN_SIZEOF_GC_MEM_SECTION      ((sizeof (GCMemSection) + 7) & ~7)
101
102 /*
103  * to quickly find the head of an object pinned by a conservative
104  * address we keep track of the objects allocated for each
105  * SGEN_SCAN_START_SIZE memory chunk in the nursery or other memory
106  * sections. Larger values have less memory overhead and bigger
107  * runtime cost. 4-8 KB are reasonable values.
108  */
109 #define SGEN_SCAN_START_SIZE (4096*2)
110
111 /*
112  * Objects bigger then this go into the large object space.  This size
113  * has a few constraints.  It must fit into the major heap, which in
114  * the case of the copying collector means that it must fit into a
115  * pinned chunk.  It must also play well with the GC descriptors, some
116  * of which (DESC_TYPE_RUN_LENGTH, DESC_TYPE_SMALL_BITMAP) encode the
117  * object size.
118  */
119 #define SGEN_MAX_SMALL_OBJ_SIZE 8000
120
121 /*
122  * This is the maximum ammount of memory we're willing to waste in order to speed up allocation.
123  * Wastage comes in thre forms:
124  *
125  * -when building the nursery fragment list, small regions are discarded;
126  * -when allocating memory from a fragment if it ends up below the threshold, we remove it from the fragment list; and
127  * -when allocating a new tlab, we discard the remaining space of the old one
128  *
129  * Increasing this value speeds up allocation but will cause more frequent nursery collections as less space will be used.
130  * Descreasing this value will cause allocation to be slower since we'll have to cycle thru more fragments.
131  * 512 annedoctally keeps wastage under control and doesn't impact allocation performance too much. 
132 */
133 #define SGEN_MAX_NURSERY_WASTE 512
134
135
136 /* This is also the MAJOR_SECTION_SIZE for the copying major
137    collector */
138 #define SGEN_PINNED_CHUNK_SIZE  (128 * 1024)
139
140 /*
141  * Number of entries of a sequential store buffer.
142  * This number represents how frequently we'll have to alloc
143  * a new buffer, so it's a tradeoff of potential wasted space and
144  * increased performance.
145  * 
146  * The current value of 1024 was probably selected because it fits a x86 page.
147  * There's no history on the why's of this value besides this.
148  */
149 #define DEFAULT_REMSET_SIZE 1024
150
151
152 /*
153  * Minimum allowance for nursery allocations, as a multiple of the size of nursery.
154  *
155  * We allow at least this much allocation to happen to the major heap from multiple
156  * minor collections before triggering a major collection.
157  *
158  * Bigger values increases throughput by allowing more garbage to sit in the major heap.
159  * Smaller values leads to better memory effiency but more frequent major collections.
160  */
161 #define SGEN_DEFAULT_ALLOWANCE_NURSERY_SIZE_RATIO 4.0
162
163 #define SGEN_MIN_ALLOWANCE_NURSERY_SIZE_RATIO 1.0
164 #define SGEN_MAX_ALLOWANCE_NURSERY_SIZE_RATIO 10.0
165
166 /*
167  * Default ratio of memory we want to release in a major collection in relation to the the current heap size.
168  *
169  * A major collection target is to free a given amount of memory. This amount is a ratio of the major heap size.
170  *
171  * Values above 0.5 cause the heap to agressively grow when it's small and waste memory when it's big.
172  * Lower values will produce more reasonable sized heaps when it's small, but will be suboptimal at large
173  * sizes as they will use a small fraction only.
174  *
175  */
176 #define SGEN_DEFAULT_SAVE_TARGET_RATIO 0.5
177
178 #define SGEN_MIN_SAVE_TARGET_RATIO 0.1
179 #define SGEN_MAX_SAVE_TARGET_RATIO 2.0
180
181 #endif