New test.
[mono.git] / mono / metadata / boehm-gc.c
index 53d2832c6f0792a92f626aacd26c8c379f0e4b27..711343f3ecc8f75a39e0b12f6c727becc2a236b4 100644 (file)
@@ -16,7 +16,8 @@
 #include <mono/metadata/opcodes.h>
 #include <mono/metadata/domain-internals.h>
 #include <mono/metadata/metadata-internals.h>
-#include <mono/utils/mono-logger.h>
+#include <mono/metadata/marshal.h>
+#include <mono/utils/mono-logger-internal.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/dtrace.h>
 
@@ -95,7 +96,10 @@ mono_gc_base_init (void)
        }
 #endif
 
+#if !defined(PLATFORM_ANDROID)
+       /* If GC_no_dls is set to true, GC_find_limit is not called. This causes a seg fault on Android. */
        GC_no_dls = TRUE;
+#endif
        GC_init ();
        GC_oom_fn = mono_gc_out_of_memory;
        GC_set_warn_proc (mono_gc_warning);
@@ -219,7 +223,7 @@ mono_gc_register_thread (void *baseptr)
 #else
        if (mono_gc_is_gc_thread())
                return TRUE;
-#if defined(USE_INCLUDED_LIBGC) && !defined(PLATFORM_WIN32)
+#if defined(USE_INCLUDED_LIBGC) && !defined(HOST_WIN32)
        return GC_thread_register_foreign (baseptr);
 #else
        return FALSE;
@@ -299,7 +303,7 @@ mono_gc_register_root (char *start, size_t size, void *descr)
 void
 mono_gc_deregister_root (char* addr)
 {
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
        /* FIXME: libgc doesn't define this work win32 for some reason */
        /* FIXME: No size info */
        GC_remove_roots (addr, addr + sizeof (gpointer) + 1);
@@ -321,10 +325,17 @@ mono_gc_weak_link_remove (void **link_addr)
        *link_addr = NULL;
 }
 
+static gpointer
+reveal_link (gpointer link_addr)
+{
+       void **link_a = link_addr;
+       return REVEAL_POINTER (*link_a);
+}
+
 MonoObject*
 mono_gc_weak_link_get (void **link_addr)
 {
-       MonoObject *obj = REVEAL_POINTER (*link_addr);
+       MonoObject *obj = GC_call_with_alloc_lock (reveal_link, link_addr);
        if (obj == (MonoObject *) -1)
                return NULL;
        return obj;
@@ -563,7 +574,11 @@ mono_gc_clear_domain (MonoDomain *domain)
 int
 mono_gc_get_suspend_signal (void)
 {
+#ifdef USE_INCLUDED_GC
        return GC_get_suspend_signal ();
+#else
+       return -1;
+#endif
 }
 
 #if defined(USE_INCLUDED_LIBGC) && defined(USE_COMPILER_TLS) && defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
@@ -597,6 +612,7 @@ create_allocator (int atype, int offset)
        MonoMethodBuilder *mb;
        MonoMethod *res;
        MonoMethodSignature *csig;
+       AllocatorWrapperInfo *info;
 
        if (atype == ATYPE_STRING) {
                csig = mono_metadata_signature_alloc (mono_defaults.corlib, 2);
@@ -784,6 +800,11 @@ create_allocator (int atype, int offset)
        res = mono_mb_create_method (mb, csig, 8);
        mono_mb_free (mb);
        mono_method_get_header (res)->init_locals = FALSE;
+
+       info = mono_image_alloc0 (mono_defaults.corlib, sizeof (AllocatorWrapperInfo));
+       info->alloc_type = atype;
+       mono_marshal_set_wrapper_info (res, info);
+
        return res;
 }
 
@@ -843,30 +864,6 @@ mono_gc_get_managed_array_allocator (MonoVTable *vtable, int rank)
        return NULL;
 }
 
-/**
- * mono_gc_get_managed_allocator_id:
- *
- *   Return a type for the managed allocator method MANAGED_ALLOC which can later be passed
- * to mono_gc_get_managed_allocator_by_type () to get back this allocator method. This can be
- * used by the AOT code to encode references to managed allocator methods.
- */
-int
-mono_gc_get_managed_allocator_type (MonoMethod *managed_alloc)
-{
-       int i;
-
-       mono_loader_lock ();
-       for (i = 0; i < ATYPE_NUM; ++i) {
-               if (alloc_method_cache [i] == managed_alloc) {
-                       mono_loader_unlock ();
-                       return i;
-               }
-       }
-       mono_loader_unlock ();
-
-       return -1;
-}
-
 /**
  * mono_gc_get_managed_allocator_by_type:
  *
@@ -893,6 +890,13 @@ mono_gc_get_managed_allocator_types (void)
        return ATYPE_NUM;
 }
 
+MonoMethod*
+mono_gc_get_write_barrier (void)
+{
+       g_assert_not_reached ();
+       return NULL;
+}
+
 #else
 
 MonoMethod*
@@ -907,12 +911,6 @@ mono_gc_get_managed_array_allocator (MonoVTable *vtable, int rank)
        return NULL;
 }
 
-int
-mono_gc_get_managed_allocator_type (MonoMethod *managed_alloc)
-{
-       return -1;
-}
-
 MonoMethod*
 mono_gc_get_managed_allocator_by_type (int atype)
 {
@@ -925,7 +923,20 @@ mono_gc_get_managed_allocator_types (void)
        return 0;
 }
 
+MonoMethod*
+mono_gc_get_write_barrier (void)
+{
+       g_assert_not_reached ();
+       return NULL;
+}
+
 #endif
 
+void*
+mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data)
+{
+       return GC_call_with_alloc_lock (func, data);
+}
+
 #endif /* no Boehm GC */