You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Freeing of rgILMapEntries in ProfToEEInterfaceImpl::SetILInstrumentedCodeMap() #12129
I'm not sure who is right because there are almost no any information about releasing of rgILMapEntries argument in ICorProfilerInfo::SetILInstrumentedCodeMap(), but probably we forgot to free that memory.
This page [ https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms232500(v%3Dvs.100) ] says nothing about transferring ownership for rgILMapEntries, but in this book [ http://blog.monstuff.com/archives/images/Profiling.pdf ] it says The code profiler should not attempt to free this memory.
There is no transfer of ownership. The profiler code can allocate the array any way it likes and it is responsible for freeing it. The array can be freed right after SetILInstrumentedCodeMap returns.
Yes, I saw it, but taking into account the various information I found on the Internet, it still could be an implementation-specific behaviour. So, can profiler developers rely on it?
If yes, does the same apply to .NET Framework in general without reservation?
There was a change in behavior between .NET Framework 2.0 to .NET Framework 4.0.
Before .NET Framework 4.0, the runtime took over the ownership of the memory. The profiler had to allocate the memory using CoTaskMemAlloc and it should not free it.
In .NET Framework 4.0 and all versions of .NET Core, the runtime does not take over the ownership of the memory anymore. The profiler can use any allocator it wishes to allocate the memory and it is responsible for freeing it.
For reference, this is the change description from the .NET Framework source control tracking system:
change 3357811 edit on 2009/06/27 22:37:48
COR_IL_MAP array
Title: Dev10 693636: SetILInstrumentedCodeMap needs to make a copy of the
COR_IL_MAP array
Issue description:
In both V2 and V4, SetILInstrumentedCodeMap() does not make a copy of
the COR_IL_MAP array passed to it as an argument. However, the
documentation on the profiling APIs specifies that the profiler is free
to release the memory after the function call. Thus, the runtime would
be holding onto a dangling pointer after the profiler releases the
memory. We should make a copy of the array instead. This should be
fixed in V4, but it's probably not important enough to fix in V2 since
not many profilers care about updating the IL to native offset mapping
information.
Change description:
Make a copy of the COR_IL_MAP array instead of using COR_IL_MAP array
allocate by the profiler
@k15tfu Yes, I agree that the docs should be updated. Would you like to submit a PR to propose the update?
Activity
jkotas commentedon Feb 27, 2019
Runtime makes a copy of
rgILMapEntries: https://github.com/dotnet/coreclr/blob/ee755e322dabc2fc280e2561b0fbaf6e90aedf54/src/vm/proftoeeinterfaceimpl.cpp#L4624There is no transfer of ownership. The profiler code can allocate the array any way it likes and it is responsible for freeing it. The array can be freed right after SetILInstrumentedCodeMap returns.
k15tfu commentedon Feb 28, 2019
@jkotas,
Yes, I saw it, but taking into account the various information I found on the Internet, it still could be an implementation-specific behaviour. So, can profiler developers rely on it?
If yes, does the same apply to .NET Framework in general without reservation?
Anyway, I think it's really important to clarify it in the docs: https://github.com/dotnet/docs/blob/master/docs/framework/unmanaged-api/profiling/icorprofilerinfo-setilinstrumentedcodemap-method.md . What do you think?
jkotas commentedon Feb 28, 2019
There was a change in behavior between .NET Framework 2.0 to .NET Framework 4.0.
Before .NET Framework 4.0, the runtime took over the ownership of the memory. The profiler had to allocate the memory using CoTaskMemAlloc and it should not free it.
In .NET Framework 4.0 and all versions of .NET Core, the runtime does not take over the ownership of the memory anymore. The profiler can use any allocator it wishes to allocate the memory and it is responsible for freeing it.
For reference, this is the change description from the .NET Framework source control tracking system:
change 3357811 edit on 2009/06/27 22:37:48
@k15tfu Yes, I agree that the docs should be updated. Would you like to submit a PR to propose the update?
sawilde commentedon Mar 3, 2019
beat me to it.
k15tfu commentedon Sep 5, 2019
@jkotas Could you check it pls: dotnet/docs#14228
Allocation and ownership of rgILMapEntries (#14228)
k15tfu commentedon Sep 9, 2019
thanks!