8080#include <mono/mini/trace.h>
8181
8282#include <mono/metadata/components.h>
83+ #include <mono/metadata/loader-internals.h>
8384
8485#ifdef TARGET_ARM
8586#include <mono/mini/mini-arm.h>
@@ -8588,7 +8589,6 @@ metadata_update_prepare_to_invalidate (void)
85888589 /* (2) invalidate all the registered imethods */
85898590}
85908591
8591-
85928592static void
85938593interp_invalidate_transformed (void )
85948594{
@@ -8599,17 +8599,27 @@ interp_invalidate_transformed (void)
85998599 need_stw_restart = TRUE;
86008600 }
86018601
8602- // FIXME: Enumerate all memory managers
8603- MonoJitMemoryManager * jit_mm = get_default_jit_mm ();
8602+ GPtrArray * alcs = mono_alc_get_all ();
86048603
8605- jit_mm_lock (jit_mm );
8606- mono_internal_hash_table_apply (& jit_mm - > interp_code_hash , invalidate_transform , NULL );
8607- jit_mm_unlock (jit_mm );
8604+ if (alcs ) {
8605+ MonoAssemblyLoadContext * alc ;
8606+ for (guint i = 0 ; i < alcs - > len ; ++ i ) {
8607+ alc = (MonoAssemblyLoadContext * )g_ptr_array_index (alcs , i );
8608+ MonoJitMemoryManager * jit_mm = (MonoJitMemoryManager * )(alc - > memory_manager - > runtime_info );
8609+
8610+ jit_mm_lock (jit_mm );
8611+ mono_internal_hash_table_apply (& jit_mm - > interp_code_hash , invalidate_transform , NULL );
8612+ jit_mm_unlock (jit_mm );
8613+ }
8614+
8615+ g_ptr_array_free (alcs , TRUE);
8616+ }
86088617
86098618 if (need_stw_restart )
86108619 mono_restart_world (MONO_THREAD_INFO_FLAGS_NO_GC );
86118620}
86128621
8622+
86138623typedef struct {
86148624 MonoJitInfo * * jit_info_array ;
86158625 gint size ;
@@ -8627,27 +8637,34 @@ interp_copy_jit_info_func (gpointer imethod, gpointer user_data)
86278637static void
86288638interp_jit_info_foreach (InterpJitInfoFunc func , gpointer user_data )
86298639{
8630- InterpCopyJitInfoFuncUserData copy_jit_info_data ;
8631-
8632- // FIXME: Enumerate all memory managers
8633- MonoJitMemoryManager * jit_mm = get_default_jit_mm ();
8640+ GPtrArray * alcs = mono_alc_get_all ();
8641+
8642+ if (alcs ) {
8643+ MonoAssemblyLoadContext * alc ;
8644+ for (guint i = 0 ; i < alcs - > len ; ++ i ) {
8645+ alc = (MonoAssemblyLoadContext * )g_ptr_array_index (alcs , i );
8646+ MonoJitMemoryManager * jit_mm = (MonoJitMemoryManager * )(alc - > memory_manager - > runtime_info );
8647+ InterpCopyJitInfoFuncUserData copy_jit_info_data ;
8648+ // Can't keep memory manager lock while iterating and calling callback since it might take other locks
8649+ // causing poential deadlock situations. Instead, create copy of interpreter imethod jinfo pointers into
8650+ // plain array and use pointers from array when when running callbacks.
8651+ copy_jit_info_data .size = mono_atomic_load_i32 (& (jit_mm - > interp_code_hash .num_entries ));
8652+ copy_jit_info_data .next = 0 ;
8653+ copy_jit_info_data .jit_info_array = (MonoJitInfo * * ) g_new (MonoJitInfo * , copy_jit_info_data .size );
8654+ if (copy_jit_info_data .jit_info_array ) {
8655+ jit_mm_lock (jit_mm );
8656+ mono_internal_hash_table_apply (& jit_mm - > interp_code_hash , interp_copy_jit_info_func , & copy_jit_info_data );
8657+ jit_mm_unlock (jit_mm );
8658+ }
86348659
8635- // Can't keep memory manager lock while iterating and calling callback since it might take other locks
8636- // causing poential deadlock situations. Instead, create copy of interpreter imethod jinfo pointers into
8637- // plain array and use pointers from array when when running callbacks.
8638- copy_jit_info_data .size = mono_atomic_load_i32 (& (jit_mm - > interp_code_hash .num_entries ));
8639- copy_jit_info_data .next = 0 ;
8640- copy_jit_info_data .jit_info_array = (MonoJitInfo * * ) g_new (MonoJitInfo * , copy_jit_info_data .size );
8641- if (copy_jit_info_data .jit_info_array ) {
8642- jit_mm_lock (jit_mm );
8643- mono_internal_hash_table_apply (& jit_mm - > interp_code_hash , interp_copy_jit_info_func , & copy_jit_info_data );
8644- jit_mm_unlock (jit_mm );
8645- }
8646-
8647- if (copy_jit_info_data .jit_info_array ) {
8648- for (int i = 0 ; i < copy_jit_info_data .next ; ++ i )
8649- func (copy_jit_info_data .jit_info_array [i ], user_data );
8650- g_free (copy_jit_info_data .jit_info_array );
8660+ if (copy_jit_info_data .jit_info_array ) {
8661+ for (int j = 0 ; j < copy_jit_info_data .next ; ++ j )
8662+ func (copy_jit_info_data .jit_info_array [j ], user_data );
8663+ g_free (copy_jit_info_data .jit_info_array );
8664+ }
8665+ }
8666+
8667+ g_ptr_array_free (alcs , TRUE );
86518668 }
86528669}
86538670
0 commit comments