Add some debug logging to lookup_data_table () to help track down why it asserts...
[mono.git] / mono / metadata / boehm-gc.c
index 0d5554dcf916be7f3d91188d0834af84b1bbc706..b7a5c79e5d9be9d7151a5d9fd724a6b18886cfc7 100644 (file)
@@ -2,7 +2,8 @@
  * boehm-gc.c: GC implementation using either the installed or included Boehm GC.
  *
  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
- * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
+ * Copyright 2011-2012 Xamarin, Inc (http://www.xamarin.com)
  */
 
 #include "config.h"
@@ -20,6 +21,7 @@
 #include <mono/metadata/domain-internals.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/runtime.h>
 #include <mono/utils/mono-logger-internal.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-threads.h>
 #include "private/pthread_support.h"
 #endif
 
+#if defined(PLATFORM_MACOSX) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
+void *pthread_get_stackaddr_np(pthread_t);
+#endif
+
 #define GC_NO_DESCRIPTOR ((gpointer)(0 | GC_DS_LENGTH))
 /*Boehm max heap cannot be smaller than 16MB*/
 #define MIN_BOEHM_MAX_HEAP_SIZE_IN_MB 16
@@ -161,9 +167,12 @@ mono_gc_base_init (void)
                                }
                                continue;
                        } else {
+                               /* Could be a parameter for sgen */
+                               /*
                                fprintf (stderr, "MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:\n");
                                fprintf (stderr, "  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)\n");
                                exit (1);
+                               */
                        }
                }
                g_strfreev (opts);
@@ -171,6 +180,11 @@ mono_gc_base_init (void)
 
        memset (&cb, 0, sizeof (cb));
        cb.thread_register = boehm_thread_register;
+       cb.mono_method_is_critical = (gpointer)mono_runtime_is_critical_method;
+#ifndef HOST_WIN32
+       cb.mono_gc_pthread_create = (gpointer)mono_gc_pthread_create;
+#endif
+       
        mono_threads_init (&cb, sizeof (MonoThreadInfo));
 
        mono_gc_enable_events ();
@@ -192,16 +206,18 @@ mono_gc_base_init (void)
 void
 mono_gc_collect (int generation)
 {
-       MONO_PROBE_GC_BEGIN (generation);
+       MONO_GC_BEGIN (generation);
 
+#ifndef DISABLE_PERFCOUNTERS
        mono_perfcounters->gc_induced++;
+#endif
        GC_gcollect ();
        
-       MONO_PROBE_GC_END (generation);
+       MONO_GC_END (generation);
 #if defined(ENABLE_DTRACE) && defined(__sun__)
        /* This works around a dtrace -G problem on Solaris.
           Limit its actual use to when the probe is enabled. */
-       if (MONO_PROBE_GC_END_ENABLED ())
+       if (MONO_GC_END_ENABLED ())
                sleep(0);
 #endif
 }
@@ -390,18 +406,30 @@ on_gc_notification (GCEventType event)
 {
        MonoGCEvent e = (MonoGCEvent)event;
 
+       if (e == MONO_GC_EVENT_PRE_STOP_WORLD) 
+               mono_thread_info_suspend_lock ();
+       else if (e == MONO_GC_EVENT_POST_START_WORLD)
+               mono_thread_info_suspend_unlock ();
+       
        if (e == MONO_GC_EVENT_START) {
-               mono_perfcounters->gc_collections0++;
-               mono_stats.major_gc_count ++;
+#ifndef DISABLE_PERFCOUNTERS
+               if (mono_perfcounters)
+                       mono_perfcounters->gc_collections0++;
+#endif
+               gc_stats.major_gc_count ++;
                gc_start_time = mono_100ns_ticks ();
        } else if (e == MONO_GC_EVENT_END) {
-               guint64 heap_size = GC_get_heap_size ();
-               guint64 used_size = heap_size - GC_get_free_bytes ();
-               mono_perfcounters->gc_total_bytes = used_size;
-               mono_perfcounters->gc_committed_bytes = heap_size;
-               mono_perfcounters->gc_reserved_bytes = heap_size;
-               mono_perfcounters->gc_gen0size = heap_size;
-               mono_stats.major_gc_time_usecs += (mono_100ns_ticks () - gc_start_time) / 10;
+#ifndef DISABLE_PERFCOUNTERS
+               if (mono_perfcounters) {
+                       guint64 heap_size = GC_get_heap_size ();
+                       guint64 used_size = heap_size - GC_get_free_bytes ();
+                       mono_perfcounters->gc_total_bytes = used_size;
+                       mono_perfcounters->gc_committed_bytes = heap_size;
+                       mono_perfcounters->gc_reserved_bytes = heap_size;
+                       mono_perfcounters->gc_gen0size = heap_size;
+               }
+#endif
+               gc_stats.major_gc_time_usecs += (mono_100ns_ticks () - gc_start_time) / 10;
                mono_trace_message (MONO_TRACE_GC, "gc took %d usecs", (mono_100ns_ticks () - gc_start_time) / 10);
        }
        mono_profiler_gc_event (e, 0);
@@ -411,9 +439,13 @@ static void
 on_gc_heap_resize (size_t new_size)
 {
        guint64 heap_size = GC_get_heap_size ();
-       mono_perfcounters->gc_committed_bytes = heap_size;
-       mono_perfcounters->gc_reserved_bytes = heap_size;
-       mono_perfcounters->gc_gen0size = heap_size;
+#ifndef DISABLE_PERFCOUNTERS
+       if (mono_perfcounters) {
+               mono_perfcounters->gc_committed_bytes = heap_size;
+               mono_perfcounters->gc_reserved_bytes = heap_size;
+               mono_perfcounters->gc_gen0size = heap_size;
+       }
+#endif
        mono_profiler_gc_heap_resize (new_size);
 }
 
@@ -686,7 +718,7 @@ mono_gc_wbarrier_set_arrayref (MonoArray *arr, gpointer slot_ptr, MonoObject* va
 void
 mono_gc_wbarrier_arrayref_copy (gpointer dest_ptr, gpointer src_ptr, int count)
 {
-       memmove (dest_ptr, src_ptr, count * sizeof (gpointer));
+       mono_gc_memmove (dest_ptr, src_ptr, count * sizeof (gpointer));
 }
 
 void
@@ -703,14 +735,14 @@ mono_gc_wbarrier_generic_nostore (gpointer ptr)
 void
 mono_gc_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *klass)
 {
-       memmove (dest, src, count * mono_class_value_size (klass, NULL));
+       mono_gc_memmove (dest, src, count * mono_class_value_size (klass, NULL));
 }
 
 void
 mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
 {
        /* do not copy the sync state */
-       memcpy ((char*)obj + sizeof (MonoObject), (char*)src + sizeof (MonoObject),
+       mono_gc_memmove ((char*)obj + sizeof (MonoObject), (char*)src + sizeof (MonoObject),
                        mono_object_class (obj)->instance_size - sizeof (MonoObject));
 }
 
@@ -959,12 +991,10 @@ create_allocator (int atype, int offset)
 
 static MonoMethod* alloc_method_cache [ATYPE_NUM];
 
-gboolean
+static G_GNUC_UNUSED gboolean
 mono_gc_is_critical_method (MonoMethod *method)
 {
        int i;
-       if (method == write_barrier_method)
-               return TRUE;
 
        for (i = 0; i < ATYPE_NUM; ++i)
                if (method == alloc_method_cache [i])
@@ -1062,7 +1092,7 @@ mono_gc_get_write_barrier (void)
 
 #else
 
-gboolean
+static G_GNUC_UNUSED gboolean
 mono_gc_is_critical_method (MonoMethod *method)
 {
        return FALSE;
@@ -1160,6 +1190,11 @@ mono_gc_get_nursery (int *shift_bits, size_t *size)
        return NULL;
 }
 
+void
+mono_gc_set_current_thread_appdomain (MonoDomain *domain)
+{
+}
+
 gboolean
 mono_gc_precise_stack_mark_enabled (void)
 {
@@ -1197,6 +1232,15 @@ mono_gc_set_gc_callbacks (MonoGCCallbacks *callbacks)
 {
 }
 
+void
+mono_gc_set_stack_end (void *stack_end)
+{
+}
+
+void mono_gc_set_skip_thread (gboolean value)
+{
+}
+
 /*
  * These will call the redefined versions in libgc.
  */
@@ -1206,7 +1250,7 @@ mono_gc_set_gc_callbacks (MonoGCCallbacks *callbacks)
 int
 mono_gc_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
 {
-       return mono_threads_pthread_create (new_thread, attr, start_routine, arg);
+       return pthread_create (new_thread, attr, start_routine, arg);
 }
 
 int
@@ -1221,6 +1265,12 @@ mono_gc_pthread_detach (pthread_t thread)
        return pthread_detach (thread);
 }
 
+void
+mono_gc_pthread_exit (void *retval)
+{
+       pthread_exit (retval);
+}
+
 #endif
 
 #ifdef HOST_WIN32
@@ -1234,4 +1284,43 @@ BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reser
 }
 #endif
 
+guint
+mono_gc_get_vtable_bits (MonoClass *class)
+{
+       return 0;
+}
+
+/*
+ * mono_gc_register_altstack:
+ *
+ *   Register the dimensions of the normal stack and altstack with the collector.
+ * Currently, STACK/STACK_SIZE is only used when the thread is suspended while it is on an altstack.
+ */
+void
+mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
+{
+#ifdef USE_INCLUDED_LIBGC
+       GC_register_altstack (stack, stack_size, altstack, altstack_size);
+#endif
+}
+
+int
+mono_gc_get_los_limit (void)
+{
+       return G_MAXINT;
+}
+
+gboolean
+mono_gc_user_markers_supported (void)
+{
+       return FALSE;
+}
+
+void *
+mono_gc_make_root_descr_user (MonoGCRootMarkFunc marker)
+{
+       g_assert_not_reached ();
+       return NULL;
+}
+
 #endif /* no Boehm GC */