Skip to content

Commit

Permalink
[mono][interp] Minor fixes (#100661)
Browse files Browse the repository at this point in the history
* [mono][interp] Remove no longer used hashtable

* [mono][interp] Fix leak in tiering

We were looking with wrong key by mistake.

* [mono][interp] Ensure new var value has initialized liveness information
  • Loading branch information
BrzVlad committed Apr 11, 2024
1 parent ff3c531 commit 14252bd
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 42 deletions.
39 changes: 1 addition & 38 deletions src/mono/mono/mini/interp/interp.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/interp/tiering.c
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/interp/transform-opt.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/mono/mono/mini/mini-runtime.c
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/mini/mini-runtime.h
Expand Up @@ -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;
Expand Down

0 comments on commit 14252bd

Please sign in to comment.