5c847572e8d7f7a61a502567fe0f08bf62763450
[mono.git] / mono / metadata / boehm-gc.c
1 /*
2  * boehm-gc.c: GC implementation using either the installed or included Boehm GC.
3  *
4  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
5  * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
6  * Copyright 2011-2012 Xamarin, Inc (http://www.xamarin.com)
7  */
8
9 #include "config.h"
10
11 #include <string.h>
12
13 #define GC_I_HIDE_POINTERS
14 #include <mono/metadata/gc-internal.h>
15 #include <mono/metadata/mono-gc.h>
16 #include <mono/metadata/profiler-private.h>
17 #include <mono/metadata/class-internals.h>
18 #include <mono/metadata/method-builder.h>
19 #include <mono/metadata/opcodes.h>
20 #include <mono/metadata/domain-internals.h>
21 #include <mono/metadata/metadata-internals.h>
22 #include <mono/metadata/marshal.h>
23 #include <mono/metadata/runtime.h>
24 #include <mono/metadata/sgen-toggleref.h>
25 #include <mono/utils/atomic.h>
26 #include <mono/utils/mono-logger-internal.h>
27 #include <mono/utils/mono-memory-model.h>
28 #include <mono/utils/mono-time.h>
29 #include <mono/utils/mono-threads.h>
30 #include <mono/utils/dtrace.h>
31 #include <mono/utils/gc_wrapper.h>
32 #include <mono/utils/mono-mutex.h>
33 #include <mono/utils/mono-counters.h>
34
35 #if HAVE_BOEHM_GC
36
37 #ifdef USE_INCLUDED_LIBGC
38 #undef TRUE
39 #undef FALSE
40 #define THREAD_LOCAL_ALLOC 1
41 #include "private/pthread_support.h"
42 #endif
43
44 #if defined(PLATFORM_MACOSX) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
45 void *pthread_get_stackaddr_np(pthread_t);
46 #endif
47
48 #define GC_NO_DESCRIPTOR ((gpointer)(0 | GC_DS_LENGTH))
49 /*Boehm max heap cannot be smaller than 16MB*/
50 #define MIN_BOEHM_MAX_HEAP_SIZE_IN_MB 16
51 #define MIN_BOEHM_MAX_HEAP_SIZE (MIN_BOEHM_MAX_HEAP_SIZE_IN_MB << 20)
52
53 static gboolean gc_initialized = FALSE;
54 static mono_mutex_t mono_gc_lock;
55
56 static void*
57 boehm_thread_register (MonoThreadInfo* info, void *baseptr);
58 static void
59 boehm_thread_unregister (MonoThreadInfo *p);
60 static void
61 register_test_toggleref_callback (void);
62
63 #define BOEHM_GC_BIT_FINALIZER_AWARE 1
64 static MonoGCFinalizerCallbacks fin_callbacks;
65
66 static void
67 mono_gc_warning (char *msg, GC_word arg)
68 {
69         mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_GC, msg, (unsigned long)arg);
70 }
71
72 void
73 mono_gc_base_init (void)
74 {
75         MonoThreadInfoCallbacks cb;
76         const char *env;
77         int dummy;
78
79         if (gc_initialized)
80                 return;
81
82         mono_counters_init ();
83
84         /*
85          * Handle the case when we are called from a thread different from the main thread,
86          * confusing libgc.
87          * FIXME: Move this to libgc where it belongs.
88          *
89          * we used to do this only when running on valgrind,
90          * but it happens also in other setups.
91          */
92 #if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) && !defined(__native_client__)
93         {
94                 size_t size;
95                 void *sstart;
96                 pthread_attr_t attr;
97                 pthread_getattr_np (pthread_self (), &attr);
98                 pthread_attr_getstack (&attr, &sstart, &size);
99                 pthread_attr_destroy (&attr); 
100                 /*g_print ("stackbottom pth is: %p\n", (char*)sstart + size);*/
101 #ifdef __ia64__
102                 /*
103                  * The calculation above doesn't seem to work on ia64, also we need to set
104                  * GC_register_stackbottom as well, but don't know how.
105                  */
106 #else
107                 /* apparently with some linuxthreads implementations sstart can be NULL,
108                  * fallback to the more imprecise method (bug# 78096).
109                  */
110                 if (sstart) {
111                         GC_stackbottom = (char*)sstart + size;
112                 } else {
113                         int dummy;
114                         gsize stack_bottom = (gsize)&dummy;
115                         stack_bottom += 4095;
116                         stack_bottom &= ~4095;
117                         GC_stackbottom = (char*)stack_bottom;
118                 }
119 #endif
120         }
121 #elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
122                 GC_stackbottom = (char*)pthread_get_stackaddr_np (pthread_self ());
123 #elif defined(__OpenBSD__)
124 #  include <pthread_np.h>
125         {
126                 stack_t ss;
127                 int rslt;
128
129                 rslt = pthread_stackseg_np(pthread_self(), &ss);
130                 g_assert (rslt == 0);
131
132                 GC_stackbottom = (char*)ss.ss_sp;
133         }
134 #elif defined(__native_client__)
135         /* Do nothing, GC_stackbottom is set correctly in libgc */
136 #else
137         {
138                 int dummy;
139                 gsize stack_bottom = (gsize)&dummy;
140                 stack_bottom += 4095;
141                 stack_bottom &= ~4095;
142                 /*g_print ("stackbottom is: %p\n", (char*)stack_bottom);*/
143                 GC_stackbottom = (char*)stack_bottom;
144         }
145 #endif
146
147 #if !defined(PLATFORM_ANDROID)
148         /* If GC_no_dls is set to true, GC_find_limit is not called. This causes a seg fault on Android. */
149         GC_no_dls = TRUE;
150 #endif
151         GC_init ();
152         GC_oom_fn = mono_gc_out_of_memory;
153         GC_set_warn_proc (mono_gc_warning);
154         GC_finalize_on_demand = 1;
155         GC_finalizer_notifier = mono_gc_finalize_notify;
156
157 #ifdef HAVE_GC_GCJ_MALLOC
158         GC_init_gcj_malloc (5, NULL);
159 #endif
160
161 #ifdef HAVE_GC_ALLOW_REGISTER_THREADS
162         GC_allow_register_threads();
163 #endif
164
165         if ((env = g_getenv ("MONO_GC_PARAMS"))) {
166                 char **ptr, **opts = g_strsplit (env, ",", -1);
167                 for (ptr = opts; *ptr; ++ptr) {
168                         char *opt = *ptr;
169                         if (g_str_has_prefix (opt, "max-heap-size=")) {
170                                 size_t max_heap;
171
172                                 opt = strchr (opt, '=') + 1;
173                                 if (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) {
174                                         if (max_heap < MIN_BOEHM_MAX_HEAP_SIZE) {
175                                                 fprintf (stderr, "max-heap-size must be at least %dMb.\n", MIN_BOEHM_MAX_HEAP_SIZE_IN_MB);
176                                                 exit (1);
177                                         }
178                                         GC_set_max_heap_size (max_heap);
179                                 } else {
180                                         fprintf (stderr, "max-heap-size must be an integer.\n");
181                                         exit (1);
182                                 }
183                                 continue;
184                         } else if (g_str_has_prefix (opt, "toggleref-test")) {
185                                 register_test_toggleref_callback ();
186                                 continue;
187                         } else {
188                                 /* Could be a parameter for sgen */
189                                 /*
190                                 fprintf (stderr, "MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:\n");
191                                 fprintf (stderr, "  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)\n");
192                                 exit (1);
193                                 */
194                         }
195                 }
196                 g_strfreev (opts);
197         }
198
199         memset (&cb, 0, sizeof (cb));
200         cb.thread_register = boehm_thread_register;
201         cb.thread_unregister = boehm_thread_unregister;
202         cb.mono_method_is_critical = (gpointer)mono_runtime_is_critical_method;
203 #ifndef HOST_WIN32
204         cb.thread_exit = mono_gc_pthread_exit;
205         cb.mono_gc_pthread_create = (gpointer)mono_gc_pthread_create;
206 #endif
207         
208         mono_threads_init (&cb, sizeof (MonoThreadInfo));
209         mono_mutex_init (&mono_gc_lock);
210
211         mono_thread_info_attach (&dummy);
212
213         mono_gc_enable_events ();
214         gc_initialized = TRUE;
215 }
216
217 /**
218  * mono_gc_collect:
219  * @generation: GC generation identifier
220  *
221  * Perform a garbage collection for the given generation, higher numbers
222  * mean usually older objects. Collecting a high-numbered generation
223  * implies collecting also the lower-numbered generations.
224  * The maximum value for @generation can be retrieved with a call to
225  * mono_gc_max_generation(), so this function is usually called as:
226  *
227  *      mono_gc_collect (mono_gc_max_generation ());
228  */
229 void
230 mono_gc_collect (int generation)
231 {
232 #ifndef DISABLE_PERFCOUNTERS
233         mono_perfcounters->gc_induced++;
234 #endif
235         GC_gcollect ();
236 }
237
238 /**
239  * mono_gc_max_generation:
240  *
241  * Get the maximum generation number used by the current garbage
242  * collector. The value will be 0 for the Boehm collector, 1 or more
243  * for the generational collectors.
244  *
245  * Returns: the maximum generation number.
246  */
247 int
248 mono_gc_max_generation (void)
249 {
250         return 0;
251 }
252
253 /**
254  * mono_gc_get_generation:
255  * @object: a managed object
256  *
257  * Get the garbage collector's generation that @object belongs to.
258  * Use this has a hint only.
259  *
260  * Returns: a garbage collector generation number
261  */
262 int
263 mono_gc_get_generation  (MonoObject *object)
264 {
265         return 0;
266 }
267
268 /**
269  * mono_gc_collection_count:
270  * @generation: a GC generation number
271  *
272  * Get how many times a garbage collection has been performed
273  * for the given @generation number.
274  *
275  * Returns: the number of garbage collections
276  */
277 int
278 mono_gc_collection_count (int generation)
279 {
280         return GC_gc_no;
281 }
282
283 /**
284  * mono_gc_add_memory_pressure:
285  * @value: amount of bytes
286  *
287  * Adjust the garbage collector's view of how many bytes of memory
288  * are indirectly referenced by managed objects (for example unmanaged
289  * memory holding image or other binary data).
290  * This is a hint only to the garbage collector algorithm.
291  * Note that negative amounts of @value will decrease the memory
292  * pressure.
293  */
294 void
295 mono_gc_add_memory_pressure (gint64 value)
296 {
297 }
298
299 /**
300  * mono_gc_get_used_size:
301  *
302  * Get the approximate amount of memory used by managed objects.
303  *
304  * Returns: the amount of memory used in bytes
305  */
306 int64_t
307 mono_gc_get_used_size (void)
308 {
309         return GC_get_heap_size () - GC_get_free_bytes ();
310 }
311
312 /**
313  * mono_gc_get_heap_size:
314  *
315  * Get the amount of memory used by the garbage collector.
316  *
317  * Returns: the size of the heap in bytes
318  */
319 int64_t
320 mono_gc_get_heap_size (void)
321 {
322         return GC_get_heap_size ();
323 }
324
325 gboolean
326 mono_gc_is_gc_thread (void)
327 {
328 #if GC_VERSION_MAJOR >= 7
329         return TRUE;
330 #elif defined(USE_INCLUDED_LIBGC)
331         return GC_thread_is_registered ();
332 #else
333         return TRUE;
334 #endif
335 }
336
337 extern int GC_thread_register_foreign (void *base_addr);
338
339 gboolean
340 mono_gc_register_thread (void *baseptr)
341 {
342         return mono_thread_info_attach (baseptr) != NULL;
343 }
344
345 static void*
346 boehm_thread_register (MonoThreadInfo* info, void *baseptr)
347 {
348 #if GC_VERSION_MAJOR >= 7
349         struct GC_stack_base sb;
350         int res;
351
352         res = GC_get_stack_base (&sb);
353         if (res != GC_SUCCESS) {
354                 sb.mem_base = baseptr;
355 #ifdef __ia64__
356                 /* Can't determine the register stack bounds */
357                 g_error ("mono_gc_register_thread failed ().\n");
358 #endif
359         }
360         res = GC_register_my_thread (&sb);
361         if ((res != GC_SUCCESS) && (res != GC_DUPLICATE)) {
362                 g_warning ("GC_register_my_thread () failed.\n");
363                 return NULL;
364         }
365         return info;
366 #else
367         if (mono_gc_is_gc_thread())
368                 return info;
369 #if defined(USE_INCLUDED_LIBGC) && !defined(HOST_WIN32)
370         return GC_thread_register_foreign (baseptr) ? info : NULL;
371 #else
372         return NULL;
373 #endif
374 #endif
375 }
376
377 static void
378 boehm_thread_unregister (MonoThreadInfo *p)
379 {
380         MonoNativeThreadId tid;
381
382         tid = mono_thread_info_get_tid (p);
383
384         if (p->runtime_thread)
385                 mono_threads_add_joinable_thread ((gpointer)tid);
386 }
387
388 gboolean
389 mono_object_is_alive (MonoObject* o)
390 {
391 #ifdef USE_INCLUDED_LIBGC
392         return GC_is_marked ((gpointer)o);
393 #else
394         return TRUE;
395 #endif
396 }
397
398 int
399 mono_gc_walk_heap (int flags, MonoGCReferences callback, void *data)
400 {
401         return 1;
402 }
403
404 #ifdef USE_INCLUDED_LIBGC
405
406 static gint64 gc_start_time;
407
408 static void
409 on_gc_notification (GCEventType event)
410 {
411         MonoGCEvent e = (MonoGCEvent)event;
412
413         switch (e) {
414         case MONO_GC_EVENT_PRE_STOP_WORLD:
415                 MONO_GC_WORLD_STOP_BEGIN ();
416                 mono_thread_info_suspend_lock ();
417                 break;
418
419         case MONO_GC_EVENT_POST_STOP_WORLD:
420                 MONO_GC_WORLD_STOP_END ();
421                 break;
422
423         case MONO_GC_EVENT_PRE_START_WORLD:
424                 MONO_GC_WORLD_RESTART_BEGIN (1);
425                 break;
426
427         case MONO_GC_EVENT_POST_START_WORLD:
428                 MONO_GC_WORLD_RESTART_END (1);
429                 mono_thread_info_suspend_unlock ();
430                 break;
431
432         case MONO_GC_EVENT_START:
433                 MONO_GC_BEGIN (1);
434 #ifndef DISABLE_PERFCOUNTERS
435                 if (mono_perfcounters)
436                         mono_perfcounters->gc_collections0++;
437 #endif
438                 gc_stats.major_gc_count ++;
439                 gc_start_time = mono_100ns_ticks ();
440                 break;
441
442         case MONO_GC_EVENT_END:
443                 MONO_GC_END (1);
444 #if defined(ENABLE_DTRACE) && defined(__sun__)
445                 /* This works around a dtrace -G problem on Solaris.
446                    Limit its actual use to when the probe is enabled. */
447                 if (MONO_GC_END_ENABLED ())
448                         sleep(0);
449 #endif
450
451 #ifndef DISABLE_PERFCOUNTERS
452                 if (mono_perfcounters) {
453                         guint64 heap_size = GC_get_heap_size ();
454                         guint64 used_size = heap_size - GC_get_free_bytes ();
455                         mono_perfcounters->gc_total_bytes = used_size;
456                         mono_perfcounters->gc_committed_bytes = heap_size;
457                         mono_perfcounters->gc_reserved_bytes = heap_size;
458                         mono_perfcounters->gc_gen0size = heap_size;
459                 }
460 #endif
461                 gc_stats.major_gc_time += mono_100ns_ticks () - gc_start_time;
462                 mono_trace_message (MONO_TRACE_GC, "gc took %d usecs", (mono_100ns_ticks () - gc_start_time) / 10);
463                 break;
464         }
465
466         mono_profiler_gc_event (e, 0);
467 }
468  
469 static void
470 on_gc_heap_resize (size_t new_size)
471 {
472         guint64 heap_size = GC_get_heap_size ();
473 #ifndef DISABLE_PERFCOUNTERS
474         if (mono_perfcounters) {
475                 mono_perfcounters->gc_committed_bytes = heap_size;
476                 mono_perfcounters->gc_reserved_bytes = heap_size;
477                 mono_perfcounters->gc_gen0size = heap_size;
478         }
479 #endif
480         mono_profiler_gc_heap_resize (new_size);
481 }
482
483 void
484 mono_gc_enable_events (void)
485 {
486         GC_notify_event = on_gc_notification;
487         GC_on_heap_resize = on_gc_heap_resize;
488 }
489
490 #else
491
492 void
493 mono_gc_enable_events (void)
494 {
495 }
496
497 #endif
498
499 int
500 mono_gc_register_root (char *start, size_t size, void *descr)
501 {
502         /* for some strange reason, they want one extra byte on the end */
503         GC_add_roots (start, start + size + 1);
504
505         return TRUE;
506 }
507
508 void
509 mono_gc_deregister_root (char* addr)
510 {
511 #ifndef HOST_WIN32
512         /* FIXME: libgc doesn't define this work win32 for some reason */
513         /* FIXME: No size info */
514         GC_remove_roots (addr, addr + sizeof (gpointer) + 1);
515 #endif
516 }
517
518 void
519 mono_gc_weak_link_add (void **link_addr, MonoObject *obj, gboolean track)
520 {
521         /* libgc requires that we use HIDE_POINTER... */
522         *link_addr = (void*)HIDE_POINTER (obj);
523         if (track)
524                 GC_REGISTER_LONG_LINK (link_addr, obj);
525         else
526                 GC_GENERAL_REGISTER_DISAPPEARING_LINK (link_addr, obj);
527 }
528
529 void
530 mono_gc_weak_link_remove (void **link_addr, gboolean track)
531 {
532         if (track)
533                 GC_unregister_long_link (link_addr);
534         else
535                 GC_unregister_disappearing_link (link_addr);
536         *link_addr = NULL;
537 }
538
539 static gpointer
540 reveal_link (gpointer link_addr)
541 {
542         void **link_a = link_addr;
543         return REVEAL_POINTER (*link_a);
544 }
545
546 MonoObject*
547 mono_gc_weak_link_get (void **link_addr)
548 {
549         MonoObject *obj = GC_call_with_alloc_lock (reveal_link, link_addr);
550         if (obj == (MonoObject *) -1)
551                 return NULL;
552         return obj;
553 }
554
555 void*
556 mono_gc_make_descr_for_string (gsize *bitmap, int numbits)
557 {
558         return mono_gc_make_descr_from_bitmap (bitmap, numbits);
559 }
560
561 void*
562 mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size)
563 {
564         return mono_gc_make_descr_from_bitmap (bitmap, numbits);
565 }
566
567 void*
568 mono_gc_make_descr_for_array (int vector, gsize *elem_bitmap, int numbits, size_t elem_size)
569 {
570         /* libgc has no usable support for arrays... */
571         return GC_NO_DESCRIPTOR;
572 }
573
574 void*
575 mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
576 {
577 #ifdef HAVE_GC_GCJ_MALLOC
578         /* It seems there are issues when the bitmap doesn't fit: play it safe */
579         if (numbits >= 30)
580                 return GC_NO_DESCRIPTOR;
581         else
582                 return (gpointer)GC_make_descriptor ((GC_bitmap)bitmap, numbits);
583 #else
584         return NULL;
585 #endif
586 }
587
588 void*
589 mono_gc_make_root_descr_all_refs (int numbits)
590 {
591         return NULL;
592 }
593
594 void*
595 mono_gc_alloc_fixed (size_t size, void *descr)
596 {
597         /* To help track down typed allocation bugs */
598         /*
599         static int count;
600         count ++;
601         if (count == atoi (g_getenv ("COUNT2")))
602                 printf ("HIT!\n");
603         if (count > atoi (g_getenv ("COUNT2")))
604                 return GC_MALLOC (size);
605         */
606
607         if (descr)
608                 return GC_MALLOC_EXPLICITLY_TYPED (size, (GC_descr)descr);
609         else
610                 return GC_MALLOC (size);
611 }
612
613 void
614 mono_gc_free_fixed (void* addr)
615 {
616 }
617
618 int
619 mono_gc_invoke_finalizers (void)
620 {
621         /* There is a bug in GC_invoke_finalizer () in versions <= 6.2alpha4:
622          * the 'mem_freed' variable is not initialized when there are no
623          * objects to finalize, which leads to strange behavior later on.
624          * The check is necessary to work around that bug.
625          */
626         if (GC_should_invoke_finalizers ())
627                 return GC_invoke_finalizers ();
628         return 0;
629 }
630
631 gboolean
632 mono_gc_pending_finalizers (void)
633 {
634         return GC_should_invoke_finalizers ();
635 }
636
637 void
638 mono_gc_wbarrier_set_field (MonoObject *obj, gpointer field_ptr, MonoObject* value)
639 {
640         *(void**)field_ptr = value;
641 }
642
643 void
644 mono_gc_wbarrier_set_arrayref (MonoArray *arr, gpointer slot_ptr, MonoObject* value)
645 {
646         *(void**)slot_ptr = value;
647 }
648
649 void
650 mono_gc_wbarrier_arrayref_copy (gpointer dest_ptr, gpointer src_ptr, int count)
651 {
652         mono_gc_memmove_aligned (dest_ptr, src_ptr, count * sizeof (gpointer));
653 }
654
655 void
656 mono_gc_wbarrier_generic_store (gpointer ptr, MonoObject* value)
657 {
658         *(void**)ptr = value;
659 }
660
661 void
662 mono_gc_wbarrier_generic_store_atomic (gpointer ptr, MonoObject *value)
663 {
664         InterlockedWritePointer (ptr, value);
665 }
666
667 void
668 mono_gc_wbarrier_generic_nostore (gpointer ptr)
669 {
670 }
671
672 void
673 mono_gc_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *klass)
674 {
675         mono_gc_memmove_atomic (dest, src, count * mono_class_value_size (klass, NULL));
676 }
677
678 void
679 mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
680 {
681         /* do not copy the sync state */
682         mono_gc_memmove_aligned ((char*)obj + sizeof (MonoObject), (char*)src + sizeof (MonoObject),
683                         mono_object_class (obj)->instance_size - sizeof (MonoObject));
684 }
685
686 void
687 mono_gc_clear_domain (MonoDomain *domain)
688 {
689 }
690
691 int
692 mono_gc_get_suspend_signal (void)
693 {
694 #ifdef USE_INCLUDED_GC
695         return GC_get_suspend_signal ();
696 #else
697         return -1;
698 #endif
699 }
700
701 int
702 mono_gc_get_restart_signal (void)
703 {
704 #ifdef USE_INCLUDED_GC
705         return GC_get_restart_signal ();
706 #else
707         return -1;
708 #endif
709 }
710
711 #if defined(USE_INCLUDED_LIBGC) && defined(USE_COMPILER_TLS) && defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
712 extern __thread MONO_TLS_FAST void* GC_thread_tls;
713 #include "metadata-internals.h"
714
715 static int
716 shift_amount (int v)
717 {
718         int i = 0;
719         while (!(v & (1 << i)))
720                 i++;
721         return i;
722 }
723
724 enum {
725         ATYPE_FREEPTR,
726         ATYPE_FREEPTR_FOR_BOX,
727         ATYPE_NORMAL,
728         ATYPE_GCJ,
729         ATYPE_STRING,
730         ATYPE_NUM
731 };
732
733 static MonoMethod*
734 create_allocator (int atype, int tls_key)
735 {
736         int index_var, bytes_var, my_fl_var, my_entry_var;
737         guint32 no_freelist_branch, not_small_enough_branch = 0;
738         guint32 size_overflow_branch = 0;
739         MonoMethodBuilder *mb;
740         MonoMethod *res;
741         MonoMethodSignature *csig;
742         AllocatorWrapperInfo *info;
743
744         if (atype == ATYPE_STRING) {
745                 csig = mono_metadata_signature_alloc (mono_defaults.corlib, 2);
746                 csig->ret = &mono_defaults.string_class->byval_arg;
747                 csig->params [0] = &mono_defaults.int_class->byval_arg;
748                 csig->params [1] = &mono_defaults.int32_class->byval_arg;
749         } else {
750                 csig = mono_metadata_signature_alloc (mono_defaults.corlib, 2);
751                 csig->ret = &mono_defaults.object_class->byval_arg;
752                 csig->params [0] = &mono_defaults.int_class->byval_arg;
753                 csig->params [1] = &mono_defaults.int32_class->byval_arg;
754         }
755
756         mb = mono_mb_new (mono_defaults.object_class, "Alloc", MONO_WRAPPER_ALLOC);
757         bytes_var = mono_mb_add_local (mb, &mono_defaults.int32_class->byval_arg);
758         if (atype == ATYPE_STRING) {
759                 /* a string alloator method takes the args: (vtable, len) */
760                 /* bytes = (offsetof (MonoString, chars) + ((len + 1) * 2)); */
761                 mono_mb_emit_ldarg (mb, 1);
762                 mono_mb_emit_icon (mb, 1);
763                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
764                 mono_mb_emit_icon (mb, 1);
765                 mono_mb_emit_byte (mb, MONO_CEE_SHL);
766                 // sizeof (MonoString) might include padding
767                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoString, chars));
768                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
769                 mono_mb_emit_stloc (mb, bytes_var);
770         } else {
771                 mono_mb_emit_ldarg (mb, 1);
772                 mono_mb_emit_stloc (mb, bytes_var);
773         }
774
775         /* this is needed for strings/arrays only as the other big types are never allocated with this method */
776         if (atype == ATYPE_STRING) {
777                 /* check for size */
778                 /* if (!SMALL_ENOUGH (bytes)) jump slow_path;*/
779                 mono_mb_emit_ldloc (mb, bytes_var);
780                 mono_mb_emit_icon (mb, (NFREELISTS-1) * GRANULARITY);
781                 not_small_enough_branch = mono_mb_emit_short_branch (mb, MONO_CEE_BGT_UN_S);
782                 /* check for overflow */
783                 mono_mb_emit_ldloc (mb, bytes_var);
784                 mono_mb_emit_icon (mb, sizeof (MonoString));
785                 size_overflow_branch = mono_mb_emit_short_branch (mb, MONO_CEE_BLE_UN_S);
786         }
787
788         /* int index = INDEX_FROM_BYTES(bytes); */
789         index_var = mono_mb_add_local (mb, &mono_defaults.int32_class->byval_arg);
790         
791         mono_mb_emit_ldloc (mb, bytes_var);
792         mono_mb_emit_icon (mb, GRANULARITY - 1);
793         mono_mb_emit_byte (mb, MONO_CEE_ADD);
794         mono_mb_emit_icon (mb, shift_amount (GRANULARITY));
795         mono_mb_emit_byte (mb, MONO_CEE_SHR_UN);
796         mono_mb_emit_icon (mb, shift_amount (sizeof (gpointer)));
797         mono_mb_emit_byte (mb, MONO_CEE_SHL);
798         /* index var is already adjusted into bytes */
799         mono_mb_emit_stloc (mb, index_var);
800
801         my_fl_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
802         my_entry_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
803         /* my_fl = ((GC_thread)tsd) -> ptrfree_freelists + index; */
804         mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
805         mono_mb_emit_byte (mb, 0x0D); /* CEE_MONO_TLS */
806         mono_mb_emit_i4 (mb, tls_key);
807         if (atype == ATYPE_FREEPTR || atype == ATYPE_FREEPTR_FOR_BOX || atype == ATYPE_STRING)
808                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (struct GC_Thread_Rep, ptrfree_freelists));
809         else if (atype == ATYPE_NORMAL)
810                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (struct GC_Thread_Rep, normal_freelists));
811         else if (atype == ATYPE_GCJ)
812                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (struct GC_Thread_Rep, gcj_freelists));
813         else
814                 g_assert_not_reached ();
815         mono_mb_emit_byte (mb, MONO_CEE_ADD);
816         mono_mb_emit_ldloc (mb, index_var);
817         mono_mb_emit_byte (mb, MONO_CEE_ADD);
818         mono_mb_emit_stloc (mb, my_fl_var);
819
820         /* my_entry = *my_fl; */
821         mono_mb_emit_ldloc (mb, my_fl_var);
822         mono_mb_emit_byte (mb, MONO_CEE_LDIND_I);
823         mono_mb_emit_stloc (mb, my_entry_var);
824
825         /* if (EXPECT((word)my_entry >= HBLKSIZE, 1)) { */
826         mono_mb_emit_ldloc (mb, my_entry_var);
827         mono_mb_emit_icon (mb, HBLKSIZE);
828         no_freelist_branch = mono_mb_emit_short_branch (mb, MONO_CEE_BLT_UN_S);
829
830         /* ptr_t next = obj_link(my_entry); *my_fl = next; */
831         mono_mb_emit_ldloc (mb, my_fl_var);
832         mono_mb_emit_ldloc (mb, my_entry_var);
833         mono_mb_emit_byte (mb, MONO_CEE_LDIND_I);
834         mono_mb_emit_byte (mb, MONO_CEE_STIND_I);
835
836         /* set the vtable and clear the words in the object */
837         mono_mb_emit_ldloc (mb, my_entry_var);
838         mono_mb_emit_ldarg (mb, 0);
839         mono_mb_emit_byte (mb, MONO_CEE_STIND_I);
840
841         if (atype == ATYPE_FREEPTR) {
842                 int start_var, end_var, start_loop;
843                 /* end = my_entry + bytes; start = my_entry + sizeof (gpointer);
844                  */
845                 start_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
846                 end_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
847                 mono_mb_emit_ldloc (mb, my_entry_var);
848                 mono_mb_emit_ldloc (mb, bytes_var);
849                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
850                 mono_mb_emit_stloc (mb, end_var);
851                 mono_mb_emit_ldloc (mb, my_entry_var);
852                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoObject, synchronisation));
853                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
854                 mono_mb_emit_stloc (mb, start_var);
855                 /*
856                  * do {
857                  *      *start++ = NULL;
858                  * } while (start < end);
859                  */
860                 start_loop = mono_mb_get_label (mb);
861                 mono_mb_emit_ldloc (mb, start_var);
862                 mono_mb_emit_icon (mb, 0);
863                 mono_mb_emit_byte (mb, MONO_CEE_STIND_I);
864                 mono_mb_emit_ldloc (mb, start_var);
865                 mono_mb_emit_icon (mb, sizeof (gpointer));
866                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
867                 mono_mb_emit_stloc (mb, start_var);
868
869                 mono_mb_emit_ldloc (mb, start_var);
870                 mono_mb_emit_ldloc (mb, end_var);
871                 mono_mb_emit_byte (mb, MONO_CEE_BLT_UN_S);
872                 mono_mb_emit_byte (mb, start_loop - (mono_mb_get_label (mb) + 1));
873         } else if (atype == ATYPE_FREEPTR_FOR_BOX || atype == ATYPE_STRING) {
874                 /* need to clear just the sync pointer */
875                 mono_mb_emit_ldloc (mb, my_entry_var);
876                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoObject, synchronisation));
877                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
878                 mono_mb_emit_icon (mb, 0);
879                 mono_mb_emit_byte (mb, MONO_CEE_STIND_I);
880         }
881
882         if (atype == ATYPE_STRING) {
883                 /* need to set length and clear the last char */
884                 /* s->length = len; */
885                 mono_mb_emit_ldloc (mb, my_entry_var);
886                 mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoString, length));
887                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
888                 mono_mb_emit_ldarg (mb, 1);
889                 mono_mb_emit_byte (mb, MONO_CEE_STIND_I4);
890                 /* s->chars [len] = 0; */
891                 mono_mb_emit_ldloc (mb, my_entry_var);
892                 mono_mb_emit_ldloc (mb, bytes_var);
893                 mono_mb_emit_icon (mb, 2);
894                 mono_mb_emit_byte (mb, MONO_CEE_SUB);
895                 mono_mb_emit_byte (mb, MONO_CEE_ADD);
896                 mono_mb_emit_icon (mb, 0);
897                 mono_mb_emit_byte (mb, MONO_CEE_STIND_I2);
898         }
899
900         /* return my_entry; */
901         mono_mb_emit_ldloc (mb, my_entry_var);
902         mono_mb_emit_byte (mb, MONO_CEE_RET);
903         
904         mono_mb_patch_short_branch (mb, no_freelist_branch);
905         if (not_small_enough_branch > 0)
906                 mono_mb_patch_short_branch (mb, not_small_enough_branch);
907         if (size_overflow_branch > 0)
908                 mono_mb_patch_short_branch (mb, size_overflow_branch);
909         /* the slow path: we just call back into the runtime */
910         if (atype == ATYPE_STRING) {
911                 mono_mb_emit_ldarg (mb, 1);
912                 mono_mb_emit_icall (mb, mono_string_alloc);
913         } else {
914                 mono_mb_emit_ldarg (mb, 0);
915                 mono_mb_emit_icall (mb, mono_object_new_specific);
916         }
917
918         mono_mb_emit_byte (mb, MONO_CEE_RET);
919
920         res = mono_mb_create_method (mb, csig, 8);
921         mono_mb_free (mb);
922         mono_method_get_header (res)->init_locals = FALSE;
923
924         info = mono_image_alloc0 (mono_defaults.corlib, sizeof (AllocatorWrapperInfo));
925         info->gc_name = "boehm";
926         info->alloc_type = atype;
927         mono_marshal_set_wrapper_info (res, info);
928
929         return res;
930 }
931
932 static MonoMethod* alloc_method_cache [ATYPE_NUM];
933
934 static G_GNUC_UNUSED gboolean
935 mono_gc_is_critical_method (MonoMethod *method)
936 {
937         int i;
938
939         for (i = 0; i < ATYPE_NUM; ++i)
940                 if (method == alloc_method_cache [i])
941                         return TRUE;
942
943         return FALSE;
944 }
945
946 /*
947  * If possible, generate a managed method that can quickly allocate objects in class
948  * @klass. The method will typically have an thread-local inline allocation sequence.
949  * The signature of the called method is:
950  *      object allocate (MonoVTable *vtable)
951  * Some of the logic here is similar to mono_class_get_allocation_ftn () i object.c,
952  * keep in sync.
953  * The thread local alloc logic is taken from libgc/pthread_support.c.
954  */
955
956 MonoMethod*
957 mono_gc_get_managed_allocator (MonoClass *klass, gboolean for_box, gboolean known_instance_size)
958 {
959         int offset = -1;
960         int atype;
961         MONO_THREAD_VAR_OFFSET (GC_thread_tls, offset);
962
963         /*g_print ("thread tls: %d\n", offset);*/
964         if (offset == -1)
965                 return NULL;
966         if (!SMALL_ENOUGH (klass->instance_size))
967                 return NULL;
968         if (mono_class_has_finalizer (klass) || mono_class_is_marshalbyref (klass) || (mono_profiler_get_events () & MONO_PROFILE_ALLOCATIONS))
969                 return NULL;
970         if (klass->rank)
971                 return NULL;
972         if (mono_class_is_open_constructed_type (&klass->byval_arg))
973                 return NULL;
974         if (klass->byval_arg.type == MONO_TYPE_STRING) {
975                 atype = ATYPE_STRING;
976         } else if (!klass->has_references) {
977                 if (for_box)
978                         atype = ATYPE_FREEPTR_FOR_BOX;
979                 else
980                         atype = ATYPE_FREEPTR;
981         } else {
982                 return NULL;
983                 /*
984                  * disabled because we currently do a runtime choice anyway, to
985                  * deal with multiple appdomains.
986                 if (vtable->gc_descr != GC_NO_DESCRIPTOR)
987                         atype = ATYPE_GCJ;
988                 else
989                         atype = ATYPE_NORMAL;
990                 */
991         }
992         return mono_gc_get_managed_allocator_by_type (atype);
993 }
994
995 MonoMethod*
996 mono_gc_get_managed_array_allocator (MonoClass *klass)
997 {
998         return NULL;
999 }
1000
1001 /**
1002  * mono_gc_get_managed_allocator_by_type:
1003  *
1004  *   Return a managed allocator method corresponding to allocator type ATYPE.
1005  */
1006 MonoMethod*
1007 mono_gc_get_managed_allocator_by_type (int atype)
1008 {
1009         int offset = -1;
1010         MonoMethod *res;
1011         MONO_THREAD_VAR_OFFSET (GC_thread_tls, offset);
1012
1013         mono_tls_key_set_offset (TLS_KEY_BOEHM_GC_THREAD, offset);
1014
1015         res = alloc_method_cache [atype];
1016         if (res)
1017                 return res;
1018
1019         res = create_allocator (atype, TLS_KEY_BOEHM_GC_THREAD);
1020         mono_mutex_lock (&mono_gc_lock);
1021         if (alloc_method_cache [atype]) {
1022                 mono_free_method (res);
1023                 res = alloc_method_cache [atype];
1024         } else {
1025                 mono_memory_barrier ();
1026                 alloc_method_cache [atype] = res;
1027         }
1028         mono_mutex_unlock (&mono_gc_lock);
1029         return res;
1030 }
1031
1032 guint32
1033 mono_gc_get_managed_allocator_types (void)
1034 {
1035         return ATYPE_NUM;
1036 }
1037
1038 MonoMethod*
1039 mono_gc_get_write_barrier (void)
1040 {
1041         g_assert_not_reached ();
1042         return NULL;
1043 }
1044
1045 #else
1046
1047 static G_GNUC_UNUSED gboolean
1048 mono_gc_is_critical_method (MonoMethod *method)
1049 {
1050         return FALSE;
1051 }
1052
1053 MonoMethod*
1054 mono_gc_get_managed_allocator (MonoClass *klass, gboolean for_box, gboolean known_instance_size)
1055 {
1056         return NULL;
1057 }
1058
1059 MonoMethod*
1060 mono_gc_get_managed_array_allocator (MonoClass *klass)
1061 {
1062         return NULL;
1063 }
1064
1065 MonoMethod*
1066 mono_gc_get_managed_allocator_by_type (int atype)
1067 {
1068         return NULL;
1069 }
1070
1071 guint32
1072 mono_gc_get_managed_allocator_types (void)
1073 {
1074         return 0;
1075 }
1076
1077 MonoMethod*
1078 mono_gc_get_write_barrier (void)
1079 {
1080         g_assert_not_reached ();
1081         return NULL;
1082 }
1083
1084 #endif
1085
1086 int
1087 mono_gc_get_aligned_size_for_allocator (int size)
1088 {
1089         return size;
1090 }
1091
1092 const char *
1093 mono_gc_get_gc_name (void)
1094 {
1095         return "boehm";
1096 }
1097
1098 void*
1099 mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data)
1100 {
1101         return GC_call_with_alloc_lock (func, data);
1102 }
1103
1104 char*
1105 mono_gc_get_description (void)
1106 {
1107         return g_strdup (DEFAULT_GC_NAME);
1108 }
1109
1110 void
1111 mono_gc_set_desktop_mode (void)
1112 {
1113         GC_dont_expand = 1;
1114 }
1115
1116 gboolean
1117 mono_gc_is_moving (void)
1118 {
1119         return FALSE;
1120 }
1121
1122 gboolean
1123 mono_gc_is_disabled (void)
1124 {
1125         if (GC_dont_gc || g_getenv ("GC_DONT_GC"))
1126                 return TRUE;
1127         else
1128                 return FALSE;
1129 }
1130
1131 void
1132 mono_gc_wbarrier_value_copy_bitmap (gpointer _dest, gpointer _src, int size, unsigned bitmap)
1133 {
1134         g_assert_not_reached ();
1135 }
1136
1137
1138 guint8*
1139 mono_gc_get_card_table (int *shift_bits, gpointer *card_mask)
1140 {
1141         g_assert_not_reached ();
1142         return NULL;
1143 }
1144
1145 gboolean
1146 mono_gc_card_table_nursery_check (void)
1147 {
1148         g_assert_not_reached ();
1149         return TRUE;
1150 }
1151
1152 void*
1153 mono_gc_get_nursery (int *shift_bits, size_t *size)
1154 {
1155         return NULL;
1156 }
1157
1158 void
1159 mono_gc_set_current_thread_appdomain (MonoDomain *domain)
1160 {
1161 }
1162
1163 gboolean
1164 mono_gc_precise_stack_mark_enabled (void)
1165 {
1166         return FALSE;
1167 }
1168
1169 FILE *
1170 mono_gc_get_logfile (void)
1171 {
1172         return NULL;
1173 }
1174
1175 void
1176 mono_gc_conservatively_scan_area (void *start, void *end)
1177 {
1178         g_assert_not_reached ();
1179 }
1180
1181 void *
1182 mono_gc_scan_object (void *obj, void *gc_data)
1183 {
1184         g_assert_not_reached ();
1185         return NULL;
1186 }
1187
1188 gsize*
1189 mono_gc_get_bitmap_for_descr (void *descr, int *numbits)
1190 {
1191         g_assert_not_reached ();
1192         return NULL;
1193 }
1194
1195 void
1196 mono_gc_set_gc_callbacks (MonoGCCallbacks *callbacks)
1197 {
1198 }
1199
1200 void
1201 mono_gc_set_stack_end (void *stack_end)
1202 {
1203 }
1204
1205 void mono_gc_set_skip_thread (gboolean value)
1206 {
1207 }
1208
1209 void
1210 mono_gc_register_for_finalization (MonoObject *obj, void *user_data)
1211 {
1212         guint offset = 0;
1213
1214 #ifndef GC_DEBUG
1215         /* This assertion is not valid when GC_DEBUG is defined */
1216         g_assert (GC_base (obj) == (char*)obj - offset);
1217 #endif
1218
1219         GC_REGISTER_FINALIZER_NO_ORDER ((char*)obj - offset, user_data, GUINT_TO_POINTER (offset), NULL, NULL);
1220 }
1221
1222 /*
1223  * These will call the redefined versions in libgc.
1224  */
1225
1226 #ifndef HOST_WIN32
1227
1228 int
1229 mono_gc_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
1230 {
1231         return pthread_create (new_thread, attr, start_routine, arg);
1232 }
1233
1234 int
1235 mono_gc_pthread_join (pthread_t thread, void **retval)
1236 {
1237         return pthread_join (thread, retval);
1238 }
1239
1240 int
1241 mono_gc_pthread_detach (pthread_t thread)
1242 {
1243         return pthread_detach (thread);
1244 }
1245
1246 void
1247 mono_gc_pthread_exit (void *retval)
1248 {
1249         pthread_exit (retval);
1250         g_assert_not_reached ();
1251 }
1252
1253 #endif
1254
1255 #ifdef HOST_WIN32
1256 BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reserved)
1257 {
1258 #ifdef USE_INCLUDED_LIBGC
1259         return GC_DllMain (module_handle, reason, reserved);
1260 #else
1261         return TRUE;
1262 #endif
1263 }
1264 #endif
1265
1266 guint
1267 mono_gc_get_vtable_bits (MonoClass *class)
1268 {
1269         if (fin_callbacks.is_class_finalization_aware) {
1270                 if (fin_callbacks.is_class_finalization_aware (class))
1271                         return BOEHM_GC_BIT_FINALIZER_AWARE;
1272         }
1273         return 0;
1274 }
1275
1276 /*
1277  * mono_gc_register_altstack:
1278  *
1279  *   Register the dimensions of the normal stack and altstack with the collector.
1280  * Currently, STACK/STACK_SIZE is only used when the thread is suspended while it is on an altstack.
1281  */
1282 void
1283 mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
1284 {
1285 #ifdef USE_INCLUDED_LIBGC
1286         GC_register_altstack (stack, stack_size, altstack, altstack_size);
1287 #endif
1288 }
1289
1290 int
1291 mono_gc_get_los_limit (void)
1292 {
1293         return G_MAXINT;
1294 }
1295
1296 void
1297 mono_gc_set_string_length (MonoString *str, gint32 new_length)
1298 {
1299         mono_unichar2 *new_end = str->chars + new_length;
1300         
1301         /* zero the discarded string. This null-delimits the string and allows 
1302          * the space to be reclaimed by SGen. */
1303          
1304         memset (new_end, 0, (str->length - new_length + 1) * sizeof (mono_unichar2));
1305         str->length = new_length;
1306 }
1307
1308 gboolean
1309 mono_gc_user_markers_supported (void)
1310 {
1311         return FALSE;
1312 }
1313
1314 void *
1315 mono_gc_make_root_descr_user (MonoGCRootMarkFunc marker)
1316 {
1317         g_assert_not_reached ();
1318         return NULL;
1319 }
1320
1321 gboolean
1322 mono_gc_set_allow_synchronous_major (gboolean flag)
1323 {
1324         return flag;
1325 }
1326 /* Toggleref support */
1327
1328 void
1329 mono_gc_toggleref_add (MonoObject *object, mono_bool strong_ref)
1330 {
1331         GC_toggleref_add ((GC_PTR)object, (int)strong_ref);
1332 }
1333
1334 void
1335 mono_gc_toggleref_register_callback (MonoToggleRefStatus (*proccess_toggleref) (MonoObject *obj))
1336 {
1337         GC_toggleref_register_callback ((int (*) (GC_PTR obj)) proccess_toggleref);
1338 }
1339
1340 /* Test support code */
1341
1342 static MonoToggleRefStatus
1343 test_toggleref_callback (MonoObject *obj)
1344 {
1345         static MonoClassField *mono_toggleref_test_field;
1346         int status = MONO_TOGGLE_REF_DROP;
1347
1348         if (!mono_toggleref_test_field) {
1349                 mono_toggleref_test_field = mono_class_get_field_from_name (mono_object_get_class (obj), "__test");
1350                 g_assert (mono_toggleref_test_field);
1351         }
1352
1353         mono_field_get_value (obj, mono_toggleref_test_field, &status);
1354         printf ("toggleref-cb obj %d\n", status);
1355         return status;
1356 }
1357
1358 static void
1359 register_test_toggleref_callback (void)
1360 {
1361         mono_gc_toggleref_register_callback (test_toggleref_callback);
1362 }
1363
1364 static gboolean
1365 is_finalization_aware (MonoObject *obj)
1366 {
1367         MonoVTable *vt = obj->vtable;
1368         return (vt->gc_bits & BOEHM_GC_BIT_FINALIZER_AWARE) == BOEHM_GC_BIT_FINALIZER_AWARE;
1369 }
1370
1371 static void
1372 fin_notifier (MonoObject *obj)
1373 {
1374         if (is_finalization_aware (obj))
1375                 fin_callbacks.object_queued_for_finalization (obj);
1376 }
1377
1378 void
1379 mono_gc_register_finalizer_callbacks (MonoGCFinalizerCallbacks *callbacks)
1380 {
1381         if (callbacks->version != MONO_GC_FINALIZER_EXTENSION_VERSION)
1382                 g_error ("Invalid finalizer callback version. Expected %d but got %d\n", MONO_GC_FINALIZER_EXTENSION_VERSION, callbacks->version);
1383
1384         fin_callbacks = *callbacks;
1385
1386         GC_set_finalizer_notify_proc ((void (*) (GC_PTR))fin_notifier);
1387 }
1388
1389 #endif /* no Boehm GC */