Skip to content

Commit

Permalink
[mono][aot] Prefer instances instead of using gsharedvt for types inf…
Browse files Browse the repository at this point in the history
…lated with empty structs. (dotnet#89688)

These structs are used in corlib for compile time templating.

Fixes dotnet#89624.
  • Loading branch information
vargaz authored Jul 31, 2023
1 parent 8622e98 commit 3769b5e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5541,12 +5541,18 @@ is_vt_inst (MonoGenericInst *inst)
}

static gboolean
is_vt_inst_no_enum (MonoGenericInst *inst)
is_vt_inst_no_enum_not_empty (MonoGenericInst *inst)
{
for (guint i = 0; i < inst->type_argc; ++i) {
MonoType *t = inst->type_argv [i];
if (MONO_TYPE_ISSTRUCT (t))
return TRUE;
if (MONO_TYPE_ISSTRUCT (t)) {
MonoClass *k = mono_class_from_mono_type_internal (t);
/*
* Empty vtypes with static virtual methods are used for templating in corlib.
*/
if (mono_class_get_field_count (k) > 0)
return TRUE;
}
}
return FALSE;
}
Expand Down Expand Up @@ -5682,7 +5688,7 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
* WASM only since other platforms depend on the
* previous behavior.
*/
if ((acfg->jit_opts & MONO_OPT_GSHAREDVT) && mono_class_is_ginst (klass) && mono_class_get_generic_class (klass)->context.class_inst && is_vt_inst_no_enum (mono_class_get_generic_class (klass)->context.class_inst)) {
if ((acfg->jit_opts & MONO_OPT_GSHAREDVT) && mono_class_is_ginst (klass) && mono_class_get_generic_class (klass)->context.class_inst && is_vt_inst_no_enum_not_empty (mono_class_get_generic_class (klass)->context.class_inst)) {
use_gsharedvt = TRUE;
use_gsharedvt_for_array = TRUE;
}
Expand Down

0 comments on commit 3769b5e

Please sign in to comment.