Skip to content

Commit 17dd5ff

Browse files
BrzVladtmds
authored andcommitted
[mono][interp] Fix some leaks during compilation (dotnet#97143)
* [mono][interp] Stop trying to inflate signature The target method and, implicitly, its signature are already inflated. This was allocating a new signature every time the method was called which was leaked. On some of the bigger tests suites, that heavily use generics, this can reduce the mem usage in the order of GBs. * [mono][interp] Free mheader in case of inline failure The header local types are not used anywhere so we can just free it.
1 parent eafcb9a commit 17dd5ff

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/mono/mono/mini/interp/transform.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ interp_inline_newobj (TransformData *td, MonoMethod *target_method, MonoMethodSi
31033103
int dreg, this_reg = -1;
31043104
int prev_sp_offset;
31053105
MonoClass *klass = target_method->klass;
3106+
MonoMethodHeader *mheader = NULL;
31063107

31073108
if (!(mono_interp_opt & INTERP_OPT_INLINE) ||
31083109
!interp_method_check_inlining (td, target_method, csignature))
@@ -3166,7 +3167,7 @@ interp_inline_newobj (TransformData *td, MonoMethod *target_method, MonoMethodSi
31663167
if (is_protected)
31673168
newobj_fast->flags |= INTERP_INST_FLAG_PROTECTED_NEWOBJ;
31683169

3169-
MonoMethodHeader *mheader = interp_method_get_header (target_method, error);
3170+
mheader = interp_method_get_header (target_method, error);
31703171
goto_if_nok (error, fail);
31713172

31723173
if (!interp_inline_method (td, target_method, mheader, error))
@@ -3180,6 +3181,7 @@ interp_inline_newobj (TransformData *td, MonoMethod *target_method, MonoMethodSi
31803181
push_var (td, dreg);
31813182
return TRUE;
31823183
fail:
3184+
mono_metadata_free_mh (mheader);
31833185
// Restore the state
31843186
td->sp = td->stack + prev_sp_offset;
31853187
td->last_ins = prev_last_ins;
@@ -3214,10 +3216,14 @@ interp_constrained_box (TransformData *td, MonoClass *constrained_class, MonoMet
32143216
static MonoMethod*
32153217
interp_get_method (MonoMethod *method, guint32 token, MonoImage *image, MonoGenericContext *generic_context, MonoError *error)
32163218
{
3217-
if (method->wrapper_type == MONO_WRAPPER_NONE)
3219+
if (method->wrapper_type == MONO_WRAPPER_NONE) {
32183220
return mono_get_method_checked (image, token, NULL, generic_context, error);
3219-
else
3220-
return (MonoMethod *)mono_method_get_wrapper_data (method, token);
3221+
} else {
3222+
MonoMethod *target_method = mono_method_get_wrapper_data (method, token);
3223+
if (generic_context)
3224+
target_method = mono_class_inflate_generic_method_checked (target_method, generic_context, error);
3225+
return target_method;
3226+
}
32213227
}
32223228

32233229
/*
@@ -3440,13 +3446,6 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
34403446
target_method = interp_get_method (method, token, image, generic_context, error);
34413447
return_val_if_nok (error, FALSE);
34423448
csignature = mono_method_signature_internal (target_method);
3443-
3444-
if (generic_context) {
3445-
csignature = mono_inflate_generic_signature (csignature, generic_context, error);
3446-
return_val_if_nok (error, FALSE);
3447-
target_method = mono_class_inflate_generic_method_checked (target_method, generic_context, error);
3448-
return_val_if_nok (error, FALSE);
3449-
}
34503449
}
34513450
} else {
34523451
csignature = mono_method_signature_internal (target_method);
@@ -3654,6 +3653,7 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
36543653
td->ip += 5;
36553654
goto done;
36563655
}
3656+
mono_metadata_free_mh (mheader);
36573657
}
36583658

36593659
/*

0 commit comments

Comments
 (0)