Represent cached generic context as a local - #132322
Draft
AndyAyersMS wants to merge 1 commit into
Draft
Conversation
Replace the anonymous generic-context frame offset with an early-created internal local while preserving existing reporting, OSR, and tailcall behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 207fb832-c84e-4e9c-b949-3921e19731ce
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces the standalone “cached generic context” frame offset bookkeeping with an early-created internal local (lvaCachedGenericContextArg) whose stack offset is assigned during frame layout, aiming to preserve existing reporting (GC), OSR, and tailcall behavior.
Changes:
- Introduce an internal temp local to represent the cached generic context argument / reportable “this” slot, instead of tracking a raw frame offset.
- Update frame layout/refcount logic to (a) conditionally keep the local dormant/off-frame, and (b) assign/propagate its virtual stack offset (including OSR reuse of the root frame slot).
- Redirect
lvaCachedGenericContextArgOffset()to read from the local’sLclVarDscstack offset.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/jit/lclvars.cpp | Creates and manages the new internal local; updates refcount and frame-layout paths to use its stack offset. |
| src/coreclr/jit/compiler.hpp | Makes lvaCachedGenericContextArgOffset() return the new local’s stack offset (with an assert). |
| src/coreclr/jit/compiler.h | Replaces the cached offset field with a cached-local var number initialized to BAD_VAR_NUM. |
Suppressed comments (1)
src/coreclr/jit/lclvars.cpp:5110
- On JIT32_GCENCODER, lvaKeepAliveAndReportThis() can be true (e.g., synchronized instance methods), but this block is currently compiled out. That leaves lvaCachedGenericContextArg.lvOnFrame set (in lvaMarkLocalVars) without ever assigning a stack offset, and the later locals-allocation loop also skips lvaCachedGenericContextArg, so lvaCachedGenericContextArgOffset() can end up returning BAD_STK_OFFS when GC encoding asks for the reportable slot.
#ifndef JIT32_GCENCODER
else if (lvaKeepAliveAndReportThis())
{
bool canUseExistingSlot = false;
if (opts.IsOSR())
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the anonymous generic-context frame offset with an early-created internal local while preserving existing reporting, OSR, and tailcall behavior.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com