This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mono / metadata / gc.c
1 /*
2  * metadata/gc.c: GC icalls.
3  *
4  * Author: Paolo Molaro <lupus@ximian.com>
5  *
6  * (C) 2002 Ximian, Inc.
7  */
8
9 #include <config.h>
10 #include <glib.h>
11 #include <string.h>
12
13 #include <mono/metadata/gc-internal.h>
14 #include <mono/metadata/threads.h>
15 #include <mono/metadata/tabledefs.h>
16 #include <mono/metadata/exception.h>
17 #include <mono/metadata/domain-internals.h>
18 #include <mono/metadata/class-internals.h>
19 #include <mono/utils/mono-logger.h>
20 #define GC_I_HIDE_POINTERS
21 #include <mono/os/gc_wrapper.h>
22
23 #ifndef HIDE_POINTER
24 #define HIDE_POINTER(v)         (v)
25 #define REVEAL_POINTER(v)       (v)
26 #endif
27
28 typedef struct DomainFinalizationReq {
29         MonoDomain *domain;
30         HANDLE done_event;
31 } DomainFinalizationReq;
32
33 #ifdef PLATFORM_WINCE /* FIXME: add accessors to gc.dll API */
34 extern void (*__imp_GC_finalizer_notifier)(void);
35 #define GC_finalizer_notifier __imp_GC_finalizer_notifier
36 extern int __imp_GC_finalize_on_demand;
37 #define GC_finalize_on_demand __imp_GC_finalize_on_demand
38 #endif
39
40 static int finalize_slot = -1;
41
42 static gboolean gc_disabled = FALSE;
43
44 static CRITICAL_SECTION finalizer_mutex;
45
46 static GSList *domains_to_finalize= NULL;
47
48 static MonoThread *gc_thread;
49
50 static void object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*));
51
52 #if HAVE_BOEHM_GC
53 static void finalize_notify (void);
54 static HANDLE pending_done_event;
55 static HANDLE shutdown_event;
56 static HANDLE thread_started_event;
57 #endif
58
59 /* 
60  * actually, we might want to queue the finalize requests in a separate thread,
61  * but we need to be careful about the execution domain of the thread...
62  */
63 static void
64 run_finalize (void *obj, void *data)
65 {
66         MonoObject *exc = NULL;
67         MonoObject *o, *o2;
68         o = (MonoObject*)((char*)obj + GPOINTER_TO_UINT (data));
69
70         if (finalize_slot < 0) {
71                 int i;
72                 MonoClass* obj_class = mono_get_object_class ();
73                 for (i = 0; i < obj_class->vtable_size; ++i) {
74                         MonoMethod *cm = obj_class->vtable [i];
75                
76                         if (!strcmp (mono_method_get_name (cm), "Finalize")) {
77                                 finalize_slot = i;
78                                 break;
79                         }
80                 }
81         }
82
83         mono_domain_lock (o->vtable->domain);
84
85         o2 = g_hash_table_lookup (o->vtable->domain->finalizable_objects_hash, o);
86
87         mono_domain_unlock (o->vtable->domain);
88
89         if (!o2)
90                 /* Already finalized somehow */
91                 return;
92
93         /* make sure the finalizer is not called again if the object is resurrected */
94         object_register_finalizer (obj, NULL);
95
96         if (o->vtable->klass == mono_get_thread_class ())
97                 if (mono_gc_is_finalizer_thread ((MonoThread*)o))
98                         /* Avoid finalizing ourselves */
99                         return;
100
101         /* speedup later... and use a timeout */
102         /* g_print ("Finalize run on %p %s.%s\n", o, mono_object_class (o)->name_space, mono_object_class (o)->name); */
103
104         /* Use _internal here, since this thread can enter a doomed appdomain */
105         mono_domain_set_internal (mono_object_domain (o));              
106
107         mono_runtime_invoke (o->vtable->klass->vtable [finalize_slot], o, NULL, &exc);
108
109         if (exc) {
110                 /* fixme: do something useful */
111         }
112 }
113
114 /*
115  * Some of our objects may point to a different address than the address returned by GC_malloc()
116  * (because of the GetHashCode hack), but we need to pass the real address to register_finalizer.
117  * This also means that in the callback we need to adjust the pointer to get back the real
118  * MonoObject*.
119  * We also need to be consistent in the use of the GC_debug* variants of malloc and register_finalizer, 
120  * since that, too, can cause the underlying pointer to be offset.
121  */
122 static void
123 object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*))
124 {
125 #if HAVE_BOEHM_GC
126         guint offset = 0;
127
128 #ifndef GC_DEBUG
129         /* This assertion is not valid when GC_DEBUG is defined */
130         g_assert (GC_base (obj) == (char*)obj - offset);
131 #endif
132
133         if (mono_domain_is_unloading (obj->vtable->domain) && (callback != NULL))
134                 /*
135                  * Can't register finalizers in a dying appdomain, since they
136                  * could be invoked after the appdomain has been unloaded.
137                  */
138                 return;
139
140         mono_domain_lock (obj->vtable->domain);
141
142         if (callback)
143                 g_hash_table_insert (obj->vtable->domain->finalizable_objects_hash, obj,
144                                                          obj);
145         else
146                 g_hash_table_remove (obj->vtable->domain->finalizable_objects_hash, obj);
147
148         mono_domain_unlock (obj->vtable->domain);
149
150         GC_REGISTER_FINALIZER_NO_ORDER ((char*)obj - offset, callback, GUINT_TO_POINTER (offset), NULL, NULL);
151 #endif
152 }
153
154 void
155 mono_object_register_finalizer (MonoObject *obj)
156 {
157         /* g_print ("Registered finalizer on %p %s.%s\n", obj, mono_object_class (obj)->name_space, mono_object_class (obj)->name); */
158         object_register_finalizer (obj, run_finalize);
159 }
160
161 /*
162  * mono_domain_finalize:
163  *
164  *  Request finalization of all finalizable objects inside @domain. Wait
165  * @timeout msecs for the finalization to complete.
166  * Returns: TRUE if succeeded, FALSE if there was a timeout
167  */
168
169 gboolean
170 mono_domain_finalize (MonoDomain *domain, guint32 timeout) 
171 {
172         DomainFinalizationReq *req;
173         guint32 res;
174         HANDLE done_event;
175
176         /* 
177          * No need to create another thread 'cause the finalizer thread
178          * is still working and will take care of running the finalizers
179          */ 
180         
181 #if HAVE_BOEHM_GC
182         if (gc_disabled)
183                 return TRUE;
184
185         GC_gcollect ();
186
187         done_event = CreateEvent (NULL, TRUE, FALSE, NULL);
188
189         req = g_new0 (DomainFinalizationReq, 1);
190         req->domain = domain;
191         req->done_event = done_event;
192         
193         EnterCriticalSection (&finalizer_mutex);
194
195         domains_to_finalize = g_slist_append (domains_to_finalize, req);
196
197         LeaveCriticalSection (&finalizer_mutex);
198
199         /* Tell the finalizer thread to finalize this appdomain */
200         finalize_notify ();
201
202         res = WaitForSingleObjectEx (done_event, timeout, TRUE);
203
204         /* printf ("WAIT RES: %d.\n", res); */
205         if (res == WAIT_TIMEOUT) {
206                 /* We leak the handle here */
207                 return FALSE;
208         }
209
210         CloseHandle (done_event);
211         return TRUE;
212 #else
213         /* We don't support domain finalization without a GC */
214         return FALSE;
215 #endif
216 }
217
218 void
219 ves_icall_System_GC_InternalCollect (int generation)
220 {
221         MONO_ARCH_SAVE_REGS;
222
223 #if HAVE_BOEHM_GC
224         GC_gcollect ();
225 #endif
226 }
227
228 gint64
229 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection)
230 {
231         MONO_ARCH_SAVE_REGS;
232
233 #if HAVE_BOEHM_GC
234         if (forceCollection)
235                 GC_gcollect ();
236         return GC_get_heap_size () - GC_get_free_bytes ();
237 #else
238         return 0;
239 #endif
240 }
241
242 void
243 ves_icall_System_GC_KeepAlive (MonoObject *obj)
244 {
245         MONO_ARCH_SAVE_REGS;
246
247         /*
248          * Does nothing.
249          */
250 }
251
252 void
253 ves_icall_System_GC_ReRegisterForFinalize (MonoObject *obj)
254 {
255         MONO_ARCH_SAVE_REGS;
256
257         object_register_finalizer (obj, run_finalize);
258 }
259
260 void
261 ves_icall_System_GC_SuppressFinalize (MonoObject *obj)
262 {
263         MONO_ARCH_SAVE_REGS;
264
265         object_register_finalizer (obj, NULL);
266 }
267
268 void
269 ves_icall_System_GC_WaitForPendingFinalizers (void)
270 {
271         MONO_ARCH_SAVE_REGS;
272         
273 #if HAVE_BOEHM_GC
274         if (!GC_should_invoke_finalizers ())
275                 return;
276
277         if (mono_thread_current () == gc_thread)
278                 /* Avoid deadlocks */
279                 return;
280
281         ResetEvent (pending_done_event);
282         finalize_notify ();
283         /* g_print ("Waiting for pending finalizers....\n"); */
284         WaitForSingleObjectEx (pending_done_event, INFINITE, TRUE);
285         /* g_print ("Done pending....\n"); */
286 #else
287 #endif
288 }
289
290 static CRITICAL_SECTION allocator_section;
291 static CRITICAL_SECTION handle_section;
292 static guint32 next_handle = 0;
293 static gpointer *gc_handles = NULL;
294 static guint8 *gc_handle_types = NULL;
295 static guint32 array_size = 0;
296
297 /*
298  * The handle type is encoded in the lower two bits of the handle value:
299  * 0 -> normal
300  * 1 -> pinned
301  * 2 -> weak
302  */
303
304 typedef enum {
305         HANDLE_WEAK,
306         HANDLE_WEAK_TRACK,
307         HANDLE_NORMAL,
308         HANDLE_PINNED
309 } HandleType;
310
311 /*
312  * FIXME: make thread safe and reuse the array entries.
313  */
314 MonoObject *
315 ves_icall_System_GCHandle_GetTarget (guint32 handle)
316 {
317         MonoObject *obj;
318         gint32 type;
319
320         MONO_ARCH_SAVE_REGS;
321
322         if (gc_handles) {
323                 type = handle & 0x3;
324                 EnterCriticalSection (&handle_section);
325                 g_assert (type == gc_handle_types [handle >> 2]);
326                 obj = gc_handles [handle >> 2];
327                 LeaveCriticalSection (&handle_section);
328                 if (!obj)
329                         return NULL;
330
331                 if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK))
332                         return REVEAL_POINTER (obj);
333                 else
334                         return obj;
335         }
336         return NULL;
337 }
338
339 guint32
340 ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type)
341 {
342         gpointer val = obj;
343         guint32 h, idx;
344
345         MONO_ARCH_SAVE_REGS;
346
347         EnterCriticalSection (&handle_section);
348         /* Indexes start from 1 since 0 means the handle is not allocated */
349         idx = ++next_handle;
350         if (idx >= array_size) {
351                 gpointer *new_array;
352                 guint8 *new_type_array;
353                 if (!array_size)
354                         array_size = 16;
355 #if HAVE_BOEHM_GC
356                 new_array = GC_MALLOC (sizeof (gpointer) * (array_size * 2));
357                 new_type_array = GC_MALLOC (sizeof (guint8) * (array_size * 2));
358 #else
359                 new_array = g_malloc0 (sizeof (gpointer) * (array_size * 2));
360                 new_type_array = g_malloc0 (sizeof (guint8) * (array_size * 2));
361 #endif
362                 if (gc_handles) {
363                         int i;
364                         memcpy (new_array, gc_handles, sizeof (gpointer) * array_size);
365                         memcpy (new_type_array, gc_handle_types, sizeof (guint8) * array_size);
366                         /* need to re-register links for weak refs. test if GC_realloc needs the same */
367                         for (i = 0; i < array_size; ++i) {
368 #if 0 /* This breaks the threaded finalizer, by causing segfaults deep
369        * inside libgc.  I assume it will also break without the
370        * threaded finalizer, just that the stress test (bug 31333)
371        * deadlocks too early without it.  Reverting to the previous
372        * version here stops the segfault.
373        */
374                                 if ((gc_handle_types[i] == HANDLE_WEAK) || (gc_handle_types[i] == HANDLE_WEAK_TRACK)) { /* all and only disguised pointers have it set */
375 #else
376                                 if (((gulong)new_array [i]) & 0x1) {
377 #endif
378 #if HAVE_BOEHM_GC
379                                         if (gc_handles [i] != (gpointer)-1)
380                                                 GC_unregister_disappearing_link (&(gc_handles [i]));
381                                         if (new_array [i] != (gpointer)-1)
382                                                 GC_GENERAL_REGISTER_DISAPPEARING_LINK (&(new_array [i]), REVEAL_POINTER (new_array [i]));
383 #endif
384                                 }
385                         }
386                 }
387                 array_size *= 2;
388 #ifndef HAVE_BOEHM_GC
389                 g_free (gc_handles);
390                 g_free (gc_handle_types);
391 #endif
392                 gc_handles = new_array;
393                 gc_handle_types = new_type_array;
394         }
395
396         /* resuse the type from the old target */
397         if (type == -1)
398                 type =  handle & 0x3;
399         h = (idx << 2) | type;
400         switch (type) {
401         case HANDLE_WEAK:
402         case HANDLE_WEAK_TRACK:
403                 val = (gpointer)HIDE_POINTER (val);
404                 gc_handles [idx] = val;
405                 gc_handle_types [idx] = type;
406 #if HAVE_BOEHM_GC
407                 if (gc_handles [idx] != (gpointer)-1)
408                         GC_GENERAL_REGISTER_DISAPPEARING_LINK (&(gc_handles [idx]), obj);
409 #endif
410                 break;
411         default:
412                 gc_handles [idx] = val;
413                 gc_handle_types [idx] = type;
414                 break;
415         }
416         LeaveCriticalSection (&handle_section);
417         return h;
418 }
419
420 void
421 ves_icall_System_GCHandle_FreeHandle (guint32 handle)
422 {
423         int idx = handle >> 2;
424         int type = handle & 0x3;
425
426         MONO_ARCH_SAVE_REGS;
427
428         EnterCriticalSection (&handle_section);
429
430 #ifdef HAVE_BOEHM_GC
431         g_assert (type == gc_handle_types [idx]);
432         if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK)) {
433                 if (gc_handles [idx] != (gpointer)-1)
434                         GC_unregister_disappearing_link (&(gc_handles [idx]));
435         }
436 #endif
437
438         gc_handles [idx] = (gpointer)-1;
439         gc_handle_types [idx] = (guint8)-1;
440         LeaveCriticalSection (&handle_section);
441 }
442
443 gpointer
444 ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle)
445 {
446         MonoObject *obj;
447         int type = handle & 0x3;
448
449         MONO_ARCH_SAVE_REGS;
450
451         if (gc_handles) {
452                 EnterCriticalSection (&handle_section);
453                 obj = gc_handles [handle >> 2];
454                 g_assert (gc_handle_types [handle >> 2] == type);
455                 LeaveCriticalSection (&handle_section);
456                 if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK)) {
457                         obj = REVEAL_POINTER (obj);
458                         if (obj == (MonoObject *) -1)
459                                 return NULL;
460                 }
461                 if (obj) {
462                         MonoClass *klass = mono_object_class (obj);
463                         if (klass == mono_defaults.string_class) {
464                                 return mono_string_chars ((MonoString*)obj);
465                         } else if (klass->rank) {
466                                 return mono_array_addr ((MonoArray*)obj, char, 0);
467                         } else {
468                                 /* the C# code will check and throw the exception */
469                                 /* FIXME: missing !klass->blittable test, see bug #61134,
470                                  * disabled in 1.0 untill the blittable-using code is audited.
471                                 if ((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_AUTO_LAYOUT)
472                                         return (gpointer)-1; */
473                                 return (char*)obj + sizeof (MonoObject);
474                         }
475                 }
476         }
477         return NULL;
478 }
479
480 guint32
481 mono_gchandle_new (MonoObject *obj, gboolean pinned)
482 {
483         return ves_icall_System_GCHandle_GetTargetHandle (obj, 0, pinned? HANDLE_PINNED: HANDLE_NORMAL);
484 }
485
486 guint32
487 mono_gchandle_new_weakref (MonoObject *obj, gboolean track_resurrection)
488 {
489         return ves_icall_System_GCHandle_GetTargetHandle (obj, 0, track_resurrection? HANDLE_WEAK_TRACK: HANDLE_WEAK);
490 }
491
492 /* This will return NULL for a collected object if using a weakref handle */
493 MonoObject*
494 mono_gchandle_get_target (guint32 gchandle)
495 {
496         return ves_icall_System_GCHandle_GetTarget (gchandle);
497 }
498
499 void
500 mono_gchandle_free (guint32 gchandle)
501 {
502         ves_icall_System_GCHandle_FreeHandle (gchandle);
503 }
504
505 #if HAVE_BOEHM_GC
506
507 static HANDLE finalizer_event;
508 static volatile gboolean finished=FALSE;
509
510 static void finalize_notify (void)
511 {
512 #ifdef DEBUG
513         g_message (G_GNUC_PRETTY_FUNCTION ": prodding finalizer");
514 #endif
515
516         SetEvent (finalizer_event);
517 }
518
519 static void
520 collect_objects (gpointer key, gpointer value, gpointer user_data)
521 {
522         GPtrArray *arr = (GPtrArray*)user_data;
523         g_ptr_array_add (arr, key);
524 }
525
526 /*
527  * finalize_domain_objects:
528  *
529  *  Run the finalizers of all finalizable objects in req->domain.
530  */
531 static void
532 finalize_domain_objects (DomainFinalizationReq *req)
533 {
534         int i;
535         GPtrArray *objs;
536         MonoDomain *domain = req->domain;
537         
538         while (g_hash_table_size (domain->finalizable_objects_hash) > 0) {
539                 /* 
540                  * Since the domain is unloading, nobody is allowed to put
541                  * new entries into the hash table. But finalize_object might
542                  * remove entries from the hash table, so we make a copy.
543                  */
544                 objs = g_ptr_array_new ();
545                 g_hash_table_foreach (domain->finalizable_objects_hash, 
546                                                           collect_objects, objs);
547                 /* printf ("FINALIZING %d OBJECTS.\n", objs->len); */
548
549                 for (i = 0; i < objs->len; ++i) {
550                         MonoObject *o = (MonoObject*)g_ptr_array_index (objs, i);
551                         /* FIXME: Avoid finalizing threads, etc */
552                         run_finalize (o, 0);
553                 }
554
555                 g_ptr_array_free (objs, TRUE);
556         }
557
558         /* printf ("DONE.\n"); */
559         SetEvent (req->done_event);
560
561         /* The event is closed in mono_domain_finalize if we get here */
562         g_free (req);
563 }
564
565 static guint32 finalizer_thread (gpointer unused)
566 {
567         gc_thread = mono_thread_current ();
568
569         SetEvent (thread_started_event);
570
571         while(!finished) {
572                 /* Wait to be notified that there's at least one
573                  * finaliser to run
574                  */
575                 WaitForSingleObjectEx (finalizer_event, INFINITE, TRUE);
576
577                 if (domains_to_finalize) {
578                         EnterCriticalSection (&finalizer_mutex);
579                         if (domains_to_finalize) {
580                                 DomainFinalizationReq *req = domains_to_finalize->data;
581                                 domains_to_finalize = g_slist_remove (domains_to_finalize, req);
582                                 LeaveCriticalSection (&finalizer_mutex);
583
584                                 finalize_domain_objects (req);
585                         }
586                         else
587                                 LeaveCriticalSection (&finalizer_mutex);
588                 }                               
589
590 #ifdef DEBUG
591                 g_message (G_GNUC_PRETTY_FUNCTION ": invoking finalizers");
592 #endif
593
594                 /* If finished == TRUE, mono_gc_cleanup has been called (from mono_runtime_cleanup),
595                  * before the domain is unloaded.
596                  *
597                  * There is a bug in GC_invoke_finalizer () in versions <= 6.2alpha4:
598                  * the 'mem_freed' variable is not initialized when there are no
599                  * objects to finalize, which leads to strange behavior later on.
600                  * The check is necessary to work around that bug.
601                  */
602                 if (GC_should_invoke_finalizers ()) {
603                         GC_invoke_finalizers ();
604                 }
605
606                 SetEvent (pending_done_event);
607         }
608
609         SetEvent (shutdown_event);
610         return(0);
611 }
612
613 /* 
614  * Enable or disable the separate finalizer thread.
615  * It's currently disabled because it still requires some
616  * work in the rest of the runtime.
617  */
618 #define ENABLE_FINALIZER_THREAD
619
620 #ifdef WITH_INCLUDED_LIBGC
621 /* from threads.c */
622 extern void mono_gc_stop_world (void);
623 extern void mono_gc_start_world (void);
624 extern void mono_gc_push_all_stacks (void);
625
626 static void mono_gc_lock (void)
627 {
628         EnterCriticalSection (&allocator_section);
629 }
630
631 static void mono_gc_unlock (void)
632 {
633         LeaveCriticalSection (&allocator_section);
634 }
635
636 static GCThreadFunctions mono_gc_thread_vtable = {
637         NULL,
638
639         mono_gc_lock,
640         mono_gc_unlock,
641
642         mono_gc_stop_world,
643         NULL,
644         mono_gc_push_all_stacks,
645         mono_gc_start_world
646 };
647 #endif /* WITH_INCLUDED_LIBGC */
648
649 static void
650 mono_gc_warning (char *msg, GC_word arg)
651 {
652         mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_GC, msg, (unsigned long)arg);
653 }
654
655 void mono_gc_init (void)
656 {
657         InitializeCriticalSection (&handle_section);
658         InitializeCriticalSection (&allocator_section);
659
660         InitializeCriticalSection (&finalizer_mutex);
661
662 #ifdef WITH_INCLUDED_LIBGC
663         gc_thread_vtable = &mono_gc_thread_vtable;
664 #endif
665
666         GC_set_warn_proc (mono_gc_warning);
667         
668 #ifdef ENABLE_FINALIZER_THREAD
669
670         if (g_getenv ("GC_DONT_GC")) {
671                 gc_disabled = TRUE;
672                 return;
673         }
674         
675         finalizer_event = CreateEvent (NULL, FALSE, FALSE, NULL);
676         pending_done_event = CreateEvent (NULL, TRUE, FALSE, NULL);
677         shutdown_event = CreateEvent (NULL, TRUE, FALSE, NULL);
678         thread_started_event = CreateEvent (NULL, TRUE, FALSE, NULL);
679         if (finalizer_event == NULL || pending_done_event == NULL || shutdown_event == NULL || thread_started_event == NULL) {
680                 g_assert_not_reached ();
681         }
682
683         GC_finalize_on_demand = 1;
684         GC_finalizer_notifier = finalize_notify;
685
686         mono_thread_create (mono_domain_get (), finalizer_thread, NULL);
687         /*
688          * Wait until the finalizer thread sets gc_thread since its value is needed
689          * by mono_thread_attach ()
690          */
691         WaitForSingleObjectEx (thread_started_event, INFINITE, FALSE);
692 #endif
693 }
694
695 void mono_gc_cleanup (void)
696 {
697 #ifdef DEBUG
698         g_message (G_GNUC_PRETTY_FUNCTION ": cleaning up finalizer");
699 #endif
700
701 #ifdef ENABLE_FINALIZER_THREAD
702         if (!gc_disabled) {
703                 ResetEvent (shutdown_event);
704                 finished = TRUE;
705                 finalize_notify ();
706                 /* Finishing the finalizer thread, so wait a little bit... */
707                 /* MS seems to wait for about 2 seconds */
708                 if (WaitForSingleObjectEx (shutdown_event, 2000, FALSE) == WAIT_TIMEOUT) {
709                         mono_thread_stop (gc_thread);
710                 }
711         }
712
713 #endif
714 }
715
716 void
717 mono_gc_disable (void)
718 {
719 #ifdef HAVE_GC_ENABLE
720         GC_disable ();
721 #else
722         g_assert_not_reached ();
723 #endif
724 }
725
726 void
727 mono_gc_enable (void)
728 {
729 #ifdef HAVE_GC_ENABLE
730         GC_enable ();
731 #else
732         g_assert_not_reached ();
733 #endif
734 }
735
736 #else
737
738 /* no Boehm GC support. */
739 void mono_gc_init (void)
740 {
741         InitializeCriticalSection (&handle_section);
742 }
743
744 void mono_gc_cleanup (void)
745 {
746 }
747
748 void
749 mono_gc_disable (void)
750 {
751 }
752
753 void
754 mono_gc_enable (void)
755 {
756 }
757
758 #endif
759
760 gboolean
761 mono_gc_is_finalizer_thread (MonoThread *thread)
762 {
763         return thread == gc_thread;
764 }
765
766