Skip to content

Represent cached generic context as a local - #132322

Draft
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:jit-generic-context-local
Draft

Represent cached generic context as a local#132322
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:jit-generic-context-local

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

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

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
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:44
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 14, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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’s LclVarDsc stack 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())

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

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants