2009-07-13 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / method-to-ir.c
index 3a83525de2420e1e01efb859da51e05663b66c06..4c9ad867f54dcccd91f95cc1badfd6d973408cae 100644 (file)
@@ -2232,17 +2232,12 @@ mono_emit_rgctx_calli (MonoCompile *cfg, MonoMethodSignature *sig, MonoInst **ar
 #endif
 }
 
-static MonoInst*
-emit_get_rgctx_method (MonoCompile *cfg, int context_used, MonoMethod *cmethod, int rgctx_type);
-
 static MonoInst*
 mono_emit_method_call_full (MonoCompile *cfg, MonoMethod *method, MonoMethodSignature *sig,
                                                        MonoInst **args, MonoInst *this, MonoInst *imt_arg)
 {
-       gboolean might_be_remote;
        gboolean virtual = this != NULL;
        gboolean enable_for_aot = TRUE;
-       int context_used;
        MonoCallInst *call;
 
        if (method->string_ctor) {
@@ -2254,27 +2249,15 @@ mono_emit_method_call_full (MonoCompile *cfg, MonoMethod *method, MonoMethodSign
                sig = ctor_sig;
        }
 
-       might_be_remote = this && sig->hasthis &&
-               (method->klass->marshalbyref || method->klass == mono_defaults.object_class) &&
-               !(method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !MONO_CHECK_THIS (this);
-
-       context_used = mono_method_check_context_used (method);
-       if (might_be_remote && context_used) {
-               MonoInst *addr;
-
-               g_assert (cfg->generic_sharing_context);
-
-               addr = emit_get_rgctx_method (cfg, context_used, method, MONO_RGCTX_INFO_REMOTING_INVOKE_WITH_CHECK);
-
-               return mono_emit_calli (cfg, sig, args, addr);
-       }
-
        call = mono_emit_call_args (cfg, sig, args, FALSE, virtual, FALSE);
 
-       if (might_be_remote)
+       if (this && sig->hasthis && 
+           (method->klass->marshalbyref || method->klass == mono_defaults.object_class) && 
+           !(method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !MONO_CHECK_THIS (this)) {
                call->method = mono_marshal_get_remoting_invoke_with_check (method);
-       else
+       } else {
                call->method = method;
+       }
        call->inst.flags |= MONO_INST_HAS_METHOD;
        call->inst.inst_left = this;
 
@@ -2707,36 +2690,6 @@ emit_get_rgctx_field (MonoCompile *cfg, int context_used,
        return emit_rgctx_fetch (cfg, rgctx, entry);
 }
 
-static void
-emit_generic_class_init (MonoCompile *cfg, MonoClass *klass)
-{
-       MonoInst *vtable_arg;
-       MonoCallInst *call;
-       int context_used = 0;
-
-       if (cfg->generic_sharing_context)
-               context_used = mono_class_check_context_used (klass);
-
-       if (context_used) {
-               vtable_arg = emit_get_rgctx_klass (cfg, context_used,
-                                                                                  klass, MONO_RGCTX_INFO_VTABLE);
-       } else {
-               MonoVTable *vtable = mono_class_vtable (cfg->domain, klass);
-
-               if (!vtable)
-                       return;
-               EMIT_NEW_VTABLECONST (cfg, vtable_arg, vtable);
-       }
-
-       call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_GENERIC_CLASS_INIT, NULL, helper_sig_generic_class_init_trampoline, &vtable_arg);
-#ifdef MONO_ARCH_VTABLE_REG
-       mono_call_inst_add_outarg_reg (cfg, call, vtable_arg->dreg, MONO_ARCH_VTABLE_REG, FALSE);
-       cfg->uses_vtable_reg = TRUE;
-#else
-       NOT_IMPLEMENTED;
-#endif
-}
-
 static void
 mini_emit_check_array_type (MonoCompile *cfg, MonoInst *obj, MonoClass *array_class)
 {
@@ -6238,13 +6191,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                        if (*ip != CEE_CALLI && check_call_signature (cfg, fsig, sp))
                                UNVERIFIED;
 
-                       /* 
-                        * If the callee is a shared method, then its static cctor
-                        * might not get called after the call was patched.
-                        */
-                       if (cfg->generic_sharing_context && cmethod && cmethod->klass != method->klass && cmethod->klass->generic_class && mono_method_is_generic_sharable_impl (cmethod, TRUE) && mono_class_needs_cctor_run (cmethod->klass, method)) {
-                               emit_generic_class_init (cfg, cmethod->klass);
-                       }
 
                        if (cmethod && ((cmethod->flags & METHOD_ATTRIBUTE_STATIC) || cmethod->klass->valuetype) &&
                                        (cmethod->klass->generic_class || cmethod->klass->generic_container)) {
@@ -7601,6 +7547,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                        INLINE_FAILURE;
                                        ins = mono_emit_rgctx_method_call_full (cfg, cmethod, fsig, sp,
                                                                                                                        callvirt_this_arg, NULL, vtable_arg);
+                                       if (mono_method_is_generic_sharable_impl (cmethod, TRUE) && ((MonoCallInst*)ins)->method->wrapper_type == MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK)
+                                               GENERIC_SHARING_FAILURE (*ip);
                                }
                        }