#define GC_finalize_on_demand __imp_GC_finalize_on_demand
#endif
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
+
static int finalize_slot = -1;
static gboolean gc_disabled = FALSE;
}
}
+gpointer
+mono_gc_out_of_memory (size_t size)
+{
+ /*
+ * we could allocate at program startup some memory that we could release
+ * back to the system at this point if we're really low on memory (ie, size is
+ * lower than the memory we set apart)
+ */
+ mono_raise_exception (mono_domain_get ()->out_of_memory_ex);
+
+ return NULL;
+}
+
/*
* Some of our objects may point to a different address than the address returned by GC_malloc()
* (because of the GetHashCode hack), but we need to pass the real address to register_finalizer.
return mono_array_addr ((MonoArray*)obj, char, 0);
} else {
/* the C# code will check and throw the exception */
- /* FIXME: missing !klass->blittable test, see bug #61134,
- * disabled in 1.0 untill the blittable-using code is audited.
+ /* FIXME: missing !klass->blittable test, see bug #61134 */
if ((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_AUTO_LAYOUT)
- return (gpointer)-1; */
+ return (gpointer)-1;
return (char*)obj + sizeof (MonoObject);
}
}
g_ptr_array_free (objs, TRUE);
}
+ /* Process finalizers which are already in the queue */
+ GC_invoke_finalizers ();
+
/* printf ("DONE.\n"); */
SetEvent (req->done_event);
mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_GC, msg, (unsigned long)arg);
}
+static gboolean
+mono_running_on_valgrind (void)
+{
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ if (RUNNING_ON_VALGRIND)
+ return TRUE;
+ else
+ return FALSE;
+#else
+ return FALSE;
+#endif
+}
+
+
void mono_gc_init (void)
{
InitializeCriticalSection (&handle_section);
#ifdef WITH_INCLUDED_LIBGC
gc_thread_vtable = &mono_gc_thread_vtable;
#endif
+
+ MONO_GC_REGISTER_ROOT (gc_handles);
+ MONO_GC_REGISTER_ROOT (gc_handle_types);
+ GC_no_dls = TRUE;
+
+ GC_oom_fn = mono_gc_out_of_memory;
+
+ GC_set_warn_proc (mono_gc_warning);
#ifdef ENABLE_FINALIZER_THREAD
return;
}
+ /* valgrind does not play nicely with the GC,
+ * so, turn it off when we are under vg.
+ */
+ if (mono_running_on_valgrind ()) {
+ /* valgrind doesnt like g_warning for some reason... */
+ printf ("You are running under valgrind. Currently, valgrind does "
+ "not support the GC. This program will run with the GC "
+ "turned off. Your program may take up a fair amount of "
+ "memory. Also, finalizers will not be run.");
+
+ gc_disabled = TRUE;
+ return;
+ }
+
finalizer_event = CreateEvent (NULL, FALSE, FALSE, NULL);
pending_done_event = CreateEvent (NULL, TRUE, FALSE, NULL);
shutdown_event = CreateEvent (NULL, TRUE, FALSE, NULL);