[runtime] For delegate invoke wrappers, store the generic invoke method in the wrappe...
authorZoltan Varga <vargaz@gmail.com>
Tue, 25 Oct 2016 22:05:32 +0000 (18:05 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Oct 2016 22:05:32 +0000 (18:05 -0400)
mono/metadata/marshal.c
mono/mini/mini-generic-sharing.c

index 0e48835962ebee18924f74593427e823e6ce38e9..a9a1042aee535ed693236c55c534486013e9e3ed 100644 (file)
@@ -2877,6 +2877,7 @@ cache_generic_delegate_wrapper (GHashTable *cache, MonoMethod *orig_method, Mono
 {
        MonoError error;
        MonoMethod *inst, *res;
+       WrapperInfo *ginfo, *info;
 
        /*
         * We use the same cache for the generic definition and the instances.
@@ -2884,6 +2885,16 @@ cache_generic_delegate_wrapper (GHashTable *cache, MonoMethod *orig_method, Mono
        inst = mono_class_inflate_generic_method_checked (def, ctx, &error);
        g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */
 
+       ginfo = mono_marshal_get_wrapper_info (def);
+       if (ginfo) {
+               info = (WrapperInfo *)mono_image_alloc0 (def->klass->image, sizeof (WrapperInfo));
+               info->subtype = ginfo->subtype;
+               if (info->subtype == WRAPPER_SUBTYPE_NONE) {
+                       info->d.delegate_invoke.method = mono_class_inflate_generic_method_checked (ginfo->d.delegate_invoke.method, ctx, &error);
+                       mono_error_assert_ok (&error);
+               }
+       }
+
        mono_memory_barrier ();
        mono_marshal_lock ();
        res = (MonoMethod *)g_hash_table_lookup (cache, orig_method->klass);
@@ -3554,7 +3565,7 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt
 #endif /* DISABLE_JIT */
 
        info = mono_wrapper_info_create (mb, subtype);
-       info->d.delegate_invoke.method = orig_method;
+       info->d.delegate_invoke.method = method;
 
        if (ctx) {
                MonoMethod *def;
index 736493198ed3b9556beb77bd842805959f7e862e..da5b3afc6c259ae2bfe8eda0229cc37c75f91b01 100644 (file)
@@ -3450,8 +3450,10 @@ mini_get_shared_method_full (MonoMethod *method, gboolean all_vt, gboolean is_gs
        if (method->wrapper_type == MONO_WRAPPER_DELEGATE_INVOKE) {
                WrapperInfo *info = mono_marshal_get_wrapper_info (method);
 
-               if (info->subtype == WRAPPER_SUBTYPE_NONE)
-                       return mono_marshal_get_delegate_invoke (mini_get_shared_method_full (info->d.delegate_invoke.method, all_vt, is_gsharedvt), NULL);
+               if (info->subtype == WRAPPER_SUBTYPE_NONE) {
+                       MonoMethod *m = mono_marshal_get_delegate_invoke (mini_get_shared_method_full (info->d.delegate_invoke.method, all_vt, is_gsharedvt), NULL);
+                       return m;
+               }
        }
 
        if (method->is_generic || (method->klass->generic_container && !method->is_inflated)) {