Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Use simdhash for aot method lookup ptr->methodinfo cache #102029

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/mono/mono/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ else()
set(metadata_platform_sources ${metadata_unix_sources})
endif()

set(imported_native_sources
../../../native/containers/dn-simdhash.c
../../../native/containers/dn-simdhash-string-ptr.c
../../../native/containers/dn-simdhash-u32-ptr.c
../../../native/containers/dn-simdhash-ptrpair-ptr.c)

set(metadata_common_sources
appdomain.c
domain.c
Expand Down Expand Up @@ -201,7 +195,7 @@ elseif(MONO_GC STREQUAL "boehm")
set(metadata_compile_definitions "HAVE_BOEHM_GC")
endif()

set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${metadata_gc_dependent_sources};${metadata_gc_sources};${ilgen_sources};${imported_native_sources}")
set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${metadata_gc_dependent_sources};${metadata_gc_sources};${ilgen_sources}")

if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS)
add_library(metadata_objects_shared OBJECT ${metadata_sources})
Expand Down
9 changes: 8 additions & 1 deletion src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ endif()
# MINI
#

set(imported_native_sources
../../../native/containers/dn-simdhash.c
../../../native/containers/dn-simdhash-ptr-ptr.c
../../../native/containers/dn-simdhash-string-ptr.c
../../../native/containers/dn-simdhash-u32-ptr.c
../../../native/containers/dn-simdhash-ptrpair-ptr.c)

set(mini_common_sources
mini.c
mini-runtime.c
Expand Down Expand Up @@ -302,7 +309,7 @@ else()
set(profiler_sources "")
endif()

set(mini_sources "main-core.c;${mini_common_sources};${arch_sources};${os_sources};${mini_interp_sources};${llvm_sources};${debugger_sources};${profiler_sources};${llvm_runtime_sources}")
set(mini_sources "main-core.c;${imported_native_sources};${mini_common_sources};${arch_sources};${os_sources};${mini_interp_sources};${llvm_sources};${debugger_sources};${profiler_sources};${llvm_runtime_sources}")

if(LLVM_INCLUDEDIR)
include_directories(BEFORE SYSTEM "${LLVM_INCLUDEDIR}")
Expand Down
11 changes: 6 additions & 5 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct MonoAotModule {
/* Maps methods to their code */
GHashTable *method_to_code;
/* Maps pointers into the method info to the methods themselves */
GHashTable *method_ref_to_method;
dn_simdhash_ptr_ptr_t *method_ref_to_method;
MonoAssemblyName *image_names;
char **image_guids;
MonoAssembly *assembly;
Expand Down Expand Up @@ -4513,7 +4513,7 @@ find_aot_method_in_amodule (MonoAotModule *code_amodule, MonoMethod *method, gui

index = 0xffffff;
while (TRUE) {
MonoMethod *m;
MonoMethod *m = NULL;
guint8 *p, *orig_p;

key = decode_uint_with_len (key_len, entry);
Expand All @@ -4528,8 +4528,9 @@ find_aot_method_in_amodule (MonoAotModule *code_amodule, MonoMethod *method, gui

amodule_lock (metadata_amodule);
if (!metadata_amodule->method_ref_to_method)
metadata_amodule->method_ref_to_method = g_hash_table_new (NULL, NULL);
m = (MonoMethod *)g_hash_table_lookup (metadata_amodule->method_ref_to_method, p);
// FIXME: Select a better initial capacity.
metadata_amodule->method_ref_to_method = dn_simdhash_ptr_ptr_new (4096, NULL);
dn_simdhash_ptr_ptr_try_get_value (metadata_amodule->method_ref_to_method, p, (void **)&m);
amodule_unlock (metadata_amodule);
if (!m) {
m = decode_resolve_method_ref_with_target (code_amodule, method, p, &p, error);
Expand All @@ -4540,7 +4541,7 @@ find_aot_method_in_amodule (MonoAotModule *code_amodule, MonoMethod *method, gui
*/
if (m && m->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE) {
amodule_lock (metadata_amodule);
g_hash_table_insert (metadata_amodule->method_ref_to_method, orig_p, m);
dn_simdhash_ptr_ptr_try_add (metadata_amodule->method_ref_to_method, orig_p, m);
amodule_unlock (metadata_amodule);
}
}
Expand Down
Loading