Support devirtualization for virtual methods that require runtime lookups#129806
Open
hez2010 wants to merge 16 commits into
Open
Support devirtualization for virtual methods that require runtime lookups#129806hez2010 wants to merge 16 commits into
hez2010 wants to merge 16 commits into
Conversation
Contributor
Author
|
@MihuBot -nuget |
13 tasks
Contributor
Author
|
@MihuBot -nuget -dependsOn 128702 |
5497d14 to
309d8fd
Compare
This was referenced Jun 29, 2026
Open
Contributor
Author
|
This is now ready for review. It's the last piece of the whole story (at least for coreclr). |
Comment on lines
+2774
to
2787
| object helperArg; | ||
| if (entryKind == DictionaryEntryKind.DevirtualizedMethodDescSlot) | ||
| { | ||
| var methodIL = HandleToObject(pResolvedToken.tokenScope); | ||
| MethodDesc sharedMethod = methodIL.OwningMethod.GetSharedRuntimeFormMethodTarget(); | ||
| // We shouldn't be needing shared generics in resumption stubs - generics info should all be stored in the continuation | ||
| Debug.Assert(MethodBeingCompiled is not AsyncResumptionStub); | ||
| _compilation.NodeFactory.DetectGenericCycles(MethodBeingCompiled, sharedMethod); | ||
| helperArg = new MethodWithToken(methodDesc, HandleToModuleToken(ref pResolvedToken, out bool strippedInstantiation), constrainedType, unboxing: false, genericContextObject: sharedMethod, forceOwningTypeFromMethodDesc: strippedInstantiation); | ||
| Debug.Assert(templateMethod != null); | ||
| MethodDesc tokenMethod = (MethodDesc)GetRuntimeDeterminedObjectForToken(ref pResolvedToken); | ||
| if (tokenMethod.HasInstantiation) | ||
| { | ||
| templateMethod = _compilation.TypeSystemContext.GetInstantiatedMethod(templateMethod.GetMethodDefinition(), tokenMethod.Instantiation); | ||
| } | ||
| _compilation.NodeFactory.DetectGenericCycles(MethodBeingCompiled, templateMethod); | ||
| ModuleToken templateMethodToken = | ||
| _compilation.NodeFactory.Resolver.GetModuleTokenForMethod(templateMethod.GetTypicalMethodDefinition(), allowDynamicallyCreatedReference: false, throwIfNotFound: true); | ||
| helperArg = new MethodWithToken(templateMethod, templateMethodToken, constrainedType: null, unboxing: false, genericContextObject: null); | ||
| } |
Contributor
Author
|
@MihuBot -nuget |
Member
|
/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, runtime-coreclr libraries-jitstress |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced Jul 1, 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.
Add support for devirtualizing virtual methods that require a runtime lookup. In this case we can't avoid the expensive runtime lookup, but at least the callee now can be devirtualized and inlined, so that they can benefit from the downstream optimizations like escape analysis, struct promotion and etc.
When we see an inexact instantiating stub on an exact class, we compute a runtime lookup against the shared generic token of the virtual method.
Codegen for
Call:Before:
After:
Contributes to #112596