Rewrite of core coder & decoder functions to fix several bugs and limitations, and...
[mono.git] / mono / metadata / sgen-gc.h
1 /*
2  * sgen-gc.c: Simple generational GC.
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_SGENGC_H__
23 #define __MONO_SGENGC_H__
24
25 /* pthread impl */
26 #include "config.h"
27
28 #ifdef HAVE_SGEN_GC
29
30 typedef struct _SgenThreadInfo SgenThreadInfo;
31 #define THREAD_INFO_TYPE SgenThreadInfo
32
33 #include <glib.h>
34 #ifdef HAVE_PTHREAD_H
35 #include <pthread.h>
36 #endif
37 #include <signal.h>
38 #include <mono/utils/mono-compiler.h>
39 #include <mono/utils/mono-threads.h>
40 #include <mono/utils/dtrace.h>
41 #include <mono/utils/mono-logger-internal.h>
42 #include <mono/utils/atomic.h>
43 #include <mono/io-layer/mono-mutex.h>
44 #include <mono/metadata/class-internals.h>
45 #include <mono/metadata/object-internals.h>
46 #include <mono/metadata/sgen-conf.h>
47 #include <mono/metadata/sgen-archdep.h>
48 #include <mono/metadata/sgen-descriptor.h>
49 #include <mono/metadata/sgen-gray.h>
50 #include <mono/metadata/sgen-hash-table.h>
51
52 /* The method used to clear the nursery */
53 /* Clearing at nursery collections is the safest, but has bad interactions with caches.
54  * Clearing at TLAB creation is much faster, but more complex and it might expose hard
55  * to find bugs.
56  */
57 typedef enum {
58         CLEAR_AT_GC,
59         CLEAR_AT_TLAB_CREATION
60 } NurseryClearPolicy;
61
62 NurseryClearPolicy sgen_get_nursery_clear_policy (void) MONO_INTERNAL;
63
64 #define SGEN_TV_DECLARE(name) gint64 name
65 #define SGEN_TV_GETTIME(tv) tv = mono_100ns_ticks ()
66 #define SGEN_TV_ELAPSED(start,end) (int)((end-start) / 10)
67 #define SGEN_TV_ELAPSED_MS(start,end) ((SGEN_TV_ELAPSED((start),(end)) + 500) / 1000)
68
69 /* eventually share with MonoThread? */
70 /*
71  * This structure extends the MonoThreadInfo structure.
72  */
73 struct _SgenThreadInfo {
74         MonoThreadInfo info;
75         int skip;
76         volatile int in_critical_region;
77         gboolean joined_stw;
78         gboolean doing_handshake;
79         gboolean thread_is_dying;
80         gboolean gc_disabled;
81         void *stack_end;
82         void *stack_start;
83         void *stack_start_limit;
84         char **tlab_next_addr;
85         char **tlab_start_addr;
86         char **tlab_temp_end_addr;
87         char **tlab_real_end_addr;
88         gpointer runtime_data;
89
90         /* Only used on POSIX platforms */
91         int signal;
92         /* Ditto */
93         unsigned int stop_count; /* to catch duplicate signals */
94
95         gpointer stopped_ip;    /* only valid if the thread is stopped */
96         MonoDomain *stopped_domain; /* ditto */
97
98 #ifdef USE_MONO_CTX
99         MonoContext ctx;                /* ditto */
100 #else
101         gpointer regs[ARCH_NUM_REGS];       /* ditto */
102 #endif
103
104 #ifndef HAVE_KW_THREAD
105         char *tlab_start;
106         char *tlab_next;
107         char *tlab_temp_end;
108         char *tlab_real_end;
109 #endif
110 };
111
112 /*
113  * The nursery section uses this struct.
114  */
115 typedef struct _GCMemSection GCMemSection;
116 struct _GCMemSection {
117         char *data;
118         mword size;
119         /* pointer where more data could be allocated if it fits */
120         char *next_data;
121         char *end_data;
122         /*
123          * scan starts is an array of pointers to objects equally spaced in the allocation area
124          * They let use quickly find pinned objects from pinning pointers.
125          */
126         char **scan_starts;
127         /* in major collections indexes in the pin_queue for objects that pin this section */
128         void **pin_queue_start;
129         int pin_queue_num_entries;
130         unsigned short num_scan_start;
131 };
132
133 /*
134  * Recursion is not allowed for the thread lock.
135  */
136 #define LOCK_DECLARE(name) mono_mutex_t name
137 /* if changing LOCK_INIT to something that isn't idempotent, look at
138    its use in mono_gc_base_init in sgen-gc.c */
139 #define LOCK_INIT(name) mono_mutex_init (&(name), NULL)
140 #define LOCK_GC do {                                            \
141                 mono_mutex_lock (&gc_mutex);                    \
142                 MONO_GC_LOCKED ();                              \
143         } while (0)
144 #define TRYLOCK_GC (mono_mutex_trylock (&gc_mutex) == 0)
145 #define UNLOCK_GC do {                                          \
146                 mono_mutex_unlock (&gc_mutex);                  \
147                 MONO_GC_UNLOCKED ();                            \
148         } while (0)
149
150 extern LOCK_DECLARE (sgen_interruption_mutex);
151
152 #define LOCK_INTERRUPTION mono_mutex_lock (&sgen_interruption_mutex)
153 #define UNLOCK_INTERRUPTION mono_mutex_unlock (&sgen_interruption_mutex)
154
155 /* FIXME: Use InterlockedAdd & InterlockedAdd64 to reduce the CAS cost. */
156 #define SGEN_CAS_PTR    InterlockedCompareExchangePointer
157 #define SGEN_ATOMIC_ADD(x,i)    do {                                    \
158                 int __old_x;                                            \
159                 do {                                                    \
160                         __old_x = (x);                                  \
161                 } while (InterlockedCompareExchange (&(x), __old_x + (i), __old_x) != __old_x); \
162         } while (0)
163 #define SGEN_ATOMIC_ADD_P(x,i) do { \
164                 size_t __old_x;                                            \
165                 do {                                                    \
166                         __old_x = (x);                                  \
167                 } while (InterlockedCompareExchangePointer ((void**)&(x), (void*)(__old_x + (i)), (void*)__old_x) != (void*)__old_x); \
168         } while (0)
169
170
171 #ifndef HOST_WIN32
172 /* we intercept pthread_create calls to know which threads exist */
173 #define USE_PTHREAD_INTERCEPT 1
174 #endif
175
176 #ifdef HEAVY_STATISTICS
177 #define HEAVY_STAT(x)   x
178
179 extern long long stat_objects_alloced_degraded;
180 extern long long stat_bytes_alloced_degraded;
181 extern long long stat_copy_object_called_major;
182 extern long long stat_objects_copied_major;
183 #else
184 #define HEAVY_STAT(x)
185 #endif
186
187 #define SGEN_ASSERT(level, a, ...) do { \
188         if (G_UNLIKELY ((level) <= SGEN_MAX_ASSERT_LEVEL && !(a))) {    \
189                 g_error (__VA_ARGS__);  \
190 } } while (0)
191
192
193 #define SGEN_LOG(level, format, ...) do {      \
194         if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {        \
195                 mono_gc_printf (gc_debug_file, format, ##__VA_ARGS__);  \
196 } } while (0)
197
198 #define SGEN_COND_LOG(level, cond, format, ...) do {    \
199         if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {        \
200                 if (cond)       \
201                         mono_gc_printf (gc_debug_file, format, ##__VA_ARGS__);  \
202 } } while (0)
203
204 #define SGEN_LOG_DO(level, fun) do {    \
205         if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {        \
206                 fun;    \
207 } } while (0)
208
209 extern int gc_debug_level;
210 extern FILE* gc_debug_file;
211
212 extern int current_collection_generation;
213
214 extern unsigned int sgen_global_stop_count;
215
216 extern gboolean bridge_processing_in_progress;
217
218 extern int num_ready_finalizers;
219
220 #define SGEN_ALLOC_ALIGN                8
221 #define SGEN_ALLOC_ALIGN_BITS   3
222
223 #define SGEN_ALIGN_UP(s)                (((s)+(SGEN_ALLOC_ALIGN-1)) & ~(SGEN_ALLOC_ALIGN-1))
224
225 /*
226  * The link pointer is hidden by negating each bit.  We use the lowest
227  * bit of the link (before negation) to store whether it needs
228  * resurrection tracking.
229  */
230 #define HIDE_POINTER(p,t)       ((gpointer)(~((gulong)(p)|((t)?1:0))))
231 #define REVEAL_POINTER(p)       ((gpointer)((~(gulong)(p))&~3L))
232
233 #ifdef SGEN_ALIGN_NURSERY
234 #define SGEN_PTR_IN_NURSERY(p,bits,start,end)   (((mword)(p) & ~((1 << (bits)) - 1)) == (mword)(start))
235 #else
236 #define SGEN_PTR_IN_NURSERY(p,bits,start,end)   ((char*)(p) >= (start) && (char*)(p) < (end))
237 #endif
238
239 #ifdef USER_CONFIG
240
241 /* good sizes are 512KB-1MB: larger ones increase a lot memzeroing time */
242 #define DEFAULT_NURSERY_SIZE (sgen_nursery_size)
243 extern int sgen_nursery_size MONO_INTERNAL;
244 #ifdef SGEN_ALIGN_NURSERY
245 /* The number of trailing 0 bits in DEFAULT_NURSERY_SIZE */
246 #define DEFAULT_NURSERY_BITS (sgen_nursery_bits)
247 extern int sgen_nursery_bits MONO_INTERNAL;
248 #endif
249
250 #else
251
252 #define DEFAULT_NURSERY_SIZE (4*1024*1024)
253 #ifdef SGEN_ALIGN_NURSERY
254 #define DEFAULT_NURSERY_BITS 22
255 #endif
256
257 #endif
258
259 #ifndef SGEN_ALIGN_NURSERY
260 #define DEFAULT_NURSERY_BITS -1
261 #endif
262
263 extern char *sgen_nursery_start MONO_INTERNAL;
264 extern char *sgen_nursery_end MONO_INTERNAL;
265
266 static inline gboolean
267 sgen_ptr_in_nursery (void *p)
268 {
269         return SGEN_PTR_IN_NURSERY ((p), DEFAULT_NURSERY_BITS, sgen_nursery_start, sgen_nursery_end);
270 }
271
272 static inline char*
273 sgen_get_nursery_start (void)
274 {
275         return sgen_nursery_start;
276 }
277
278 static inline char*
279 sgen_get_nursery_end (void)
280 {
281         return sgen_nursery_end;
282 }
283
284 /* Structure that corresponds to a MonoVTable: desc is a mword so requires
285  * no cast from a pointer to an integer
286  */
287 typedef struct {
288         MonoClass *klass;
289         mword desc;
290 } GCVTable;
291
292 /* these bits are set in the object vtable: we could merge them since an object can be
293  * either pinned or forwarded but not both.
294  * We store them in the vtable slot because the bits are used in the sync block for
295  * other purposes: if we merge them and alloc the sync blocks aligned to 8 bytes, we can change
296  * this and use bit 3 in the syncblock (with the lower two bits both set for forwarded, that
297  * would be an invalid combination for the monitor and hash code).
298  * The values are already shifted.
299  * The forwarding address is stored in the sync block.
300  */
301 #define SGEN_FORWARDED_BIT 1
302 #define SGEN_PINNED_BIT 2
303 #define SGEN_VTABLE_BITS_MASK 0x3
304
305 /* returns NULL if not forwarded, or the forwarded address */
306 #define SGEN_OBJECT_IS_FORWARDED(obj) (((mword*)(obj))[0] & SGEN_FORWARDED_BIT ? (void*)(((mword*)(obj))[0] & ~SGEN_VTABLE_BITS_MASK) : NULL)
307 #define SGEN_OBJECT_IS_PINNED(obj) (((mword*)(obj))[0] & SGEN_PINNED_BIT)
308
309 /* set the forwarded address fw_addr for object obj */
310 #define SGEN_FORWARD_OBJECT(obj,fw_addr) do {                           \
311                 ((mword*)(obj))[0] = (mword)(fw_addr) | SGEN_FORWARDED_BIT; \
312         } while (0)
313 #define SGEN_PIN_OBJECT(obj) do {       \
314                 ((mword*)(obj))[0] |= SGEN_PINNED_BIT;  \
315         } while (0)
316 #define SGEN_UNPIN_OBJECT(obj) do {     \
317                 ((mword*)(obj))[0] &= ~SGEN_PINNED_BIT; \
318         } while (0)
319
320 /*
321  * Since we set bits in the vtable, use the macro to load it from the pointer to
322  * an object that is potentially pinned.
323  */
324 #define SGEN_LOAD_VTABLE(addr) ((*(mword*)(addr)) & ~SGEN_VTABLE_BITS_MASK)
325
326 #if defined(SGEN_GRAY_OBJECT_ENQUEUE) || SGEN_MAX_DEBUG_LEVEL >= 9
327 #define GRAY_OBJECT_ENQUEUE sgen_gray_object_enqueue
328 #define GRAY_OBJECT_DEQUEUE(queue,o) ((o) = sgen_gray_object_dequeue ((queue)))
329 #else
330 #define GRAY_OBJECT_ENQUEUE(queue,o) do {                               \
331                 if (G_UNLIKELY (!(queue)->first || (queue)->first->end == SGEN_GRAY_QUEUE_SECTION_SIZE)) \
332                         sgen_gray_object_enqueue ((queue), (o));        \
333                 else                                                    \
334                         (queue)->first->objects [(queue)->first->end++] = (o); \
335                 PREFETCH ((o));                                         \
336         } while (0)
337 #define GRAY_OBJECT_DEQUEUE(queue,o) do {                               \
338                 if (!(queue)->first)                                    \
339                         (o) = NULL;                                     \
340                 else if (G_UNLIKELY ((queue)->first->end == 1))         \
341                         (o) = sgen_gray_object_dequeue ((queue));               \
342                 else                                                    \
343                         (o) = (queue)->first->objects [--(queue)->first->end]; \
344         } while (0)
345 #endif
346
347 /*
348 List of what each bit on of the vtable gc bits means. 
349 */
350 enum {
351         SGEN_GC_BIT_BRIDGE_OBJECT = 1,
352 };
353
354 /* the runtime can register areas of memory as roots: we keep two lists of roots,
355  * a pinned root set for conservatively scanned roots and a normal one for
356  * precisely scanned roots (currently implemented as a single list).
357  */
358 typedef struct _RootRecord RootRecord;
359 struct _RootRecord {
360         char *end_root;
361         mword root_desc;
362 };
363
364 enum {
365         ROOT_TYPE_NORMAL = 0, /* "normal" roots */
366         ROOT_TYPE_PINNED = 1, /* roots without a GC descriptor */
367         ROOT_TYPE_WBARRIER = 2, /* roots with a write barrier */
368         ROOT_TYPE_NUM
369 };
370
371 extern SgenHashTable roots_hash [ROOT_TYPE_NUM];
372
373 typedef void (*IterateObjectCallbackFunc) (char*, size_t, void*);
374
375 int sgen_thread_handshake (BOOL suspend) MONO_INTERNAL;
376 gboolean sgen_suspend_thread (SgenThreadInfo *info) MONO_INTERNAL;
377 gboolean sgen_resume_thread (SgenThreadInfo *info) MONO_INTERNAL;
378 void sgen_wait_for_suspend_ack (int count) MONO_INTERNAL;
379 gboolean sgen_park_current_thread_if_doing_handshake (SgenThreadInfo *p) MONO_INTERNAL;
380 void sgen_os_init (void) MONO_INTERNAL;
381
382 gboolean sgen_is_worker_thread (MonoNativeThreadId thread) MONO_INTERNAL;
383
384 void sgen_update_heap_boundaries (mword low, mword high) MONO_INTERNAL;
385
386 void sgen_scan_area_with_callback (char *start, char *end, IterateObjectCallbackFunc callback, void *data, gboolean allow_flags) MONO_INTERNAL;
387 void sgen_check_section_scan_starts (GCMemSection *section) MONO_INTERNAL;
388
389 /* Keep in sync with description_for_type() in sgen-internal.c! */
390 enum {
391         INTERNAL_MEM_PIN_QUEUE,
392         INTERNAL_MEM_FRAGMENT,
393         INTERNAL_MEM_SECTION,
394         INTERNAL_MEM_SCAN_STARTS,
395         INTERNAL_MEM_FIN_TABLE,
396         INTERNAL_MEM_FINALIZE_ENTRY,
397         INTERNAL_MEM_FINALIZE_READY_ENTRY,
398         INTERNAL_MEM_DISLINK_TABLE,
399         INTERNAL_MEM_DISLINK,
400         INTERNAL_MEM_ROOTS_TABLE,
401         INTERNAL_MEM_ROOT_RECORD,
402         INTERNAL_MEM_STATISTICS,
403         INTERNAL_MEM_STAT_PINNED_CLASS,
404         INTERNAL_MEM_STAT_REMSET_CLASS,
405         INTERNAL_MEM_GRAY_QUEUE,
406         INTERNAL_MEM_MS_TABLES,
407         INTERNAL_MEM_MS_BLOCK_INFO,
408         INTERNAL_MEM_MS_BLOCK_INFO_SORT,
409         INTERNAL_MEM_EPHEMERON_LINK,
410         INTERNAL_MEM_WORKER_DATA,
411         INTERNAL_MEM_WORKER_JOB_DATA,
412         INTERNAL_MEM_BRIDGE_DATA,
413         INTERNAL_MEM_BRIDGE_HASH_TABLE,
414         INTERNAL_MEM_BRIDGE_HASH_TABLE_ENTRY,
415         INTERNAL_MEM_BRIDGE_ALIVE_HASH_TABLE,
416         INTERNAL_MEM_BRIDGE_ALIVE_HASH_TABLE_ENTRY,
417         INTERNAL_MEM_JOB_QUEUE_ENTRY,
418         INTERNAL_MEM_TOGGLEREF_DATA,
419         INTERNAL_MEM_CARDTABLE_MOD_UNION,
420         INTERNAL_MEM_MAX
421 };
422
423 enum {
424         GENERATION_NURSERY,
425         GENERATION_OLD,
426         GENERATION_MAX
427 };
428
429 #ifdef SGEN_BINARY_PROTOCOL
430 #define BINARY_PROTOCOL_ARG(x)  ,x
431 #else
432 #define BINARY_PROTOCOL_ARG(x)
433 #endif
434
435 void sgen_init_internal_allocator (void) MONO_INTERNAL;
436
437 typedef struct _ObjectList ObjectList;
438 struct _ObjectList {
439         MonoObject *obj;
440         ObjectList *next;
441 };
442
443 typedef void (*CopyOrMarkObjectFunc) (void**, SgenGrayQueue*);
444 typedef void (*ScanObjectFunc) (char*, SgenGrayQueue*);
445 typedef void (*ScanVTypeFunc) (char*, mword desc, SgenGrayQueue* BINARY_PROTOCOL_ARG (size_t size));
446
447 typedef struct
448 {
449         ScanObjectFunc scan_func;
450         CopyOrMarkObjectFunc copy_func;
451         SgenGrayQueue *queue;
452 } ScanCopyContext;
453
454 void sgen_report_internal_mem_usage (void) MONO_INTERNAL;
455 void sgen_dump_internal_mem_usage (FILE *heap_dump_file) MONO_INTERNAL;
456 void sgen_dump_section (GCMemSection *section, const char *type) MONO_INTERNAL;
457 void sgen_dump_occupied (char *start, char *end, char *section_start) MONO_INTERNAL;
458
459 void sgen_register_moved_object (void *obj, void *destination) MONO_INTERNAL;
460
461 void sgen_register_fixed_internal_mem_type (int type, size_t size) MONO_INTERNAL;
462
463 void* sgen_alloc_internal (int type) MONO_INTERNAL;
464 void sgen_free_internal (void *addr, int type) MONO_INTERNAL;
465
466 void* sgen_alloc_internal_dynamic (size_t size, int type, gboolean assert_on_failure) MONO_INTERNAL;
467 void sgen_free_internal_dynamic (void *addr, size_t size, int type) MONO_INTERNAL;
468
469 void** sgen_find_optimized_pin_queue_area (void *start, void *end, int *num) MONO_INTERNAL;
470 void sgen_find_section_pin_queue_start_end (GCMemSection *section) MONO_INTERNAL;
471 void sgen_pin_objects_in_section (GCMemSection *section, ScanCopyContext ctx) MONO_INTERNAL;
472
473 void sgen_pin_stats_register_object (char *obj, size_t size);
474 void sgen_pin_stats_register_global_remset (char *obj);
475 void sgen_pin_stats_print_class_stats (void);
476
477 void sgen_sort_addresses (void **array, int size) MONO_INTERNAL;
478 void sgen_add_to_global_remset (gpointer ptr, gpointer obj) MONO_INTERNAL;
479
480 int sgen_get_current_collection_generation (void) MONO_INTERNAL;
481 gboolean sgen_collection_is_parallel (void) MONO_INTERNAL;
482 gboolean sgen_collection_is_concurrent (void) MONO_INTERNAL;
483 gboolean sgen_concurrent_collection_in_progress (void) MONO_INTERNAL;
484
485 typedef struct {
486         CopyOrMarkObjectFunc copy_or_mark_object;
487         ScanObjectFunc scan_object;
488         ScanVTypeFunc scan_vtype;
489         /*FIXME add allocation function? */
490 } SgenObjectOperations;
491
492 SgenObjectOperations *sgen_get_current_object_ops (void) MONO_INTERNAL;
493
494 typedef struct _SgenFragment SgenFragment;
495
496 struct _SgenFragment {
497         SgenFragment *next;
498         char *fragment_start;
499         char *fragment_next; /* the current soft limit for allocation */
500         char *fragment_end;
501         SgenFragment *next_in_order; /* We use a different entry for all active fragments so we can avoid SMR. */
502 };
503
504 typedef struct {
505         SgenFragment *alloc_head; /* List head to be used when allocating memory. Walk with fragment_next. */
506         SgenFragment *region_head; /* List head of the region used by this allocator. Walk with next_in_order. */
507 } SgenFragmentAllocator;
508
509 void sgen_fragment_allocator_add (SgenFragmentAllocator *allocator, char *start, char *end) MONO_INTERNAL;
510 void sgen_fragment_allocator_release (SgenFragmentAllocator *allocator) MONO_INTERNAL;
511 void* sgen_fragment_allocator_serial_alloc (SgenFragmentAllocator *allocator, size_t size) MONO_INTERNAL;
512 void* sgen_fragment_allocator_par_alloc (SgenFragmentAllocator *allocator, size_t size) MONO_INTERNAL;
513 void* sgen_fragment_allocator_serial_range_alloc (SgenFragmentAllocator *allocator, size_t desired_size, size_t minimum_size, size_t *out_alloc_size) MONO_INTERNAL;
514 void* sgen_fragment_allocator_par_range_alloc (SgenFragmentAllocator *allocator, size_t desired_size, size_t minimum_size, size_t *out_alloc_size) MONO_INTERNAL;
515 SgenFragment* sgen_fragment_allocator_alloc (void) MONO_INTERNAL;
516 void sgen_clear_allocator_fragments (SgenFragmentAllocator *allocator) MONO_INTERNAL;
517 void sgen_clear_range (char *start, char *end) MONO_INTERNAL;
518
519
520 /*
521 This is a space/speed compromise as we need to make sure the from/to space check is both O(1)
522 and only hit cache hot memory. On a 4Mb nursery it requires 1024 bytes, or 3% of your average
523 L1 cache. On small configs with a 512kb nursery, this goes to 0.4%.
524
525 Experimental results on how much space we waste with a 4Mb nursery:
526
527 Note that the wastage applies to the half nursery, or 2Mb:
528
529 Test 1 (compiling corlib):
530 9: avg: 3.1k
531 8: avg: 1.6k
532
533 */
534 #define SGEN_TO_SPACE_GRANULE_BITS 9
535 #define SGEN_TO_SPACE_GRANULE_IN_BYTES (1 << SGEN_TO_SPACE_GRANULE_BITS)
536
537 extern char *sgen_space_bitmap MONO_INTERNAL;
538 extern int sgen_space_bitmap_size MONO_INTERNAL;
539
540 static inline gboolean
541 sgen_nursery_is_to_space (char *object)
542 {
543         int idx = (object - sgen_nursery_start) >> SGEN_TO_SPACE_GRANULE_BITS;
544         int byte = idx / 8;
545         int bit = idx & 0x7;
546
547         SGEN_ASSERT (4, sgen_ptr_in_nursery (object), "object %p is not in nursery [%p - %p]", object, sgen_get_nursery_start (), sgen_get_nursery_end ());
548         SGEN_ASSERT (4, byte < sgen_space_bitmap_size, "byte index %d out of range", byte, sgen_space_bitmap_size);
549
550         return (sgen_space_bitmap [byte] & (1 << bit)) != 0;
551 }
552
553 static inline gboolean
554 sgen_nursery_is_from_space (char *object)
555 {
556         return !sgen_nursery_is_to_space (object);
557 }
558
559 static inline gboolean
560 sgen_nursery_is_object_alive (char *obj)
561 {
562         /* FIXME put this asserts under a non default level */
563         g_assert (sgen_ptr_in_nursery (obj));
564
565         if (sgen_nursery_is_to_space (obj))
566                 return TRUE;
567
568         if (SGEN_OBJECT_IS_PINNED (obj) || SGEN_OBJECT_IS_FORWARDED (obj))
569                 return TRUE;
570
571         return FALSE;
572 }
573
574 typedef struct {
575         gboolean is_split;
576
577         char* (*alloc_for_promotion) (MonoVTable *vtable, char *obj, size_t objsize, gboolean has_references);
578         char* (*par_alloc_for_promotion) (MonoVTable *vtable, char *obj, size_t objsize, gboolean has_references);
579
580         SgenObjectOperations serial_ops;
581         SgenObjectOperations parallel_ops;
582
583         void (*prepare_to_space) (char *to_space_bitmap, int space_bitmap_size);
584         void (*clear_fragments) (void);
585         SgenFragment* (*build_fragments_get_exclude_head) (void);
586         void (*build_fragments_release_exclude_head) (void);
587         void (*build_fragments_finish) (SgenFragmentAllocator *allocator);
588         void (*init_nursery) (SgenFragmentAllocator *allocator, char *start, char *end);
589
590         gboolean (*handle_gc_param) (const char *opt); /* Optional */
591         void (*print_gc_param_usage) (void); /* Optional */
592 } SgenMinorCollector;
593
594 extern SgenMinorCollector sgen_minor_collector;
595
596 void sgen_simple_nursery_init (SgenMinorCollector *collector) MONO_INTERNAL;
597 void sgen_split_nursery_init (SgenMinorCollector *collector) MONO_INTERNAL;
598
599 typedef void (*sgen_cardtable_block_callback) (mword start, mword size);
600 void sgen_major_collector_iterate_live_block_ranges (sgen_cardtable_block_callback callback) MONO_INTERNAL;
601
602 typedef struct _SgenMajorCollector SgenMajorCollector;
603 struct _SgenMajorCollector {
604         size_t section_size;
605         gboolean is_parallel;
606         gboolean is_concurrent;
607         gboolean supports_cardtable;
608         gboolean sweeps_lazily;
609
610         /*
611          * This is set to TRUE if the sweep for the last major
612          * collection has been completed.
613          */
614         gboolean *have_swept;
615         /*
616          * This is set to TRUE by the sweep if the next major
617          * collection should be synchronous (for evacuation).  For
618          * non-concurrent collectors, this should be NULL.
619          */
620         gboolean *want_synchronous_collection;
621
622         void* (*alloc_heap) (mword nursery_size, mword nursery_align, int nursery_bits);
623         gboolean (*is_object_live) (char *obj);
624         void* (*alloc_small_pinned_obj) (MonoVTable *vtable, size_t size, gboolean has_references);
625         void* (*alloc_degraded) (MonoVTable *vtable, size_t size);
626
627         SgenObjectOperations major_ops;
628         SgenObjectOperations major_concurrent_ops;
629
630         void* (*alloc_object) (MonoVTable *vtable, int size, gboolean has_references);
631         void* (*par_alloc_object) (MonoVTable *vtable, int size, gboolean has_references);
632         void (*free_pinned_object) (char *obj, size_t size);
633         void (*iterate_objects) (gboolean non_pinned, gboolean pinned, IterateObjectCallbackFunc callback, void *data);
634         void (*free_non_pinned_object) (char *obj, size_t size);
635         void (*find_pin_queue_start_ends) (SgenGrayQueue *queue);
636         void (*pin_objects) (SgenGrayQueue *queue);
637         void (*pin_major_object) (char *obj, SgenGrayQueue *queue);
638         void (*scan_card_table) (gboolean mod_union, SgenGrayQueue *queue);
639         void (*iterate_live_block_ranges) (sgen_cardtable_block_callback callback);
640         void (*update_cardtable_mod_union) (void);
641         void (*init_to_space) (void);
642         void (*sweep) (void);
643         void (*check_scan_starts) (void);
644         void (*dump_heap) (FILE *heap_dump_file);
645         gint64 (*get_used_size) (void);
646         void (*start_nursery_collection) (void);
647         void (*finish_nursery_collection) (void);
648         void (*start_major_collection) (void);
649         void (*finish_major_collection) (void);
650         void (*have_computed_minor_collection_allowance) (void);
651         gboolean (*ptr_is_in_non_pinned_space) (char *ptr, char **start);
652         gboolean (*obj_is_from_pinned_alloc) (char *obj);
653         void (*report_pinned_memory_usage) (void);
654         int (*get_num_major_sections) (void);
655         gboolean (*handle_gc_param) (const char *opt);
656         void (*print_gc_param_usage) (void);
657         gboolean (*is_worker_thread) (MonoNativeThreadId thread);
658         void (*post_param_init) (SgenMajorCollector *collector);
659         void* (*alloc_worker_data) (void);
660         void (*init_worker_thread) (void *data);
661         void (*reset_worker_data) (void *data);
662         gboolean (*is_valid_object) (char *object);
663         gboolean (*describe_pointer) (char *pointer);
664         guint8* (*get_cardtable_mod_union_for_object) (char *object);
665         long long (*get_and_reset_num_major_objects_marked) (void);
666 };
667
668 extern SgenMajorCollector major_collector;
669
670 void sgen_marksweep_init (SgenMajorCollector *collector) MONO_INTERNAL;
671 void sgen_marksweep_fixed_init (SgenMajorCollector *collector) MONO_INTERNAL;
672 void sgen_marksweep_par_init (SgenMajorCollector *collector) MONO_INTERNAL;
673 void sgen_marksweep_fixed_par_init (SgenMajorCollector *collector) MONO_INTERNAL;
674 void sgen_marksweep_conc_init (SgenMajorCollector *collector) MONO_INTERNAL;
675 SgenMajorCollector* sgen_get_major_collector (void) MONO_INTERNAL;
676
677
678 typedef struct {
679         void (*wbarrier_set_field) (MonoObject *obj, gpointer field_ptr, MonoObject* value);
680         void (*wbarrier_set_arrayref) (MonoArray *arr, gpointer slot_ptr, MonoObject* value);
681         void (*wbarrier_arrayref_copy) (gpointer dest_ptr, gpointer src_ptr, int count);
682         void (*wbarrier_value_copy) (gpointer dest, gpointer src, int count, MonoClass *klass);
683         void (*wbarrier_object_copy) (MonoObject* obj, MonoObject *src);
684         void (*wbarrier_generic_nostore) (gpointer ptr);
685         void (*record_pointer) (gpointer ptr);
686
687         void (*finish_scan_remsets) (void *start_nursery, void *end_nursery, SgenGrayQueue *queue);
688
689         void (*prepare_for_major_collection) (void);
690
691         void (*finish_minor_collection) (void);
692         gboolean (*find_address) (char *addr);
693         gboolean (*find_address_with_cards) (char *cards_start, guint8 *cards, char *addr);
694 } SgenRemeberedSet;
695
696 SgenRemeberedSet *sgen_get_remset (void) MONO_INTERNAL;
697
698 static guint /*__attribute__((noinline)) not sure if this hint is a good idea*/
699 slow_object_get_size (MonoVTable *vtable, MonoObject* o)
700 {
701         MonoClass *klass = vtable->klass;
702
703         /*
704          * We depend on mono_string_length_fast and
705          * mono_array_length_fast not using the object's vtable.
706          */
707         if (klass == mono_defaults.string_class) {
708                 return sizeof (MonoString) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
709         } else if (klass->rank) {
710                 MonoArray *array = (MonoArray*)o;
711                 size_t size = sizeof (MonoArray) + klass->sizes.element_size * mono_array_length_fast (array);
712                 if (G_UNLIKELY (array->bounds)) {
713                         size += sizeof (mono_array_size_t) - 1;
714                         size &= ~(sizeof (mono_array_size_t) - 1);
715                         size += sizeof (MonoArrayBounds) * klass->rank;
716                 }
717                 return size;
718         } else {
719                 /* from a created object: the class must be inited already */
720                 return klass->instance_size;
721         }
722 }
723
724 /*
725  * This function can be called on an object whose first word, the
726  * vtable field, is not intact.  This is necessary for the parallel
727  * collector.
728  */
729 static inline guint
730 sgen_par_object_get_size (MonoVTable *vtable, MonoObject* o)
731 {
732         mword descr = (mword)vtable->gc_descr;
733         mword type = descr & 0x7;
734
735         if (type == DESC_TYPE_RUN_LENGTH || type == DESC_TYPE_SMALL_BITMAP) {
736                 mword size = descr & 0xfff8;
737                 if (size == 0) /* This is used to encode a string */
738                         return sizeof (MonoString) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
739                 return size;
740         } else if (type == DESC_TYPE_VECTOR) {
741                 int element_size = ((descr) >> VECTOR_ELSIZE_SHIFT) & MAX_ELEMENT_SIZE;
742                 MonoArray *array = (MonoArray*)o;
743                 size_t size = sizeof (MonoArray) + element_size * mono_array_length_fast (array);
744
745                 if (descr & VECTOR_KIND_ARRAY) {
746                         size += sizeof (mono_array_size_t) - 1;
747                         size &= ~(sizeof (mono_array_size_t) - 1);
748                         size += sizeof (MonoArrayBounds) * vtable->klass->rank;
749                 }
750                 return size;
751         }
752
753         return slow_object_get_size (vtable, o);
754 }
755
756 static inline guint
757 sgen_safe_object_get_size (MonoObject *obj)
758 {
759        char *forwarded;
760
761        if ((forwarded = SGEN_OBJECT_IS_FORWARDED (obj)))
762                obj = (MonoObject*)forwarded;
763
764        return sgen_par_object_get_size ((MonoVTable*)SGEN_LOAD_VTABLE (obj), obj);
765 }
766
767 const char* sgen_safe_name (void* obj) MONO_INTERNAL;
768
769 gboolean sgen_object_is_live (void *obj) MONO_INTERNAL;
770
771 gboolean sgen_need_bridge_processing (void) MONO_INTERNAL;
772 void sgen_bridge_reset_data (void) MONO_INTERNAL;
773 void sgen_bridge_processing_stw_step (void) MONO_INTERNAL;
774 void sgen_bridge_processing_finish (int generation) MONO_INTERNAL;
775 void sgen_register_test_bridge_callbacks (const char *bridge_class_name) MONO_INTERNAL;
776 gboolean sgen_is_bridge_object (MonoObject *obj) MONO_INTERNAL;
777 gboolean sgen_is_bridge_class (MonoClass *class) MONO_INTERNAL;
778 void sgen_mark_bridge_object (MonoObject *obj) MONO_INTERNAL;
779 void sgen_bridge_register_finalized_object (MonoObject *object) MONO_INTERNAL;
780
781 void sgen_scan_togglerefs (char *start, char *end, ScanCopyContext ctx) MONO_INTERNAL;
782 void sgen_process_togglerefs (void) MONO_INTERNAL;
783
784 typedef mono_bool (*WeakLinkAlivePredicateFunc) (MonoObject*, void*);
785
786 void sgen_null_links_with_predicate (int generation, WeakLinkAlivePredicateFunc predicate, void *data) MONO_INTERNAL;
787
788 gboolean sgen_gc_is_object_ready_for_finalization (void *object) MONO_INTERNAL;
789 void sgen_gc_lock (void) MONO_INTERNAL;
790 void sgen_gc_unlock (void) MONO_INTERNAL;
791 void sgen_gc_event_moves (void) MONO_INTERNAL;
792
793 void sgen_queue_finalization_entry (MonoObject *obj) MONO_INTERNAL;
794 const char* sgen_generation_name (int generation) MONO_INTERNAL;
795
796 void sgen_collect_bridge_objects (int generation, ScanCopyContext ctx) MONO_INTERNAL;
797 void sgen_finalize_in_range (int generation, ScanCopyContext ctx) MONO_INTERNAL;
798 void sgen_null_link_in_range (int generation, gboolean before_finalization, ScanCopyContext ctx) MONO_INTERNAL;
799 void sgen_null_links_for_domain (MonoDomain *domain, int generation) MONO_INTERNAL;
800 void sgen_remove_finalizers_for_domain (MonoDomain *domain, int generation) MONO_INTERNAL;
801 void sgen_process_fin_stage_entries (void) MONO_INTERNAL;
802 void sgen_process_dislink_stage_entries (void) MONO_INTERNAL;
803 void sgen_register_disappearing_link (MonoObject *obj, void **link, gboolean track, gboolean in_gc) MONO_INTERNAL;
804
805 gboolean sgen_drain_gray_stack (int max_objs, ScanCopyContext ctx) MONO_INTERNAL;
806
807 enum {
808         SPACE_NURSERY,
809         SPACE_MAJOR,
810         SPACE_LOS
811 };
812
813 void sgen_pin_object (void *object, SgenGrayQueue *queue) MONO_INTERNAL;
814 void sgen_parallel_pin_or_update (void **ptr, void *obj, MonoVTable *vt, SgenGrayQueue *queue) MONO_INTERNAL;
815 void sgen_set_pinned_from_failed_allocation (mword objsize) MONO_INTERNAL;
816
817 void sgen_ensure_free_space (size_t size) MONO_INTERNAL;
818 void sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean wait_to_finish) MONO_INTERNAL;
819 gboolean sgen_has_critical_method (void) MONO_INTERNAL;
820 gboolean sgen_is_critical_method (MonoMethod *method) MONO_INTERNAL;
821
822 /* STW */
823
824 typedef struct {
825         int generation;
826         const char *reason;
827         gboolean is_overflow;
828         SGEN_TV_DECLARE (total_time);
829         SGEN_TV_DECLARE (stw_time);
830         SGEN_TV_DECLARE (bridge_time);
831 } GGTimingInfo;
832
833 int sgen_stop_world (int generation) MONO_INTERNAL;
834 int sgen_restart_world (int generation, GGTimingInfo *timing) MONO_INTERNAL;
835
836 /* LOS */
837
838 typedef struct _LOSObject LOSObject;
839 struct _LOSObject {
840         LOSObject *next;
841         mword size; /* this is the object size, lowest bit used for pin/mark */
842         guint8 *cardtable_mod_union; /* only used by the concurrent collector */
843 #if SIZEOF_VOID_P < 8
844         mword dummy;            /* to align object to sizeof (double) */
845 #endif
846         char data [MONO_ZERO_LEN_ARRAY];
847 };
848
849 #define ARRAY_OBJ_INDEX(ptr,array,elem_size) (((char*)(ptr) - ((char*)(array) + G_STRUCT_OFFSET (MonoArray, vector))) / (elem_size))
850
851 extern LOSObject *los_object_list;
852 extern mword los_memory_usage;
853
854 void sgen_los_free_object (LOSObject *obj) MONO_INTERNAL;
855 void* sgen_los_alloc_large_inner (MonoVTable *vtable, size_t size) MONO_INTERNAL;
856 void sgen_los_sweep (void) MONO_INTERNAL;
857 gboolean sgen_ptr_is_in_los (char *ptr, char **start) MONO_INTERNAL;
858 void sgen_los_iterate_objects (IterateObjectCallbackFunc cb, void *user_data) MONO_INTERNAL;
859 void sgen_los_iterate_live_block_ranges (sgen_cardtable_block_callback callback) MONO_INTERNAL;
860 void sgen_los_scan_card_table (gboolean mod_union, SgenGrayQueue *queue) MONO_INTERNAL;
861 void sgen_los_update_cardtable_mod_union (void) MONO_INTERNAL;
862 void sgen_major_collector_scan_card_table (SgenGrayQueue *queue) MONO_INTERNAL;
863 gboolean sgen_los_is_valid_object (char *object) MONO_INTERNAL;
864 gboolean mono_sgen_los_describe_pointer (char *ptr) MONO_INTERNAL;
865 LOSObject* sgen_los_header_for_object (char *data) MONO_INTERNAL;
866 mword sgen_los_object_size (LOSObject *obj) MONO_INTERNAL;
867 void sgen_los_pin_object (char *obj) MONO_INTERNAL;
868 void sgen_los_unpin_object (char *obj) MONO_INTERNAL;
869 gboolean sgen_los_object_is_pinned (char *obj) MONO_INTERNAL;
870
871
872 /* nursery allocator */
873
874 void sgen_clear_nursery_fragments (void) MONO_INTERNAL;
875 void sgen_nursery_allocator_prepare_for_pinning (void) MONO_INTERNAL;
876 void sgen_nursery_allocator_set_nursery_bounds (char *nursery_start, char *nursery_end) MONO_INTERNAL;
877 mword sgen_build_nursery_fragments (GCMemSection *nursery_section, void **start, int num_entries, SgenGrayQueue *unpin_queue) MONO_INTERNAL;
878 void sgen_init_nursery_allocator (void) MONO_INTERNAL;
879 void sgen_nursery_allocator_init_heavy_stats (void) MONO_INTERNAL;
880 void sgen_alloc_init_heavy_stats (void) MONO_INTERNAL;
881 char* sgen_nursery_alloc_get_upper_alloc_bound (void) MONO_INTERNAL;
882 void* sgen_nursery_alloc (size_t size) MONO_INTERNAL;
883 void* sgen_nursery_alloc_range (size_t size, size_t min_size, size_t *out_alloc_size) MONO_INTERNAL;
884 MonoVTable* sgen_get_array_fill_vtable (void) MONO_INTERNAL;
885 gboolean sgen_can_alloc_size (size_t size) MONO_INTERNAL;
886 void sgen_nursery_retire_region (void *address, ptrdiff_t size) MONO_INTERNAL;
887
888 void sgen_nursery_alloc_prepare_for_minor (void) MONO_INTERNAL;
889 void sgen_nursery_alloc_prepare_for_major (void) MONO_INTERNAL;
890
891 char* sgen_alloc_for_promotion (char *obj, size_t objsize, gboolean has_references) MONO_INTERNAL;
892 char* sgen_par_alloc_for_promotion (char *obj, size_t objsize, gboolean has_references) MONO_INTERNAL;
893
894 /* TLS Data */
895
896 extern MonoNativeTlsKey thread_info_key;
897
898 #ifdef HAVE_KW_THREAD
899 extern __thread SgenThreadInfo *sgen_thread_info;
900 extern __thread char *stack_end;
901 #endif
902
903 #ifdef HAVE_KW_THREAD
904 #define TLAB_ACCESS_INIT
905 #define IN_CRITICAL_REGION sgen_thread_info->in_critical_region
906 #else
907 #define TLAB_ACCESS_INIT        SgenThreadInfo *__thread_info__ = mono_native_tls_get_value (thread_info_key)
908 #define IN_CRITICAL_REGION (__thread_info__->in_critical_region)
909 #endif
910
911 #ifndef DISABLE_CRITICAL_REGION
912
913 #ifdef HAVE_KW_THREAD
914 #define IN_CRITICAL_REGION sgen_thread_info->in_critical_region
915 #else
916 #define IN_CRITICAL_REGION (__thread_info__->in_critical_region)
917 #endif
918
919 /* Enter must be visible before anything is done in the critical region. */
920 #define ENTER_CRITICAL_REGION do { mono_atomic_store_acquire (&IN_CRITICAL_REGION, 1); } while (0)
921
922 /* Exit must make sure all critical regions stores are visible before it signal the end of the region. 
923  * We don't need to emit a full barrier since we
924  */
925 #define EXIT_CRITICAL_REGION  do { mono_atomic_store_release (&IN_CRITICAL_REGION, 0); } while (0)
926
927 #endif
928
929 #ifdef HAVE_KW_THREAD
930 #define EMIT_TLS_ACCESS(mb,dummy,offset)        do {    \
931         mono_mb_emit_byte ((mb), MONO_CUSTOM_PREFIX);   \
932         mono_mb_emit_byte ((mb), CEE_MONO_TLS);         \
933         mono_mb_emit_i4 ((mb), (offset));               \
934         } while (0)
935 #else
936
937 /* 
938  * CEE_MONO_TLS requires the tls offset, not the key, so the code below only works on darwin,
939  * where the two are the same.
940  */
941 #if defined(__APPLE__) || defined (HOST_WIN32)
942 #define EMIT_TLS_ACCESS(mb,member,dummy)        do {    \
943         mono_mb_emit_byte ((mb), MONO_CUSTOM_PREFIX);   \
944         mono_mb_emit_byte ((mb), CEE_MONO_TLS);         \
945         mono_mb_emit_i4 ((mb), thread_info_key);        \
946         mono_mb_emit_icon ((mb), G_STRUCT_OFFSET (SgenThreadInfo, member));     \
947         mono_mb_emit_byte ((mb), CEE_ADD);              \
948         mono_mb_emit_byte ((mb), CEE_LDIND_I);          \
949         } while (0)
950 #else
951 #define EMIT_TLS_ACCESS(mb,member,dummy)        do { g_error ("sgen is not supported when using --with-tls=pthread.\n"); } while (0)
952 #endif
953
954 #endif
955
956 /* Other globals */
957
958 extern GCMemSection *nursery_section;
959 extern int stat_major_gcs;
960 extern guint32 collect_before_allocs;
961 extern guint32 verify_before_allocs;
962 extern gboolean has_per_allocation_action;
963 extern int degraded_mode;
964 extern int default_nursery_size;
965 extern guint32 tlab_size;
966 extern NurseryClearPolicy nursery_clear_policy;
967
968 extern LOCK_DECLARE (gc_mutex);
969
970 extern int do_pin_stats;
971
972 /* Nursery helpers. */
973
974 static inline void
975 sgen_set_nursery_scan_start (char *p)
976 {
977         int idx = (p - (char*)nursery_section->data) / SGEN_SCAN_START_SIZE;
978         char *old = nursery_section->scan_starts [idx];
979         if (!old || old > p)
980                 nursery_section->scan_starts [idx] = p;
981 }
982
983
984 /* Object Allocation */
985
986 typedef enum {
987         ATYPE_NORMAL,
988         ATYPE_VECTOR,
989         ATYPE_SMALL,
990         ATYPE_NUM
991 } SgenAllocatorType;
992
993 void sgen_init_tlab_info (SgenThreadInfo* info);
994 void sgen_clear_tlabs (void);
995 void sgen_set_use_managed_allocator (gboolean flag);
996 gboolean sgen_is_managed_allocator (MonoMethod *method);
997 gboolean sgen_has_managed_allocator (void);
998
999 /* Debug support */
1000
1001 void sgen_check_consistency (void);
1002 void sgen_check_mod_union_consistency (void);
1003 void sgen_check_major_refs (void);
1004 void sgen_check_whole_heap (gboolean allow_missing_pinning);
1005 void sgen_check_whole_heap_stw (void) MONO_INTERNAL;
1006 void sgen_check_objref (char *obj);
1007 void sgen_check_major_heap_marked (void) MONO_INTERNAL;
1008 void sgen_check_nursery_objects_pinned (gboolean pinned) MONO_INTERNAL;
1009
1010 /* Write barrier support */
1011
1012 /*
1013  * This causes the compile to extend the liveness of 'v' till the call to dummy_use
1014  */
1015 static inline void
1016 sgen_dummy_use (gpointer v) {
1017 #if defined(__GNUC__)
1018         __asm__ volatile ("" : "=r"(v) : "r"(v));
1019 #elif defined(_MSC_VER)
1020         __asm {
1021                 mov eax, v;
1022                 and eax, eax;
1023         };
1024 #else
1025 #error "Implement sgen_dummy_use for your compiler"
1026 #endif
1027 }
1028
1029 /* Environment variable parsing */
1030
1031 #define MONO_GC_PARAMS_NAME     "MONO_GC_PARAMS"
1032 #define MONO_GC_DEBUG_NAME      "MONO_GC_DEBUG"
1033
1034 gboolean sgen_parse_environment_string_extract_number (const char *str, glong *out) MONO_INTERNAL;
1035 void sgen_env_var_error (const char *env_var, const char *fallback, const char *description_format, ...) MONO_INTERNAL;
1036
1037 #endif /* HAVE_SGEN_GC */
1038
1039 #endif /* __MONO_SGENGC_H__ */