Skip to content

Commit

Permalink
[mono][interp] Avoid calls to m_class_get_mem_manager () in get_virtu…
Browse files Browse the repository at this point in the history
…al_method_fast () (#60229)

unless needed.
  • Loading branch information
vargaz authored Oct 10, 2021
1 parent 2e8615b commit 6c09f34
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]) {
Expand All @@ -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);
Expand Down

0 comments on commit 6c09f34

Please sign in to comment.