-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Replace Delegate MethodInfo cache with the MethodDesc #99200
Open
MichalPetryka
wants to merge
30
commits into
dotnet:main
Choose a base branch
from
MichalPetryka:immutable-delegates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+119
−84
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5b3126e
Make delegates immutable
MichalPetryka 64baa1d
Add a comment
MichalPetryka a489288
Optimize cache checks
MichalPetryka b0b31bd
Merge branch 'main' into immutable-delegates
MichalPetryka bc132e4
Fix x86
MichalPetryka 2dce6a8
Fix R2R
MichalPetryka 00fcd02
Update methodcontext.cpp
MichalPetryka 7941123
Fix contract
MichalPetryka 4de2754
Update src/coreclr/vm/object.cpp
MichalPetryka b9f7f14
Swap fields
MichalPetryka 90c6085
Reorder asserts
MichalPetryka 9509023
Fix contract again
MichalPetryka 557bf4d
GCPROTECT
MichalPetryka 1eab602
Merge branch 'main' into immutable-delegates
MichalPetryka 477a3c5
Merge branch 'main' into immutable-delegates
MichalPetryka fff595a
Merge remote-tracking branch 'upstream/main' into immutable-delegates
MichalPetryka 2c16705
Rework equality checks
MichalPetryka cbe22f7
Merge remote-tracking branch 'upstream/main' into immutable-delegates
MichalPetryka bb2a509
Fix compile errors
MichalPetryka 3bb047b
Add asserts
MichalPetryka b957392
Revert some changes, add more caching
MichalPetryka f3e48e1
Add asserts
MichalPetryka 35e4404
Merge branch 'main' into immutable-delegates
MichalPetryka 8701078
Improve GetHashCode
MichalPetryka e22a731
Merge branch 'main' into immutable-delegates
MichalPetryka 63cba0a
Fix GetHashCode
MichalPetryka 10964cd
Massage codegen
MichalPetryka d593b08
Merge remote-tracking branch 'upstream/main' into immutable-delegates
MichalPetryka 26b6e61
Apply feedback
MichalPetryka 99e37d6
Overload invocationList for DynamicMethods
MichalPetryka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1291,8 +1291,9 @@ void COMDelegate::BindToMethod(DELEGATEREF *pRefThis, | |
|
||
LoaderAllocator *pLoaderAllocator = pTargetMethod->GetLoaderAllocator(); | ||
|
||
_ASSERTE(refRealDelegate->GetInvocationList() == NULL); | ||
if (pLoaderAllocator->IsCollectible()) | ||
refRealDelegate->SetMethodBase(pLoaderAllocator->GetExposedObject()); | ||
refRealDelegate->SetInvocationList(pLoaderAllocator->GetExposedObject()); | ||
|
||
GCPROTECT_END(); | ||
} | ||
|
@@ -1725,8 +1726,9 @@ extern "C" void QCALLTYPE Delegate_Construct(QCall::ObjectHandleOnStack _this, Q | |
if (COMDelegate::NeedsWrapperDelegate(pMeth)) | ||
refThis = COMDelegate::CreateWrapperDelegate(refThis, pMeth); | ||
|
||
_ASSERTE(refThis->GetInvocationList() == NULL); | ||
if (pMeth->GetLoaderAllocator()->IsCollectible()) | ||
refThis->SetMethodBase(pMeth->GetLoaderAllocator()->GetExposedObject()); | ||
refThis->SetInvocationList(pMeth->GetLoaderAllocator()->GetExposedObject()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Open delegates. | ||
if (invokeArgCount == methodArgCount) | ||
|
@@ -1817,11 +1819,16 @@ MethodDesc *COMDelegate::GetMethodDesc(OBJECTREF orDelegate) | |
// If you modify this logic, please update DacDbiInterfaceImpl::GetDelegateType, DacDbiInterfaceImpl::GetDelegateType, | ||
// DacDbiInterfaceImpl::GetDelegateFunctionData, and DacDbiInterfaceImpl::GetDelegateTargetObject. | ||
|
||
MethodDesc *pMethodHandle = NULL; | ||
|
||
DELEGATEREF thisDel = (DELEGATEREF) orDelegate; | ||
DELEGATEREF innerDel = NULL; | ||
|
||
MethodDesc *pMethodHandle = thisDel->GetMethodDesc(); | ||
|
||
if (pMethodHandle != NULL) | ||
{ | ||
return pMethodHandle; | ||
} | ||
|
||
INT_PTR count = thisDel->GetInvocationCount(); | ||
if (count != 0) | ||
{ | ||
|
@@ -1889,6 +1896,9 @@ MethodDesc *COMDelegate::GetMethodDesc(OBJECTREF orDelegate) | |
} | ||
|
||
_ASSERTE(pMethodHandle); | ||
|
||
thisDel->SetMethodDesc(pMethodHandle); | ||
|
||
return pMethodHandle; | ||
} | ||
|
||
|
@@ -2132,6 +2142,7 @@ DELEGATEREF COMDelegate::CreateWrapperDelegate(DELEGATEREF delegate, MethodDesc* | |
|
||
// save the secure invoke stub. GetWrapperInvoke() can trigger GC. | ||
PCODE tmp = GetWrapperInvoke(pMD); | ||
|
||
gc.refWrapperDel->SetMethodPtr(tmp); | ||
// save the delegate MethodDesc for the frame | ||
gc.refWrapperDel->SetInvocationCount((INT_PTR)pMD); | ||
|
@@ -2146,34 +2157,32 @@ DELEGATEREF COMDelegate::CreateWrapperDelegate(DELEGATEREF delegate, MethodDesc* | |
} | ||
|
||
// This method will get the MethodInfo for a delegate | ||
extern "C" void QCALLTYPE Delegate_FindMethodHandle(QCall::ObjectHandleOnStack d, QCall::ObjectHandleOnStack retMethodInfo) | ||
extern "C" void QCALLTYPE Delegate_CreateMethodInfo(MethodDesc* methodDesc, QCall::ObjectHandleOnStack retMethodInfo) | ||
{ | ||
QCALL_CONTRACT; | ||
|
||
BEGIN_QCALL; | ||
|
||
GCX_COOP(); | ||
|
||
MethodDesc* pMD = COMDelegate::GetMethodDesc(d.Get()); | ||
MethodDesc* pMD = methodDesc; | ||
pMD = MethodDesc::FindOrCreateAssociatedMethodDescForReflection(pMD, TypeHandle(pMD->GetMethodTable()), pMD->GetMethodInstantiation()); | ||
retMethodInfo.Set(pMD->GetStubMethodInfo()); | ||
|
||
END_QCALL; | ||
} | ||
|
||
extern "C" BOOL QCALLTYPE Delegate_InternalEqualMethodHandles(QCall::ObjectHandleOnStack left, QCall::ObjectHandleOnStack right) | ||
extern "C" MethodDesc* QCALLTYPE Delegate_GetMethodDesc(QCall::ObjectHandleOnStack instance) | ||
{ | ||
QCALL_CONTRACT; | ||
|
||
BOOL fRet = FALSE; | ||
MethodDesc* fRet = nullptr; | ||
|
||
BEGIN_QCALL; | ||
|
||
GCX_COOP(); | ||
|
||
MethodDesc* pMDLeft = COMDelegate::GetMethodDesc(left.Get()); | ||
MethodDesc* pMDRight = COMDelegate::GetMethodDesc(right.Get()); | ||
fRet = pMDLeft == pMDRight; | ||
fRet = COMDelegate::GetMethodDesc(instance.Get()); | ||
|
||
END_QCALL; | ||
|
||
|
@@ -2811,8 +2820,8 @@ MethodDesc* COMDelegate::GetDelegateCtor(TypeHandle delegateType, MethodDesc *pT | |
LoaderAllocator *pTargetMethodLoaderAllocator = pTargetMethod->GetLoaderAllocator(); | ||
BOOL isCollectible = pTargetMethodLoaderAllocator->IsCollectible(); | ||
// A method that may be instantiated over a collectible type, and is static will require a delegate | ||
// that has the _methodBase field filled in with the LoaderAllocator of the collectible assembly | ||
// associated with the instantiation. | ||
// that has the LoaderAllocator of the collectible assembly associated with the instantiation | ||
// stored in the MethodInfo cache. | ||
BOOL fMaybeCollectibleAndStatic = FALSE; | ||
|
||
// Do not allow static methods with [UnmanagedCallersOnlyAttribute] to be a delegate target. | ||
|
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Could any of the checks above be removed now that the "slow" path is not that slow?