-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: fix issue in conditional escape analysis #118214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Conditional escape analysis is triggered by a GDV guarded call to `GetEnumerator`. On the fast path this call is devirtualized and inlined and exposes one or more enumerator object allocations. This allows for collections to do special-case optimizations like returning a static enumerator object for an empty collection. When there is more than one enumerator object allocation under the GDV guard, ensure that only the allocation that was analyzed for conditional escape is stack allocated; the remaining enumerators will end up on the "slow path" where enumeration happens via interface calls, and so must be heap objects. Fixes dotnet#111922.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes an issue in the JIT's conditional escape analysis where multiple enumerator object allocations under a GDV (Guarded Devirtualization) guard could incorrectly be stack allocated. The fix ensures that only the analyzed allocation is stack allocated while others remain heap allocated for proper interface call handling.
Key changes:
- Enhanced CloneInfo structure to track GDV guard and definition blocks
- Added logic to prevent stack allocation of enumerator objects on "slow paths"
- Included regression test to validate the fix
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/coreclr/jit/objectalloc.h | Added fields to CloneInfo for tracking GDV guard and definition blocks |
src/coreclr/jit/objectalloc.cpp | Implemented logic to detect slow path allocations and prevent their stack allocation |
src/tests/JIT/opt/ObjectStackAllocation/Runtime_111922v2.csproj | Test project configuration for regression test |
src/tests/JIT/opt/ObjectStackAllocation/Runtime_111922v2.cs | Regression test reproducing the fixed issue |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
FYI @dotnet/jit-contrib No diffs expected. The libraries tests only occasionally tier up the method that exposes this problem. The attached repro case was reliable on linux x64. |
Co-authored-by: Copilot <[email protected]>
Have some asserts to investigate... |
the DFS tree. Such sites will not be in an enumerator GDV hammock so can be exempted from checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Conditional escape analysis is triggered by a GDV guarded call to
GetEnumerator
. On the fast path this call is devirtualized and inlined and exposes one or more enumerator object allocations. The more case allows for collections to do optimizations like returning a special enumerator object for an empty collection.When there is more than one enumerator object allocation under the GDV guard, ensure that only the allocation that was analyzed for conditional escape is stack allocated; the remaining enumerators will end up on the "slow path" where enumeration happens via interface calls, and so must be heap objects.
Fixes #111922.