Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract partial class Delegate : ICloneable, ISerializable
{
// MethodBase, either cached after first request or assigned from a DynamicMethod
// For open delegates to collectible types, this may be a LoaderAllocator object
internal object? _methodBase;
internal object? _helperObject;
Comment thread
jkotas marked this conversation as resolved.
Comment thread
jkotas marked this conversation as resolved.

// _target is the object we will invoke on; null if static delegate
internal object? _target; // Keep _target and _methodPtr next to each other for optimal delegate invoke performance
Expand Down Expand Up @@ -80,7 +80,7 @@ protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Al
protected virtual object? DynamicInvokeImpl(object?[]? args)
{
RuntimeMethodHandleInternal method = new RuntimeMethodHandleInternal(GetInvokeMethod());
RuntimeMethodInfo invoke = (RuntimeMethodInfo)RuntimeType.GetMethodBase((RuntimeType)this.GetType(), method)!;
RuntimeMethodInfo invoke = (RuntimeMethodInfo)RuntimeType.GetMethodBase((RuntimeType)GetType(), method)!;

return invoke.Invoke(this, BindingFlags.Default, null, args, null);
}
Expand Down Expand Up @@ -132,8 +132,8 @@ public override bool Equals([NotNullWhen(true)] object? obj)

// method ptrs don't match, go down long path

if (_methodBase is MethodInfo && d._methodBase is MethodInfo)
return _methodBase.Equals(d._methodBase);
if (_helperObject is MethodInfo && d._helperObject is MethodInfo)
return _helperObject.Equals(d._helperObject);
else
return InternalEqualMethodHandles(this, d);
}
Expand All @@ -146,9 +146,9 @@ public override int GetHashCode()
// different hashcode which is not true.
/*
if (_methodPtrAux == IntPtr.Zero)
return unchecked((int)((long)this._methodPtr));
return unchecked((int)((long)_methodPtr));
else
return unchecked((int)((long)this._methodPtrAux));
return unchecked((int)((long)_methodPtrAux));
*/
if (_methodPtrAux == IntPtr.Zero)
return (_target != null ? RuntimeHelpers.GetHashCode(_target) * 33 : 0) + GetType().GetHashCode();
Expand All @@ -158,7 +158,7 @@ public override int GetHashCode()

protected virtual MethodInfo GetMethodImpl()
{
if (_methodBase is MethodInfo methodInfo)
if (_helperObject is MethodInfo methodInfo)
{
return methodInfo;
}
Expand Down Expand Up @@ -208,14 +208,14 @@ protected virtual MethodInfo GetMethodImpl()
else
{
// it's an open one, need to fetch the first arg of the instantiation
MethodInfo invoke = this.GetType().GetMethod("Invoke")!;
MethodInfo invoke = GetType().GetMethod("Invoke")!;
declaringType = (RuntimeType)invoke.GetParametersAsSpan()[0].ParameterType;
}
}
}

_methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method)!;
return (MethodInfo)_methodBase;
_helperObject = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method)!;
return (MethodInfo)_helperObject;
}

public object? Target => GetTarget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ private unsafe MulticastDelegate NewMulticastDelegate(object[] invocationList, i
// copy _methodPtr and _methodPtrAux fields rather than calling into the EE to get them
if (thisIsMultiCastAlready)
{
result._methodPtr = this._methodPtr;
result._methodPtrAux = this._methodPtrAux;
result._methodPtr = _methodPtr;
result._methodPtrAux = _methodPtrAux;
}
else
{
Expand All @@ -167,7 +167,7 @@ internal MulticastDelegate NewMulticastDelegate(object[] invocationList, int inv
internal void StoreDynamicMethod(MethodInfo dynamicMethod)
{
Debug.Assert(_invocationCount == 0);
_methodBase = dynamicMethod;
_helperObject = dynamicMethod;
}

// This method will combine this delegate with the passed delegate
Expand Down Expand Up @@ -304,7 +304,7 @@ private static bool EqualInvocationLists(object[] a, object[] b, int start, int
if (_invocationList is not object[] invocationList)
{
// they are both not real Multicast
if (this.Equals(value))
if (Equals(value))
return null;
}
else
Expand Down Expand Up @@ -455,7 +455,7 @@ protected override MethodInfo GetMethodImpl()
{
// we handle unmanaged function pointers here because the generic ones (used for WinRT) would otherwise
// be treated as open delegates by the base implementation, resulting in failure to get the MethodInfo
if (_methodBase is MethodInfo methodInfo)
if (_helperObject is MethodInfo methodInfo)
{
return methodInfo;
}
Expand All @@ -466,13 +466,13 @@ protected override MethodInfo GetMethodImpl()
// need a proper declaring type instance method on a generic type
if (declaringType.IsGenericType)
{
// we are returning the 'Invoke' method of this delegate so use this.GetType() for the exact type
// we are returning the 'Invoke' method of this delegate so use GetType() for the exact type
RuntimeType reflectedType = (RuntimeType)GetType();
declaringType = reflectedType;
}

_methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method)!;
return (MethodInfo)_methodBase;
_helperObject = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method)!;
return (MethodInfo)_helperObject;
}

return base.GetMethodImpl();
Expand All @@ -491,16 +491,16 @@ private void CtorClosed(object target, IntPtr methodPtr)
{
if (target == null)
ThrowNullThisInDelegateToInstance();
this._target = target;
this._methodPtr = methodPtr;
_target = target;
_methodPtr = methodPtr;
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorClosedStatic(object target, IntPtr methodPtr)
{
this._target = target;
this._methodPtr = methodPtr;
_target = target;
_methodPtr = methodPtr;
}

[DebuggerNonUserCode]
Expand All @@ -509,55 +509,55 @@ private void CtorRTClosed(object target, IntPtr methodPtr)
{
if (target == null)
ThrowNullThisInDelegateToInstance();
this._target = target;
this._methodPtr = AdjustTarget(target, methodPtr);
_target = target;
_methodPtr = AdjustTarget(target, methodPtr);
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorOpened(object target, IntPtr methodPtr, IntPtr shuffleThunk)
{
this._target = this;
this._methodPtr = shuffleThunk;
this._methodPtrAux = methodPtr;
_target = this;
_methodPtr = shuffleThunk;
_methodPtrAux = methodPtr;
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorVirtualDispatch(object target, IntPtr methodPtr, IntPtr shuffleThunk)
{
this._target = this;
this._methodPtr = shuffleThunk;
this.InitializeVirtualCallStub(methodPtr);
_target = this;
_methodPtr = shuffleThunk;
InitializeVirtualCallStub(methodPtr);
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorCollectibleClosedStatic(object target, IntPtr methodPtr, IntPtr gchandle)
{
this._target = target;
this._methodPtr = methodPtr;
this._methodBase = GCHandle.InternalGet(gchandle);
Comment thread
jkotas marked this conversation as resolved.
_target = target;
_methodPtr = methodPtr;
_helperObject = GCHandle.InternalGet(gchandle);
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorCollectibleOpened(object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
{
this._target = this;
this._methodPtr = shuffleThunk;
this._methodPtrAux = methodPtr;
this._methodBase = GCHandle.InternalGet(gchandle);
_target = this;
_methodPtr = shuffleThunk;
_methodPtrAux = methodPtr;
_helperObject = GCHandle.InternalGet(gchandle);
}

[DebuggerNonUserCode]
[DebuggerStepThrough]
private void CtorCollectibleVirtualDispatch(object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
{
this._target = this;
this._methodPtr = shuffleThunk;
this._methodBase = GCHandle.InternalGet(gchandle);
this.InitializeVirtualCallStub(methodPtr);
_target = this;
_methodPtr = shuffleThunk;
_helperObject = GCHandle.InternalGet(gchandle);
InitializeVirtualCallStub(methodPtr);
}
#pragma warning restore IDE0060
}
Expand Down
Loading
Loading