Skip to content

Conversation

@jkotas
Copy link
Member

@jkotas jkotas commented Dec 21, 2025

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.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas changed the title Split GetInterpThreadContext to allocating and non-allocating variants Split GetInterpThreadContext into allocating and non-allocating variants Dec 21, 2025
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.
@jkotas jkotas force-pushed the InterpThreadContext branch from 220ea5d to 43799fc Compare December 21, 2025 16:07
Copy link
Contributor

Copilot AI left a 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/free to new/delete for consistency
  • Moved interpreter context cleanup in OnThreadTerminate after 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

@jkotas
Copy link
Member Author

jkotas commented Dec 21, 2025

Related to #122404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants