-
Notifications
You must be signed in to change notification settings - Fork 5.3k
JIT: Devirtualize non-shared generic virtual methods #122023
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
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 PR enables devirtualization support for generic virtual methods in the JIT compiler, allowing calls to generic virtual methods to be devirtualized when the exact type is known at JIT time. This optimization eliminates virtual dispatch overhead and enables further optimizations like inlining.
Key changes:
- Removes the assertion that previously blocked generic method devirtualization
- Generalizes array interface devirtualization to support generic virtual methods by renaming
wasArrayInterfaceDevirttoneedsMethodContext - Adds runtime lookup support for generic method instantiation parameters
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/jitinterface.cpp | Removes assertion blocking generic method devirtualization and adds logic to handle generic virtual methods using FindOrCreateAssociatedMethodDesc |
| src/coreclr/inc/corinfo.h | Renames wasArrayInterfaceDevirt to needsMethodContext to generalize the field meaning |
| src/coreclr/jit/jitconfigvalues.h | Adds JitEnableGenericVirtualDevirtualization configuration flag to control the feature |
| src/coreclr/jit/gentree.h | Adds IsGenericVirtual() helper method to identify generic virtual method calls |
| src/coreclr/jit/gentree.cpp | Updates IsDevirtualizationCandidate() to include generic virtual methods (non-AOT only) |
| src/coreclr/jit/importercalls.cpp | Implements devirtualization logic for generic virtual methods including runtime lookup handling, updates comments and variable names, and introduces DEVIRT label for control flow |
| src/coreclr/jit/inline.h | Renames arrayInterface field to needsMethodContext in InlineCandidateInfo struct |
| src/coreclr/jit/indirectcalltransformer.cpp | Updates to use renamed needsMethodContext field |
| src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | Updates managed struct definition to match renamed field |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Updates to use renamed field in managed implementation |
| src/coreclr/tools/superpmi/superpmi-shared/agnostic.h | Updates SuperPMI data structure with renamed field |
| src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp | Updates SuperPMI recording/replay to use renamed field |
530e75d to
6e678a5
Compare
jakobbotsch
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 apart from that. Thanks!
@davidwrighton can you take a look too?
|
@hez2010 sorry about the delay, I got stuck in a bunch of work just before the holidays and wasn't able to do the review before vacation began. |
|
I'm guessing the crossgen issues are related, I don't see them on other PRs. Can you see if you can reproduce them? |
I managed to reproduce the freebsd one on my local cross-build environment. Will investigate it soon to see whether it's related or not. |
|
We hit the assertion here: I think GVM applies the same with virtual stub, where in R2R mode, we might see GVM calls to non-virtuals. I think we should change the assertion to |
Seems reasonable to me. |
|
CI is green now. |
|
/azp run runtime-coreclr jitstress, runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 2 pipeline(s). |
I am not sure, perhaps that is something specific to how the crossgen2 testing is done for the community targets. I kicked off some more testing. There are some known test failures in jitstress (for async), so might take some filtering once it's done to validate things. |
All failures seem to be preexisting and unrelated. |
|
/ba-g Failure is #122345 that is not being matched automatically |
|
Thanks! |
Enable devirtualization support for generic virtual methods.
When we see a base method having a method instantiation, we use
FindOrCreateAssociatedMethodDescto obtain the devirted method.Also introduced a jit knob so that it can be turned off at any time.
AOT support is not included in this PR, which needs additional work in managed type system.
Also, if we end up with an instantiating stub (i.e. a shared generic method that requires runtime lookup), we don't have the correct generic context so we need to bail out for now.
Codegen example:
Codegen diff:
Contributes to #112596
cc: @dotnet/jit-contrib