Skip to content

Commit

Permalink
[mono][aot] Fix the inclusion of generic instances when doing profile…
Browse files Browse the repository at this point in the history
…d AOT. (#61627)

If a profile contained a method like List<AnInst>:.ctor () and the
'profile-only' option was used, the fully shared version of the method
needs to be added to the aot image.
  • Loading branch information
vargaz authored Nov 17, 2021
1 parent da0e0f7 commit 0666ebc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12909,8 +12909,15 @@ resolve_class (ClassProfileData *cdata)
}
if (cdata->inst) {
resolve_ginst (cdata->inst);
if (!cdata->inst->inst)
if (!cdata->inst->inst) {
/*
* The instance might not be found if its arguments are in another assembly,
* use the definition instead.
*/
cdata->klass = klass;
//printf ("[%s] %s.%s\n", cdata->image->name, cdata->ns, cdata->name);
return;
}
MonoGenericContext ctx;

memset (&ctx, 0, sizeof (ctx));
Expand Down Expand Up @@ -12989,12 +12996,14 @@ resolve_profile_data (MonoAotCompile *acfg, ProfileData *data, MonoAssembly* cur
printf ("Unable to load method '%s' because its class '%s.%s' is not loaded.\n", mdata->name, mdata->klass->ns, mdata->klass->name);
continue;
}

miter = NULL;
while ((m = mono_class_get_methods (klass, &miter))) {
ERROR_DECL (error);

if (strcmp (m->name, mdata->name))
continue;

MonoMethodSignature *sig = mono_method_signature_internal (m);
if (!sig)
continue;
Expand All @@ -13021,9 +13030,11 @@ resolve_profile_data (MonoAotCompile *acfg, ProfileData *data, MonoAssembly* cur
char *sig_str = mono_signature_full_name (sig);
gboolean match = !strcmp (sig_str, mdata->signature);
g_free (sig_str);
if (!match)

continue;
if (!match) {
// The signature might not match for methods on gtds
if (!mono_class_is_gtd (klass))
continue;
}
//printf ("%s\n", mono_method_full_name (m, 1));
mdata->method = m;
break;
Expand Down Expand Up @@ -13114,8 +13125,14 @@ add_profile_instances (MonoAotCompile *acfg, ProfileData *data)
continue;
if (!m->is_inflated)
continue;
if (mono_method_is_generic_sharable_full (m, FALSE, FALSE, FALSE))
if (mono_method_is_generic_sharable_full (m, FALSE, FALSE, FALSE)) {
if (acfg->aot_opts.profile_only && m_class_get_image (m->klass) == acfg->image) {
// Add the fully shared version to its home image
add_profile_method (acfg, m);
count ++;
}
continue;
}

if (acfg->aot_opts.dedup_include) {
/* Add all instances from the profile */
Expand Down

0 comments on commit 0666ebc

Please sign in to comment.