From 8df60a29bfe18f3e729825a77f1163c85f349a88 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Tue, 30 Oct 2018 12:45:19 -0400 Subject: [PATCH] [delegates] do not use CEE_CALLVIRT for non-virtual methods (#11451) [2018-08] [delegates] do not use CEE_CALLVIRT for non-virtual methods Backport of #11433. /cc @lewurm Description: --- mcs/class/corlib/Test/System/DelegateTest.cs | 2 -- mono/metadata/marshal-ilgen.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mcs/class/corlib/Test/System/DelegateTest.cs b/mcs/class/corlib/Test/System/DelegateTest.cs index e0801848d2e7..338201073e0f 100644 --- a/mcs/class/corlib/Test/System/DelegateTest.cs +++ b/mcs/class/corlib/Test/System/DelegateTest.cs @@ -1144,8 +1144,6 @@ public static int DynamicInvokeClosedStaticDelegate_CB (string instance) } [Test] - // Interp uses slowpath delegate invoke virtual wrapper which throws NRE also with JIT - [Category ("NotWorkingRuntimeInterpreter")] public void DynamicInvokeOpenInstanceDelegate () { var d1 = Delegate.CreateDelegate (typeof (Func), typeof(DelegateTest).GetMethod ("DynamicInvokeOpenInstanceDelegate_CB")); diff --git a/mono/metadata/marshal-ilgen.c b/mono/metadata/marshal-ilgen.c index 6b5a6b7a20e1..50283eaba9ba 100644 --- a/mono/metadata/marshal-ilgen.c +++ b/mono/metadata/marshal-ilgen.c @@ -3897,7 +3897,8 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature if (callvirt) { if (!closed_over_null) { - if (m_class_is_valuetype (target_class)) { + /* if target_method is not really virtual, turn it into a direct call */ + if (!(target_method->flags & METHOD_ATTRIBUTE_VIRTUAL) || m_class_is_valuetype (target_class)) { mono_mb_emit_ldarg (mb, 1); for (i = 1; i < sig->param_count; ++i) mono_mb_emit_ldarg (mb, i + 1);