X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fboehm-gc.c;h=2c648c85da6d7bf8bb36a165c5931bafe013fe3a;hb=60b660d2180f2fa8cd4824875f7d88ff7760172b;hp=43844ad98304cfed42194dc622df44a161fe27ab;hpb=3e81958f1dd4cecb97167c5b3cb5541bda31c444;p=mono.git diff --git a/mono/metadata/boehm-gc.c b/mono/metadata/boehm-gc.c index 43844ad9830..2c648c85da6 100644 --- a/mono/metadata/boehm-gc.c +++ b/mono/metadata/boehm-gc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,8 @@ boehm_thread_register (MonoThreadInfo* info, void *baseptr); static void boehm_thread_unregister (MonoThreadInfo *p); static void +boehm_thread_detach (MonoThreadInfo *p); +static void register_test_toggleref_callback (void); #define BOEHM_GC_BIT_FINALIZER_AWARE 1 @@ -96,6 +99,9 @@ mono_gc_warning (char *msg, GC_word arg) mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_GC, msg, (unsigned long)arg); } +static void on_gc_notification (GC_EventType event); +static void on_gc_heap_resize (size_t new_size); + void mono_gc_base_init (void) { @@ -108,6 +114,10 @@ mono_gc_base_init (void) mono_counters_init (); +#ifndef HOST_WIN32 + mono_w32handle_init (); +#endif + /* * Handle the case when we are called from a thread different from the main thread, * confusing libgc. @@ -235,6 +245,7 @@ mono_gc_base_init (void) memset (&cb, 0, sizeof (cb)); cb.thread_register = boehm_thread_register; cb.thread_unregister = boehm_thread_unregister; + cb.thread_detach = boehm_thread_detach; cb.mono_method_is_critical = (gboolean (*)(void *))mono_runtime_is_critical_method; mono_threads_init (&cb, sizeof (MonoThreadInfo)); @@ -243,7 +254,8 @@ mono_gc_base_init (void) mono_thread_info_attach (&dummy); - mono_gc_enable_events (); + GC_set_on_collection_event (on_gc_notification); + GC_on_heap_resize = on_gc_heap_resize; MONO_GC_REGISTER_ROOT_FIXED (gc_handles [HANDLE_NORMAL].entries, MONO_ROOT_SOURCE_GC_HANDLE, "gc handles table"); MONO_GC_REGISTER_ROOT_FIXED (gc_handles [HANDLE_PINNED].entries, MONO_ROOT_SOURCE_GC_HANDLE, "gc handles table"); @@ -388,6 +400,9 @@ boehm_thread_register (MonoThreadInfo* info, void *baseptr) res = GC_register_my_thread (&sb); if (res == GC_UNIMPLEMENTED) return NULL; /* Cannot happen with GC v7+. */ + + info->handle_stack = mono_handle_stack_alloc (); + return info; } @@ -402,6 +417,13 @@ boehm_thread_unregister (MonoThreadInfo *p) mono_threads_add_joinable_thread ((gpointer)tid); } +static void +boehm_thread_detach (MonoThreadInfo *p) +{ + if (mono_thread_internal_current_is_attached ()) + mono_thread_detach_internal (mono_thread_internal_current ()); +} + gboolean mono_object_is_alive (MonoObject* o) { @@ -424,7 +446,6 @@ on_gc_notification (GC_EventType event) switch (e) { case MONO_GC_EVENT_PRE_STOP_WORLD: MONO_GC_WORLD_STOP_BEGIN (); - mono_thread_info_suspend_lock (); break; case MONO_GC_EVENT_POST_STOP_WORLD: @@ -437,7 +458,6 @@ on_gc_notification (GC_EventType event) case MONO_GC_EVENT_POST_START_WORLD: MONO_GC_WORLD_RESTART_END (1); - mono_thread_info_suspend_unlock (); break; case MONO_GC_EVENT_START: @@ -477,7 +497,21 @@ on_gc_notification (GC_EventType event) } mono_profiler_gc_event (e, 0); + + switch (e) { + case MONO_GC_EVENT_PRE_STOP_WORLD: + mono_thread_info_suspend_lock (); + mono_profiler_gc_event (MONO_GC_EVENT_PRE_STOP_WORLD_LOCKED, 0); + break; + case MONO_GC_EVENT_POST_START_WORLD: + mono_thread_info_suspend_unlock (); + mono_profiler_gc_event (MONO_GC_EVENT_POST_START_WORLD_UNLOCKED, 0); + break; + default: + break; + } } + static void on_gc_heap_resize (size_t new_size) @@ -493,21 +527,6 @@ on_gc_heap_resize (size_t new_size) mono_profiler_gc_heap_resize (new_size); } -void -mono_gc_enable_events (void) -{ - GC_set_on_collection_event (on_gc_notification); - GC_on_heap_resize = on_gc_heap_resize; -} - -static gboolean alloc_events = FALSE; - -void -mono_gc_enable_alloc_events (void) -{ - alloc_events = TRUE; -} - int mono_gc_register_root (char *start, size_t size, void *descr, MonoGCRootSource source, const char *msg) { @@ -649,7 +668,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size) obj->vtable = vtable; } - if (G_UNLIKELY (alloc_events)) + if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_ALLOCATIONS)) mono_profiler_allocation (obj); return obj; @@ -683,7 +702,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length) obj->max_length = max_length; - if (G_UNLIKELY (alloc_events)) + if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_ALLOCATIONS)) mono_profiler_allocation (&obj->obj); return obj; @@ -720,7 +739,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint if (bounds_size) obj->bounds = (MonoArrayBounds *) ((char *) obj + size - bounds_size); - if (G_UNLIKELY (alloc_events)) + if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_ALLOCATIONS)) mono_profiler_allocation (&obj->obj); return obj; @@ -738,7 +757,7 @@ mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len) obj->length = len; obj->chars [len] = 0; - if (G_UNLIKELY (alloc_events)) + if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_ALLOCATIONS)) mono_profiler_allocation (&obj->object); return obj; @@ -769,7 +788,7 @@ mono_gc_invoke_finalizers (void) return 0; } -gboolean +MonoBoolean mono_gc_pending_finalizers (void) { return GC_should_invoke_finalizers (); @@ -829,6 +848,11 @@ mono_gc_clear_domain (MonoDomain *domain) { } +void +mono_gc_suspend_finalizers (void) +{ +} + int mono_gc_get_suspend_signal (void) { @@ -1125,7 +1149,9 @@ mono_gc_get_managed_allocator (MonoClass *klass, gboolean for_box, gboolean know return NULL; if (!SMALL_ENOUGH (klass->instance_size)) return NULL; - if (mono_class_has_finalizer (klass) || mono_class_is_marshalbyref (klass) || (mono_profiler_get_events () & MONO_PROFILE_ALLOCATIONS)) + if (mono_class_has_finalizer (klass) || mono_class_is_marshalbyref (klass)) + return NULL; + if (mono_profiler_get_events () & (MONO_PROFILE_ALLOCATIONS | MONO_PROFILE_STATISTICAL)) return NULL; if (klass->rank) return NULL; @@ -1151,7 +1177,7 @@ mono_gc_get_managed_allocator (MonoClass *klass, gboolean for_box, gboolean know atype = ATYPE_NORMAL; */ } - return mono_gc_get_managed_allocator_by_type (atype, FALSE); + return mono_gc_get_managed_allocator_by_type (atype, MANAGED_ALLOCATOR_REGULAR); } MonoMethod* @@ -1166,10 +1192,11 @@ mono_gc_get_managed_array_allocator (MonoClass *klass) * Return a managed allocator method corresponding to allocator type ATYPE. */ MonoMethod* -mono_gc_get_managed_allocator_by_type (int atype, gboolean slowpath) +mono_gc_get_managed_allocator_by_type (int atype, ManagedAllocatorVariant variant) { int offset = -1; MonoMethod *res; + gboolean slowpath = variant != MANAGED_ALLOCATOR_REGULAR; MonoMethod **cache = slowpath ? slowpath_alloc_method_cache : alloc_method_cache; MONO_THREAD_VAR_OFFSET (GC_thread_tls, offset); @@ -1226,7 +1253,7 @@ mono_gc_get_managed_array_allocator (MonoClass *klass) } MonoMethod* -mono_gc_get_managed_allocator_by_type (int atype, gboolean slowpath) +mono_gc_get_managed_allocator_by_type (int atype, ManagedAllocatorVariant variant) { return NULL; } @@ -1325,11 +1352,6 @@ 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) { @@ -1342,6 +1364,16 @@ mono_gc_get_logfile (void) return NULL; } +void +mono_gc_params_set (const char* options) +{ +} + +void +mono_gc_debug_set (const char* options) +{ +} + void mono_gc_conservatively_scan_area (void *start, void *end) { @@ -1904,5 +1936,10 @@ mono_gchandle_free_domain (MonoDomain *domain) } } +#else +#ifdef _MSC_VER +// Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty. +void __mono_win32_boehm_gc_quiet_lnk4221(void) {} +#endif #endif /* no Boehm GC */