From 2b74a8a8e236c6010ae72e7497b98e8fa8921d57 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 5 Apr 2024 11:41:27 +0300 Subject: [PATCH 1/3] [mono][interp] Remove no longer used hashtable --- src/mono/mono/mini/interp/interp.c | 39 +----------------------------- src/mono/mono/mini/mini-runtime.c | 1 - src/mono/mono/mini/mini-runtime.h | 2 -- 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 087e7d6ea3689..a4e435ceeb789 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -266,8 +266,6 @@ static gboolean debugger_enabled = FALSE; static MonoException* do_transform_method (InterpMethod *imethod, InterpFrame *method, ThreadContext *context); -static InterpMethod* lookup_method_pointer (gpointer addr); - typedef void (*ICallMethod) (InterpFrame *frame); static MonoNativeTlsKey thread_context_id; @@ -3262,20 +3260,6 @@ interp_compile_interp_method (MonoMethod *method, MonoError *error) return imethod->jinfo; } -static InterpMethod* -lookup_method_pointer (gpointer addr) -{ - InterpMethod *res = NULL; - MonoJitMemoryManager *jit_mm = get_default_jit_mm (); - - jit_mm_lock (jit_mm); - if (jit_mm->interp_method_pointer_hash) - res = (InterpMethod*)g_hash_table_lookup (jit_mm->interp_method_pointer_hash, addr); - jit_mm_unlock (jit_mm); - - return res; -} - #ifndef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED static void interp_no_native_to_managed (void) @@ -3380,13 +3364,6 @@ interp_create_method_pointer_llvmonly (MonoMethod *method, gboolean unbox, MonoE addr = mini_llvmonly_create_ftndesc (method, entry_wrapper, entry_ftndesc); - MonoJitMemoryManager *jit_mm = jit_mm_for_method (method); - jit_mm_lock (jit_mm); - if (!jit_mm->interp_method_pointer_hash) - jit_mm->interp_method_pointer_hash = g_hash_table_new (NULL, NULL); - g_hash_table_insert (jit_mm->interp_method_pointer_hash, addr, imethod); - jit_mm_unlock (jit_mm); - mono_memory_barrier (); if (unbox) imethod->llvmonly_unbox_entry = addr; @@ -3538,13 +3515,6 @@ interp_create_method_pointer (MonoMethod *method, gboolean compile, MonoError *e addr = mono_create_ftnptr_arg_trampoline (ftndesc, entry_wrapper); - MonoJitMemoryManager *jit_mm = get_default_jit_mm (); - jit_mm_lock (jit_mm); - if (!jit_mm->interp_method_pointer_hash) - jit_mm->interp_method_pointer_hash = g_hash_table_new (NULL, NULL); - g_hash_table_insert (jit_mm->interp_method_pointer_hash, addr, imethod); - jit_mm_unlock (jit_mm); - mono_memory_barrier (); imethod->jit_entry = addr; @@ -3555,23 +3525,16 @@ static void interp_free_method (MonoMethod *method) { MonoJitMemoryManager *jit_mm = jit_mm_for_method (method); - InterpMethod *imethod; MonoDynamicMethod *dmethod = (MonoDynamicMethod*)method; jit_mm_lock (jit_mm); - imethod = (InterpMethod*)mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method); #if HOST_BROWSER + InterpMethod *imethod = (InterpMethod*)mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method); mono_jiterp_free_method_data (method, imethod); #endif mono_internal_hash_table_remove (&jit_mm->interp_code_hash, method); - if (imethod && jit_mm->interp_method_pointer_hash) { - if (imethod->jit_entry) - g_hash_table_remove (jit_mm->interp_method_pointer_hash, imethod->jit_entry); - if (imethod->llvmonly_unbox_entry) - g_hash_table_remove (jit_mm->interp_method_pointer_hash, imethod->llvmonly_unbox_entry); - } jit_mm_unlock (jit_mm); if (dmethod->mp) { diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 90fe8ddc799eb..35ae4b04161d6 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4452,7 +4452,6 @@ free_jit_mem_manager (MonoMemoryManager *mem_manager) g_hash_table_destroy (info->dyn_delegate_info_hash); g_hash_table_destroy (info->static_rgctx_trampoline_hash); g_hash_table_destroy (info->mrgctx_hash); - g_hash_table_destroy (info->interp_method_pointer_hash); mono_conc_hashtable_destroy (info->runtime_invoke_hash); g_hash_table_destroy (info->seq_points); g_hash_table_destroy (info->arch_seq_points); diff --git a/src/mono/mono/mini/mini-runtime.h b/src/mono/mono/mini/mini-runtime.h index 1e4cb5dc1eb8e..c6a82a5231b09 100644 --- a/src/mono/mono/mini/mini-runtime.h +++ b/src/mono/mono/mini/mini-runtime.h @@ -54,8 +54,6 @@ typedef struct { MonoInternalHashTable interp_code_hash; /* Maps MonoMethod -> MonoMethodRuntimeGenericContext */ GHashTable *mrgctx_hash; - /* Maps gpointer -> InterpMethod */ - GHashTable *interp_method_pointer_hash; /* Protected by 'jit_code_hash_lock' */ MonoInternalHashTable jit_code_hash; mono_mutex_t jit_code_hash_lock; From cf821eb5b185c5b6624eb34f4c4ebd66a1698202 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 5 Apr 2024 11:44:13 +0300 Subject: [PATCH 2/3] [mono][interp] Fix leak in tiering We were looking with wrong key by mistake. --- src/mono/mono/mini/interp/tiering.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/interp/tiering.c b/src/mono/mono/mini/interp/tiering.c index f22f8b7ea1f5f..f35c83bc17d0a 100644 --- a/src/mono/mono/mini/interp/tiering.c +++ b/src/mono/mono/mini/interp/tiering.c @@ -64,7 +64,7 @@ patch_interp_data_items (InterpMethod *old_imethod, InterpMethod *new_imethod) GSList *sites = g_hash_table_lookup (patch_sites_table, old_imethod); g_slist_foreach (sites, patch_imethod_site, new_imethod); - g_hash_table_remove (patch_sites_table, sites); + g_hash_table_remove (patch_sites_table, old_imethod); g_slist_free (sites); } From 30dc24fc1384eff621af4b3cebdd157c4d48eddb Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Mon, 8 Apr 2024 19:47:33 +0300 Subject: [PATCH 3/3] [mono][interp] Ensure new var value has initialized liveness information --- src/mono/mono/mini/interp/transform-opt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/mini/interp/transform-opt.c b/src/mono/mono/mini/interp/transform-opt.c index 4ee96b7a541d2..7b606d60c2620 100644 --- a/src/mono/mono/mini/interp/transform-opt.c +++ b/src/mono/mono/mini/interp/transform-opt.c @@ -2241,6 +2241,7 @@ interp_fold_unop (TransformData *td, InterpInst *ins) td->var_values [sreg].ref_count--; result.def = ins; result.ref_count = td->var_values [dreg].ref_count; // preserve ref count + result.liveness = td->var_values [dreg].liveness; td->var_values [dreg] = result; return ins; @@ -2478,6 +2479,7 @@ interp_fold_binop (TransformData *td, InterpInst *ins, gboolean *folded) td->var_values [sreg2].ref_count--; result.def = ins; result.ref_count = td->var_values [dreg].ref_count; // preserve ref count + result.liveness = td->var_values [dreg].liveness; td->var_values [dreg] = result; return ins;