2 * metadata/gc.c: GC icalls.
4 * Author: Paolo Molaro <lupus@ximian.com>
6 * (C) 2002 Ximian, Inc.
12 #include <mono/metadata/gc.h>
13 #include <mono/metadata/threads.h>
18 static int finalize_slot = -1;
21 * actually, we might want to queue the finalize requests in a separate thread,
22 * but we need to be careful about the execution domain of the thread...
25 run_finalize (void *obj, void *data)
28 o = (MonoObject*)((char*)obj + GPOINTER_TO_UINT (data));
30 if (finalize_slot < 0) {
32 for (i = 0; i < mono_defaults.object_class->vtable_size; ++i) {
33 MonoMethod *cm = mono_defaults.object_class->vtable [i];
35 if (!strcmp (cm->name, "Finalize")) {
41 /* speedup later... */
43 * mono crashes (see bug#23778)
44 g_print ("finalizer is run on %s at %p\n", mono_object_class(o)->name, o);
45 mono_runtime_invoke (o->vtable->klass->vtable [finalize_slot], obj, NULL);
50 * Some of our objects may point to a different address than the address returned by GC_malloc()
51 * (because of the GetHashCode hack), but we need to pass the real address to register_finalizer.
52 * This also means that in the callback we need to adjust the pointer to get back the real
54 * We also need to be consistent in the use of the GC_debug* variants of malloc and register_finalizer,
55 * since that, too, can cause the underlying pointer to be offset.
58 object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*))
62 if (mono_object_class (obj)->ghcimpl)
64 /*g_print ("registering %s at %p (base: %p)\n", mono_object_class (obj)->name, obj, GC_base (obj));*/
65 GC_register_finalizer ((char*)obj - offset, run_finalize, GUINT_TO_POINTER (offset), NULL, NULL);
70 mono_object_register_finalizer (MonoObject *obj)
72 object_register_finalizer (obj, run_finalize);
76 ves_icall_System_GC_InternalCollect (int generation)
84 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection)
89 return GC_get_heap_size ();
96 ves_icall_System_GC_KeepAlive (MonoObject *obj)
104 ves_icall_System_GC_ReRegisterForFinalize (MonoObject *obj)
106 object_register_finalizer (obj, run_finalize);
110 ves_icall_System_GC_SuppressFinalize (MonoObject *obj)
112 object_register_finalizer (obj, NULL);
116 ves_icall_System_GC_WaitForPendingFinalizers (void)