-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Split GetInterpThreadContext into allocating and non-allocating variants #122688
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
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
This ensures that InterpThreadContext is not allocated unless the interpreter is actually used. For example, TryEnsureSufficientExecutionStack allocated InterpThreadContext even when the interpreter is not used.
220ea5d to
43799fc
Compare
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 optimizes interpreter thread context allocation by splitting GetInterpThreadContext into two variants: a non-allocating getter (GetInterpThreadContext) and an allocating/creating variant (GetOrCreateInterpThreadContext). This ensures that InterpThreadContext is only allocated when the interpreter is actually used, avoiding unnecessary allocations in scenarios like TryEnsureSufficientExecutionStack.
Key Changes
- Added
GetOrCreateInterpThreadContext()method that allocates the context if needed - Modified
GetInterpThreadContext()to simply return the existing context (may be null) - Updated all call sites where allocation is needed to use the new
GetOrCreateInterpThreadContext() - Changed memory allocation from
malloc/freetonew/deletefor consistency - Moved interpreter context cleanup in
OnThreadTerminateafter the shutdown check
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/threads.h | Added declaration for GetOrCreateInterpThreadContext() |
| src/coreclr/vm/threads.cpp | Implemented split methods with appropriate contracts; moved cleanup code |
| src/coreclr/vm/prestub.cpp | Updated local helper to use allocating variant |
| src/coreclr/vm/interpexec.cpp | Changed to use allocating variant and switched to new/delete |
| src/coreclr/vm/eetwain.cpp | Removed null checks that are now potentially problematic |
|
Related to #122404 |
janvorli
left a comment
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, thank you!
This ensures that InterpThreadContext is not allocated unless the interpreter is actually used. For example, TryEnsureSufficientExecutionStack allocated InterpThreadContext even when the interpreter is not used.