Revert dfa9220e8b7e89c29447a71c7b30d5a9a3cbdfec.
[mono.git] / mono / mini / mini-x86.c
index 06f5ee0c21ae932f696d2035676e21b2c67ac209..75a6a7a24ad36c4a9a0a6749dc65e8949c692720 100644 (file)
@@ -1485,7 +1485,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
        /* Arguments are pushed in the reverse order */
        for (i = n - 1; i >= 0; i --) {
                ArgInfo *ainfo = cinfo->args + i;
-               MonoType *t;
+               MonoType *orig_type, *t;
                int argsize;
 
                if (cinfo->vtype_retaddr && cinfo->vret_arg_index == 1 && i == 0) {
@@ -1503,6 +1503,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
                        t = sig->params [i - sig->hasthis];
                else
                        t = &mono_defaults.int_class->byval_arg;
+               orig_type = t;
                t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
 
                MONO_INST_NEW (cfg, arg, OP_X86_PUSH);
@@ -1536,7 +1537,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
 
                                MONO_ADD_INS (cfg->cbb, arg);
                                sp_offset += size;
-                               emit_gc_param_slot_def (cfg, sp_offset, t);
+                               emit_gc_param_slot_def (cfg, sp_offset, orig_type);
                        }
                } else {
                        argsize = 4;
@@ -1575,11 +1576,16 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
                        if (cfg->compute_gc_maps) {
                                if (argsize == 4) {
                                        /* FIXME: The == STACK_OBJ check might be fragile ? */
-                                       if (sig->hasthis && i == 0 && call->args [i]->type == STACK_OBJ)
+                                       if (sig->hasthis && i == 0 && call->args [i]->type == STACK_OBJ) {
                                                /* this */
-                                               emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.object_class->byval_arg);
-                                       else
-                                               emit_gc_param_slot_def (cfg, sp_offset, t);
+                                               if (call->need_unbox_trampoline)
+                                                       /* The unbox trampoline transforms this into a managed pointer */
+                                                       emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.int_class->this_arg);
+                                               else
+                                                       emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.object_class->byval_arg);
+                                       } else {
+                                               emit_gc_param_slot_def (cfg, sp_offset, orig_type);
+                                       }
                                } else {
                                        /* i8/r8 */
                                        for (j = 0; j < argsize; j += 4)
@@ -3152,6 +3158,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        MonoCallInst *call = (MonoCallInst*)ins;
                        int pos = 0, i;
 
+                       ins->flags |= MONO_INST_GC_CALLSITE;
+                       ins->backend.pc_offset = code - cfg->native_code;
+
                        /* FIXME: no tracing support... */
                        if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
                                code = mono_arch_instrument_epilog (cfg, mono_profiler_method_leave, code, FALSE);
@@ -5900,9 +5909,9 @@ mono_arch_get_patch_offset (guint8 *code)
 {
        if ((code [0] == 0x8b) && (x86_modrm_mod (code [1]) == 0x2))
                return 2;
-       else if ((code [0] == 0xba))
+       else if (code [0] == 0xba)
                return 1;
-       else if ((code [0] == 0x68))
+       else if (code [0] == 0x68)
                /* push IMM */
                return 1;
        else if ((code [0] == 0xff) && (x86_modrm_reg (code [1]) == 0x6))