Merge pull request #186 from QuickJack/master
[mono.git] / mono / mini / mini-trampolines.c
index e1b83d4e8b6758c560090962353471d1ef9ecc71..4bb60254632c9110ec5c34562574d30963c160c3 100644 (file)
@@ -1,4 +1,8 @@
-
+/*
+ * (C) 2003 Ximian, Inc.
+ * (C) 2003-2011 Novell, Inc.
+ * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
+ */
 #include <config.h>
 #include <glib.h>
 
@@ -156,6 +160,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__
+/*
+ * 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, 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);
@@ -864,7 +877,6 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_data, gui
        gboolean multicast, callvirt = FALSE;
        gboolean need_rgctx_tramp = FALSE;
        gboolean enable_caching = TRUE;
-       gboolean disable_fast_path = FALSE;
        MonoMethod *invoke = tramp_data [0];
        guint8 *impl_this = tramp_data [1];
        guint8 *impl_nothis = tramp_data [2];
@@ -894,17 +906,12 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_data, gui
                                method = mono_marshal_get_remoting_invoke (method);
                }
                else {
-                       MonoMethodSignature *iv_sig;
                        mono_error_init (&err);
                        sig = mono_method_signature_checked (method, &err);
                        if (!sig)
                                mono_error_raise_exception (&err);
-
-                       iv_sig = mono_method_signature_checked (invoke, &err);
-                       if (!iv_sig)
-                               mono_error_raise_exception (&err);
-
-                       if (sig->hasthis && method->klass->valuetype && !(iv_sig->param_count && iv_sig->params[0]->byref) && delegate->target)
+                               
+                       if (sig->hasthis && method->klass->valuetype)
                                method = mono_marshal_get_unbox_wrapper (method);
                }
        } else {
@@ -919,9 +926,7 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_data, gui
                if (!sig)
                        mono_error_raise_exception (&err);
 
-               callvirt = !delegate->target && sig->hasthis && (method->flags & METHOD_ATTRIBUTE_VIRTUAL);
-               disable_fast_path = !delegate->target && sig->hasthis;
-
+               callvirt = !delegate->target && sig->hasthis;
                if (delegate->target && 
                        method->flags & METHOD_ATTRIBUTE_VIRTUAL && 
                        method->flags & METHOD_ATTRIBUTE_ABSTRACT &&
@@ -959,7 +964,7 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_data, gui
        }
 
        multicast = ((MonoMulticastDelegate*)delegate)->prev != NULL;
-       if (!multicast && !callvirt && !disable_fast_path) {
+       if (!multicast && !callvirt) {
                if (method && (method->flags & METHOD_ATTRIBUTE_STATIC) && mono_method_signature (method)->param_count == mono_method_signature (invoke)->param_count + 1)
                        /* Closed static delegate */
                        code = impl_this;
@@ -989,7 +994,7 @@ mono_handler_block_guard_trampoline (mgreg_t *regs, guint8 *code, gpointer *tram
 {
        MonoContext ctx;
        MonoException *exc;
-       MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        gpointer resume_ip = jit_tls->handler_block_return_address;
 
        memcpy (&ctx, &jit_tls->handler_block_context, sizeof (MonoContext));
@@ -1009,7 +1014,7 @@ mono_handler_block_guard_trampoline (mgreg_t *regs, guint8 *code, gpointer *tram
                if (!restore_context)
                        restore_context = mono_get_restore_context ();
 
-               mono_handle_exception (&ctx, exc, NULL, FALSE);
+               mono_handle_exception (&ctx, exc);
                restore_context (&ctx);
        }
 
@@ -1326,7 +1331,7 @@ mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token)
        MonoDomain *domain = mono_domain_get ();
        guint8 *buf, *start;
 
-       buf = start = mono_domain_code_reserve (domain, 2 * sizeof (gpointer));
+       buf = start = mono_domain_alloc0 (domain, 2 * sizeof (gpointer));
 
        *(gpointer*)(gpointer)buf = image;
        buf += sizeof (gpointer);
@@ -1433,7 +1438,6 @@ gpointer
 mono_create_monitor_enter_trampoline (void)
 {
        static gpointer code;
-       MonoTrampInfo *info;
 
        if (mono_aot_only) {
                if (!code)
@@ -1445,6 +1449,8 @@ mono_create_monitor_enter_trampoline (void)
        mono_trampolines_lock ();
 
        if (!code) {
+               MonoTrampInfo *info;
+
                code = mono_arch_create_monitor_enter_trampoline (&info, FALSE);
                if (info) {
                        mono_save_trampoline_xdebug_info (info);
@@ -1467,7 +1473,6 @@ gpointer
 mono_create_monitor_exit_trampoline (void)
 {
        static gpointer code;
-       MonoTrampInfo *info;
 
        if (mono_aot_only) {
                if (!code)
@@ -1479,6 +1484,8 @@ mono_create_monitor_exit_trampoline (void)
        mono_trampolines_lock ();
 
        if (!code) {
+               MonoTrampInfo *info;
+
                code = mono_arch_create_monitor_exit_trampoline (&info, FALSE);
                if (info) {
                        mono_save_trampoline_xdebug_info (info);