2 * metadata/gc.c: GC icalls.
4 * Author: Paolo Molaro <lupus@ximian.com>
6 * (C) 2002 Ximian, Inc.
13 #include <mono/metadata/gc.h>
14 #include <mono/metadata/threads.h>
19 static int finalize_slot = -1;
22 * actually, we might want to queue the finalize requests in a separate thread,
23 * but we need to be careful about the execution domain of the thread...
26 run_finalize (void *obj, void *data)
28 MonoObject *exc = NULL;
30 o = (MonoObject*)((char*)obj + GPOINTER_TO_UINT (data));
32 if (finalize_slot < 0) {
34 for (i = 0; i < mono_defaults.object_class->vtable_size; ++i) {
35 MonoMethod *cm = mono_defaults.object_class->vtable [i];
37 if (!strcmp (cm->name, "Finalize")) {
43 /* speedup later... */
44 /* g_print ("Finalize run on %s\n", mono_object_class (o)->name); */
45 mono_runtime_invoke (o->vtable->klass->vtable [finalize_slot], o, NULL, &exc);
48 /* fixme: do something useful */
53 * Some of our objects may point to a different address than the address returned by GC_malloc()
54 * (because of the GetHashCode hack), but we need to pass the real address to register_finalizer.
55 * This also means that in the callback we need to adjust the pointer to get back the real
57 * We also need to be consistent in the use of the GC_debug* variants of malloc and register_finalizer,
58 * since that, too, can cause the underlying pointer to be offset.
61 object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*))
66 g_assert (GC_base (obj) == (char*)obj - offset);
67 GC_register_finalizer ((char*)obj - offset, callback, GUINT_TO_POINTER (offset), NULL, NULL);
72 mono_object_register_finalizer (MonoObject *obj)
74 object_register_finalizer (obj, run_finalize);
78 ves_icall_System_GC_InternalCollect (int generation)
86 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection)
91 return GC_get_heap_size ();
98 ves_icall_System_GC_KeepAlive (MonoObject *obj)
106 ves_icall_System_GC_ReRegisterForFinalize (MonoObject *obj)
108 object_register_finalizer (obj, run_finalize);
112 ves_icall_System_GC_SuppressFinalize (MonoObject *obj)
114 object_register_finalizer (obj, NULL);
118 ves_icall_System_GC_WaitForPendingFinalizers (void)