From 6c09f34947026ed988fd3013fdaa624a5fab0f26 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sun, 10 Oct 2021 16:09:37 +0200 Subject: [PATCH] [mono][interp] Avoid calls to m_class_get_mem_manager () in get_virtual_method_fast () (#60229) unless needed. --- src/mono/mono/mini/interp/interp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 7ad368990b162..6a0039ca872d7 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -694,11 +694,12 @@ static InterpMethod* // Inlining causes additional stack use in caller. get_virtual_method_fast (InterpMethod *imethod, MonoVTable *vtable, int offset) { gpointer *table; - MonoMemoryManager *memory_manager = m_class_get_mem_manager (vtable->klass); + MonoMemoryManager *memory_manager = NULL; table = get_method_table (vtable, offset); - if (!table) { + if (G_UNLIKELY (!table)) { + memory_manager = m_class_get_mem_manager (vtable->klass); /* Lazily allocate method table */ mono_mem_manager_lock (memory_manager); table = get_method_table (vtable, offset); @@ -707,8 +708,10 @@ get_virtual_method_fast (InterpMethod *imethod, MonoVTable *vtable, int offset) mono_mem_manager_unlock (memory_manager); } - if (!table [offset]) { + if (G_UNLIKELY (!table [offset])) { InterpMethod *target_imethod = get_virtual_method (imethod, vtable); + if (!memory_manager) + memory_manager = m_class_get_mem_manager (vtable->klass); /* Lazily initialize the method table slot */ mono_mem_manager_lock (memory_manager); if (!table [offset]) { @@ -727,8 +730,10 @@ get_virtual_method_fast (InterpMethod *imethod, MonoVTable *vtable, int offset) /* Virtual generic or interface call. Multiple methods in slot */ InterpMethod *target_imethod = get_target_imethod ((GSList*)table [offset], imethod); - if (!target_imethod) { + if (G_UNLIKELY (!target_imethod)) { target_imethod = get_virtual_method (imethod, vtable); + if (!memory_manager) + memory_manager = m_class_get_mem_manager (vtable->klass); mono_mem_manager_lock (memory_manager); if (!get_target_imethod ((GSList*)table [offset], imethod)) table [offset] = append_imethod (memory_manager, (GSList*)table [offset], imethod, target_imethod);