2005-02-20 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / tramp-sparc.c
index 76ba8906583684ee4490854435f443d3a37f0d08..a1a00ff5778f56693fcf87717e42faef0d00d0da 100644 (file)
@@ -50,10 +50,10 @@ get_unbox_trampoline (MonoMethod *m, gpointer addr)
        guint8 *code, *start;
        int this_pos = 4, reg;
 
-       if (!m->signature->ret->byref && MONO_TYPE_ISSTRUCT (m->signature->ret))
+       if (!mono_method_signature (m)->ret->byref && MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
                this_pos = 8;
            
-       start = code = g_malloc (36);
+       start = code = mono_global_codeman_reserve (36);
 
        /* This executes in the context of the caller, hence o0 */
        sparc_add_imm (code, 0, sparc_o0, sizeof (MonoObject), sparc_o0);
@@ -98,17 +98,25 @@ sparc_magic_trampoline (MonoMethod *m, guint32 *code, guint32 *fp)
         * needed.
         */
        if (mono_sparc_is_virtual_call (code)) {
-               if (m->klass->valuetype)
-                       addr = get_unbox_trampoline (m, addr);
-
                /* Compute address of vtable slot */
                vtable_slot = mono_sparc_get_vcall_slot_addr (code, fp);
-               *vtable_slot = addr;
+               if (m->klass->valuetype && !mono_aot_is_got_entry (code, vtable_slot))
+                       addr = get_unbox_trampoline (m, addr);
+               if (mono_aot_is_got_entry (code, vtable_slot) || mono_domain_owns_vtable_slot (mono_domain_get (), vtable_slot))
+                       *vtable_slot = addr;
        }
        else {
                /* Patch calling code */
-               if (sparc_inst_op (*code) == 0x1)
-                       sparc_call_simple (code, (guint8*)addr - (guint8*)code);
+               if (sparc_inst_op (*code) == 0x1) {
+                       MonoJitInfo *ji = 
+                               mono_jit_info_table_find (mono_domain_get (), code);
+                       MonoJitInfo *target_ji = 
+                               mono_jit_info_table_find (mono_domain_get (), addr);
+
+                       if (mono_method_same_domain (ji, target_ji)) {
+                               sparc_call_simple (code, (guint8*)addr - (guint8*)code);
+                       }
+               }
        }
 
        return addr;
@@ -148,7 +156,7 @@ create_trampoline_code (MonoTrampolineType tramp_type)
                break;
        }
 
-       code = buf = g_malloc (512);
+       code = buf = mono_global_codeman_reserve (512);
 
        sparc_save_imm (code, sparc_sp, -608, sparc_sp);
 
@@ -327,19 +335,13 @@ gpointer
 mono_arch_create_jit_trampoline (MonoMethod *method)
 {
        MonoJitInfo *ji;
-
-       /* previously created trampoline code */
-       if (method->info)
-               return method->info;
-
-       if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
-               return mono_arch_create_jit_trampoline (mono_marshal_get_synchronized_wrapper (method));
+       gpointer code_start;
 
        ji = create_specific_trampoline (method, MONO_TRAMPOLINE_GENERIC, mono_domain_get ());
-       method->info = ji->code_start;
+       code_start = ji->code_start;
        g_free (ji);
 
-       return method->info;
+       return code_start;
 }
 
 /**
@@ -374,7 +376,7 @@ mono_debugger_create_notification_function (gpointer *notification_address)
 {
        guint8 *ptr, *buf;
 
-       ptr = buf = g_malloc0 (16);
+       ptr = buf = mono_global_codeman_reserve (16);
        if (notification_address)
                *notification_address = buf;