Change ICorProfilerInfo::SetILFunctionBody to use codeversions #33197
Labels
area-Diagnostics-coreclr
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
#32969 is introducing on stack replacement (OSR) for jitted methods, and this means there is a new sharp edge for profilers to find. Currently we do not prevent (but do have documentation that states you shouldn't) profilers from calling ICorProfilerInfo::SetILFunctionBody after a method has already been jitted. Previous to tiered compilation this would be effectively a no-op, unless rejit was called, since the method was already compiled.
Once tiered compilation was introduced, if a profiler sets the IL after a tier 0 compilation has occurred but before a tier 1 has, then the tier 1 will use different IL and have different behavior than tier 0. While this might be unexpected by the profiler author, it won't cause fatal errors.
With OSR, if a profiler calls SetILFunctionBody after tier 0 the new function will potentially be replaced mid method, and if the IL varies significantly then there is plenty of potential for misbehavior or crashes.
As mentioned in #32969 (comment), we could solve this by using the existing code versioning scheme that we use for rejit and tiered compilation. Some extra care would be necessary to preserve the existing behavior of SetILFunctionBody. We want it to be viewed as the new default IL version, so any code that requests the default version should be redirected to the new version provided to SetILFunctionBody, including RequestRevert.
The text was updated successfully, but these errors were encountered: