static gboolean gc_disabled = FALSE;
+#define mono_finalizer_lock() EnterCriticalSection (&finalizer_mutex)
+#define mono_finalizer_unlock() LeaveCriticalSection (&finalizer_mutex)
static CRITICAL_SECTION finalizer_mutex;
static GSList *domains_to_finalize= NULL;
static void object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*));
-#if HAVE_BOEHM_GC
-static void finalize_notify (void);
+#ifndef HAVE_NULL_GC
static HANDLE pending_done_event;
static HANDLE shutdown_event;
static HANDLE thread_started_event;
MonoObject *o, *o2;
o = (MonoObject*)((char*)obj + GPOINTER_TO_UINT (data));
+#ifndef HAVE_SGEN_GC
mono_domain_lock (o->vtable->domain);
o2 = g_hash_table_lookup (o->vtable->domain->finalizable_objects_hash, o);
if (!o2)
/* Already finalized somehow */
return;
+#endif
/* make sure the finalizer is not called again if the object is resurrected */
object_register_finalizer (obj, NULL);
mono_domain_unlock (obj->vtable->domain);
GC_REGISTER_FINALIZER_NO_ORDER ((char*)obj - offset, callback, GUINT_TO_POINTER (offset), NULL, NULL);
+#elif defined(HAVE_SGEN_GC)
+ mono_gc_register_for_finalization (obj, callback);
#endif
}
* is still working and will take care of running the finalizers
*/
-#if HAVE_BOEHM_GC
+#ifndef HAVE_NULL_GC
if (gc_disabled)
return TRUE;
- GC_gcollect ();
+ mono_gc_collect (mono_gc_max_generation ());
done_event = CreateEvent (NULL, TRUE, FALSE, NULL);
req->domain = domain;
req->done_event = done_event;
- EnterCriticalSection (&finalizer_mutex);
+ mono_finalizer_lock ();
domains_to_finalize = g_slist_append (domains_to_finalize, req);
- LeaveCriticalSection (&finalizer_mutex);
+ mono_finalizer_unlock ();
/* Tell the finalizer thread to finalize this appdomain */
- finalize_notify ();
+ mono_gc_finalize_notify ();
res = WaitForSingleObjectEx (done_event, timeout, TRUE);
{
MONO_ARCH_SAVE_REGS;
-#if HAVE_BOEHM_GC
- if (!GC_should_invoke_finalizers ())
+#ifndef HAVE_NULL_GC
+ if (!mono_gc_pending_finalizers ())
return;
if (mono_thread_current () == gc_thread)
return;
ResetEvent (pending_done_event);
- finalize_notify ();
+ mono_gc_finalize_notify ();
/* g_print ("Waiting for pending finalizers....\n"); */
WaitForSingleObjectEx (pending_done_event, INFINITE, TRUE);
/* g_print ("Done pending....\n"); */
#else
#endif
}
-
+#define mono_allocator_lock() EnterCriticalSection (&allocator_section)
+#define mono_allocator_unlock() LeaveCriticalSection (&allocator_section)
static CRITICAL_SECTION allocator_section;
static CRITICAL_SECTION handle_section;
if (slot < handles->size && (handles->bitmap [slot / 32] & (1 << (slot % 32)))) {
if (handles->type <= HANDLE_WEAK_TRACK)
mono_gc_weak_link_remove (&handles->entries [slot]);
- handles->entries [slot] = NULL;
+ else
+ handles->entries [slot] = NULL;
handles->bitmap [slot / 32] &= ~(1 << (slot % 32));
} else {
/* print a warning? */
unlock_handles (handles);
}
-#if HAVE_BOEHM_GC
+#ifndef HAVE_NULL_GC
static HANDLE finalizer_event;
static volatile gboolean finished=FALSE;
-static void finalize_notify (void)
+void
+mono_gc_finalize_notify (void)
{
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": prodding finalizer");
}
/* Process finalizers which are already in the queue */
- GC_invoke_finalizers ();
+ mono_gc_invoke_finalizers ();
/* printf ("DONE.\n"); */
SetEvent (req->done_event);
WaitForSingleObjectEx (finalizer_event, INFINITE, TRUE);
if (domains_to_finalize) {
- EnterCriticalSection (&finalizer_mutex);
+ mono_finalizer_lock ();
if (domains_to_finalize) {
DomainFinalizationReq *req = domains_to_finalize->data;
domains_to_finalize = g_slist_remove (domains_to_finalize, req);
- LeaveCriticalSection (&finalizer_mutex);
+ mono_finalizer_unlock ();
finalize_domain_objects (req);
}
else
- LeaveCriticalSection (&finalizer_mutex);
+ mono_finalizer_unlock ();
}
#ifdef DEBUG
/* If finished == TRUE, mono_gc_cleanup has been called (from mono_runtime_cleanup),
* before the domain is unloaded.
- *
- * There is a bug in GC_invoke_finalizer () in versions <= 6.2alpha4:
- * the 'mem_freed' variable is not initialized when there are no
- * objects to finalize, which leads to strange behavior later on.
- * The check is necessary to work around that bug.
*/
- if (GC_should_invoke_finalizers ()) {
- GC_invoke_finalizers ();
- }
+ mono_gc_invoke_finalizers ();
SetEvent (pending_done_event);
}
*/
#define ENABLE_FINALIZER_THREAD
-#ifdef WITH_INCLUDED_LIBGC
-/* from threads.c */
-extern void mono_gc_stop_world (void);
-extern void mono_gc_start_world (void);
-extern void mono_gc_push_all_stacks (void);
-
-static void mono_gc_lock (void)
-{
- EnterCriticalSection (&allocator_section);
-}
-
-static void mono_gc_unlock (void)
-{
- LeaveCriticalSection (&allocator_section);
-}
-
-static GCThreadFunctions mono_gc_thread_vtable = {
- NULL,
-
- mono_gc_lock,
- mono_gc_unlock,
-
- mono_gc_stop_world,
- NULL,
- mono_gc_push_all_stacks,
- mono_gc_start_world
-};
-#endif /* WITH_INCLUDED_LIBGC */
-
-static void
-mono_gc_warning (char *msg, GC_word arg)
-{
- mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_GC, msg, (unsigned long)arg);
-}
-
-void mono_gc_init (void)
+void
+mono_gc_init (void)
{
InitializeCriticalSection (&handle_section);
InitializeCriticalSection (&allocator_section);
InitializeCriticalSection (&finalizer_mutex);
-#ifdef WITH_INCLUDED_LIBGC
- gc_thread_vtable = &mono_gc_thread_vtable;
-#endif
-
MONO_GC_REGISTER_ROOT (gc_handles [HANDLE_NORMAL].entries);
MONO_GC_REGISTER_ROOT (gc_handles [HANDLE_PINNED].entries);
- GC_no_dls = TRUE;
- GC_oom_fn = mono_gc_out_of_memory;
-
- GC_set_warn_proc (mono_gc_warning);
+ mono_gc_base_init ();
#ifdef ENABLE_FINALIZER_THREAD
g_assert_not_reached ();
}
- GC_finalize_on_demand = 1;
- GC_finalizer_notifier = finalize_notify;
-
mono_thread_create (mono_domain_get (), finalizer_thread, NULL);
/*
* Wait until the finalizer thread sets gc_thread since its value is needed
ResetEvent (shutdown_event);
finished = TRUE;
if (mono_thread_current () != gc_thread) {
- finalize_notify ();
+ mono_gc_finalize_notify ();
/* Finishing the finalizer thread, so wait a little bit... */
/* MS seems to wait for about 2 seconds */
if (WaitForSingleObjectEx (shutdown_event, 2000, FALSE) == WAIT_TIMEOUT) {
}
}
gc_thread = NULL;
+#ifdef HAVE_BOEHM_GC
GC_finalizer_notifier = NULL;
+#endif
}
#endif