Skip to content

Commit

Permalink
[mono][aot] Reduce collisions in mono_aot_method_hash () for some wra…
Browse files Browse the repository at this point in the history
…ppers. (#80667)
  • Loading branch information
vargaz authored Jan 17, 2023
1 parent 2e77a42 commit bd3e1f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -10802,6 +10802,7 @@ mono_aot_method_hash (MonoMethod *method)
guint32 a, b, c;
MonoGenericInst *class_ginst = NULL;
MonoGenericInst *ginst = NULL;
WrapperInfo *info = NULL;

/* Similar to the hash in mono_method_get_imt_slot () */

Expand All @@ -10816,12 +10817,21 @@ mono_aot_method_hash (MonoMethod *method)
hashes_start = (guint32 *)g_malloc0 (hashes_count * sizeof (guint32));
hashes = hashes_start;

if (method->wrapper_type && method->wrapper_type != MONO_WRAPPER_DYNAMIC_METHOD)
info = mono_marshal_get_wrapper_info (method);

/* Some wrappers are assigned to random classes */
if (!method->wrapper_type)
if (!method->wrapper_type) {
klass = method->klass;
else
} else {
klass = mono_defaults.object_class;

if (method->wrapper_type == MONO_WRAPPER_OTHER &&
(info->subtype == WRAPPER_SUBTYPE_PTR_TO_STRUCTURE || info->subtype == WRAPPER_SUBTYPE_STRUCTURE_TO_PTR)) {
klass = method->klass;
}
}

if (!method->wrapper_type) {
char *full_name;

Expand All @@ -10842,6 +10852,12 @@ mono_aot_method_hash (MonoMethod *method)
hashes [2] = mono_marshal_get_wrapper_info (method)->d.icall.jit_icall_id;
else
hashes [2] = mono_metadata_str_hash (method->name);

if (method->wrapper_type == MONO_WRAPPER_OTHER) {
if (info && (info->subtype == WRAPPER_SUBTYPE_GSHAREDVT_IN_SIG || info->subtype == WRAPPER_SUBTYPE_GSHAREDVT_OUT_SIG))
sig = info->d.gsharedvt.sig;
}

hashes [3] = method->wrapper_type;
hashes [4] = mono_aot_type_hash (sig->ret);
hindex = 5;
Expand All @@ -10856,7 +10872,8 @@ mono_aot_method_hash (MonoMethod *method)
for (guint i = 0; i < ginst->type_argc; ++i)
hashes [hindex ++] = mono_aot_type_hash (ginst->type_argv [i]);
}
g_assert (hindex == hashes_count);
g_assert (hindex <= hashes_count);
hashes_count = hindex;

/* Setup internal state */
a = b = c = 0xdeadbeef + (((guint32)hashes_count)<<2);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "mini.h"

/* Version number of the AOT file format */
#define MONO_AOT_FILE_VERSION 183
#define MONO_AOT_FILE_VERSION 184

#define MONO_AOT_TRAMP_PAGE_SIZE 16384

Expand Down

0 comments on commit bd3e1f5

Please sign in to comment.