[sgen] When out of memory, finish concurrent with scanning whole nursery. Fixes...
[mono.git] / mono / mini / mini-trampolines.c
index 5de69085b60b2b74f26e9fc62774bf7e525d6a40..d8f1e4298e956e681b2b67aeffe75750005c678a 100644 (file)
@@ -13,6 +13,7 @@
 #include <mono/utils/mono-counters.h>
 #include <mono/utils/mono-error-internals.h>
 #include <mono/utils/mono-membar.h>
+#include <mono/utils/mono-compiler.h>
 
 #include "mini.h"
 
@@ -27,9 +28,9 @@ static GHashTable *rgctx_lazy_fetch_trampoline_hash;
 static GHashTable *rgctx_lazy_fetch_trampoline_hash_addr;
 static guint32 trampoline_calls, jit_trampolines, unbox_trampolines, static_rgctx_trampolines;
 
-#define mono_trampolines_lock() EnterCriticalSection (&trampolines_mutex)
-#define mono_trampolines_unlock() LeaveCriticalSection (&trampolines_mutex)
-static CRITICAL_SECTION trampolines_mutex;
+#define mono_trampolines_lock() mono_mutex_lock (&trampolines_mutex)
+#define mono_trampolines_unlock() mono_mutex_unlock (&trampolines_mutex)
+static mono_mutex_t trampolines_mutex;
 
 #ifdef MONO_ARCH_GSHARED_SUPPORTED
 
@@ -140,18 +141,15 @@ mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr)
 
 /*
  * Either IMPL_METHOD or AOT_ADDR will be set on return.
- */
-static gpointer*
-#ifdef __GNUC__
-/*
+ *
+ * MONO_NEVER_INLINE :
  * This works against problems when compiling with gcc 4.6 on arm. The 'then' part of
  * this line gets executed, even when the condition is false:
  *             if (impl && mono_method_needs_static_rgctx_invoke (impl, FALSE))
  *                     *need_rgctx_tramp = TRUE;
  */
-__attribute__ ((noinline))
-#endif
-       mono_convert_imt_slot_to_vtable_slot (gpointer* slot, mgreg_t *regs, guint8 *code, MonoMethod *method, gboolean lookup_aot, MonoMethod **impl_method, gboolean *need_rgctx_tramp, gboolean *variance_used, gpointer *aot_addr)
+static MONO_NEVER_INLINE gpointer*
+mono_convert_imt_slot_to_vtable_slot (gpointer* slot, mgreg_t *regs, guint8 *code, MonoMethod *method, gboolean lookup_aot, MonoMethod **impl_method, gboolean *need_rgctx_tramp, gboolean *variance_used, gpointer *aot_addr)
 {
        MonoObject *this_argument = mono_arch_get_this_arg_from_call (regs, code);
        MonoVTable *vt = this_argument->vtable;
@@ -730,10 +728,6 @@ mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
         * We use one vtable trampoline per vtable slot index, so we need only the vtable,
         * the other two can be computed from the vtable + the slot index.
         */
-#ifndef MONO_ARCH_THIS_AS_FIRST_ARG
-       /* All architectures should support this */
-       g_assert_not_reached ();
-#endif
 
        /*
         * Obtain the vtable from the 'this' arg.
@@ -983,7 +977,7 @@ create_delegate_trampoline_data (MonoDomain *domain, MonoClass *klass, MonoMetho
        invoke = mono_get_delegate_invoke (klass);
        g_assert (invoke);
 
-       tramp_data = mono_domain_alloc (domain, sizeof (MonoDelegateTrampInfo));
+       tramp_data = mono_domain_alloc0 (domain, sizeof (MonoDelegateTrampInfo));
        tramp_data->invoke = invoke;
        tramp_data->invoke_sig = mono_method_signature (invoke);
        tramp_data->impl_this = mono_arch_get_delegate_invoke_impl (mono_method_signature (invoke), TRUE);
@@ -1290,7 +1284,7 @@ create_trampoline_code (MonoTrampolineType tramp_type)
 void
 mono_trampolines_init (void)
 {
-       InitializeCriticalSection (&trampolines_mutex);
+       mono_mutex_init_recursive (&trampolines_mutex);
 
        if (mono_aot_only)
                return;
@@ -1335,7 +1329,7 @@ mono_trampolines_cleanup (void)
        if (rgctx_lazy_fetch_trampoline_hash_addr)
                g_hash_table_destroy (rgctx_lazy_fetch_trampoline_hash_addr);
 
-       DeleteCriticalSection (&trampolines_mutex);
+       mono_mutex_destroy (&trampolines_mutex);
 }
 
 guint8 *
@@ -1571,6 +1565,19 @@ mono_create_delegate_trampoline (MonoDomain *domain, MonoClass *klass)
 #endif
 }
 
+gpointer
+mono_create_delegate_virtual_trampoline (MonoDomain *domain, MonoClass *klass, MonoMethod *method)
+{
+#ifdef MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
+       MonoMethod *invoke = mono_get_delegate_invoke (klass);
+       g_assert (invoke);
+
+       return mono_get_delegate_virtual_invoke_impl (mono_method_signature (invoke), method);
+#else
+       return NULL;
+#endif
+}
+
 gpointer
 mono_create_rgctx_lazy_fetch_trampoline (guint32 offset)
 {