Skip to content

Commit 7b7d2fd

Browse files
committed
[mono] Actually free dynamic methods, even if we have profiler attached (dotnet#119749)
* [mono] Actually free dynamic methods, even if we have profiler attached Ever since the early days of mono, freeing dynamic methods was disabled if a profiler was attached. The reason for this was probably that the profiler might store `MonoMethod` instances in its own data, leading to problems if we free those instances. Looking at the profilers nowadays it is not clear where patterns like this would happen. Profilers that do store methods (like aot, coverage), don't process wrapper methods, so we should be safe since dynamic methods have the MONO_WRAPPER_DYNAMIC_METHOD wrapper type. The problem is that, nowadays, we can always have a profiler attached even if no actual profiling happens. macios for example always calls mono_profiler_install. I belive actual callbacks can be added later as necessary. * Disable freeing dynamic methods only when eventpipe or debugger are enabled
1 parent 13f2da3 commit 7b7d2fd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/mono/mono/metadata/loader.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <mono/metadata/loader-internals.h>
3737
#include <mono/metadata/class-init.h>
3838
#include <mono/metadata/class-internals.h>
39+
#include <mono/metadata/components.h>
3940
#include <mono/metadata/debug-helpers.h>
4041
#include <mono/metadata/reflection.h>
4142
#include <mono/metadata/profiler-private.h>
@@ -1371,8 +1372,11 @@ mono_free_method (MonoMethod *method)
13711372

13721373
MONO_PROFILER_RAISE (method_free, (method));
13731374

1374-
/* FIXME: This hack will go away when the profiler will support freeing methods */
1375-
if (G_UNLIKELY (mono_profiler_installed ()))
1375+
// EventPipe might require information about methods to be stored throughout
1376+
// entire app execution, so stack traces can be resolved at a later time.
1377+
// Same for debugger, we are being overly conservative
1378+
if (mono_component_event_pipe ()->component.available () ||
1379+
mono_component_debugger ()->component.available ())
13761380
return;
13771381

13781382
if (method->signature) {

0 commit comments

Comments
 (0)