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