Support devirtualization for virtual methods that require an instantiating stub#128702
Open
hez2010 wants to merge 24 commits into
Open
Support devirtualization for virtual methods that require an instantiating stub#128702hez2010 wants to merge 24 commits into
hez2010 wants to merge 24 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Enables devirtualization of generic virtual methods and default interface methods (DIMs) on generic interfaces, by computing and passing the instantiation argument needed at runtime, instead of failing devirtualization in those cases.
Changes:
- In the VM JIT interface, remove the early bail-out for generic DIMs and shared generic virtual methods, and instead compute
instParamLookup/ re-resolve via the exact (non-shared) MethodDesc when possible; defer the instantiating-stub unwrap until aftertokenLookupContextis set. - In the managed JIT interface (
CorInfoImpl), add parallel logic to populateinstParamLookupfor generic DIM / generic virtual / array-interface devirtualization (R2R usesTypeDictionary/MethodHandlehelpers; NativeAOT path returnsFAILED_CANONfor now), and switchtokenLookupContextto a method context where appropriate. - In
DevirtualizationManager, drop the unconditional generic-virtual canon bail-out and, for R2R, only fail DIM resolution on variant dispatch (allowing generic DIMs); keep the stricter pre-existing behavior for NativeAOT.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/coreclr/vm/jitinterface.cpp | Allow devirt to generic DIM / shared GVM by computing exact MD and instParamLookup; move instantiating-stub unwrap after context setup. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Add instParamLookup population for generic DIM / GVM / array-interface cases; adjust tokenLookupContext; gate AOT vs R2R behavior. |
| src/coreclr/tools/Common/Compiler/DevirtualizationManager.cs | For R2R, only fail DIM resolution on variant dispatch; remove unconditional shared-GVM canon bail-out. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DevirtualizationManager.cs | Update stale comment numbering after removing the DIM-restriction note. |
16 tasks
Contributor
Author
Contributor
Author
|
@MihuBot -nuget |
This was referenced May 29, 2026
Member
|
/azp run runtime-coreclr outerloop, runtime-coreclr pgo, runtime-coreclr pgostress, runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 4 pipeline(s). |
Contributor
Author
|
All test failures seem unrelated. PTAL. |
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.
Enable devirtualization of virtual methods that require an instantiating stub.
We have landed the refactor in the JIT so that now we are able to handle instantiating stub naturally without a JIT change.
This covers both shared generic virtual methods that don't require a runtime lookup, and generic interface methods that have a default implementation.
GVM devirt for NativeAOT requires more changes which is out of scope of this PR.
Before:
After:
Similar for R2R:
For NativeAOT:
Before:
After:
Also added a couple of tests from #43668.
Closes #9588
Contributes to #112596
/cc: @jakobbotsch @davidwrighton @MichalStrehovsky