diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
index a4ddab439f6c07..9574dae04aec42 100644
--- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -185,6 +185,7 @@
+
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
index f58e24742dc500..3766f4af5f4cfe 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
@@ -1,21 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using static System.Reflection.InvokerEmitUtil;
+using static System.Reflection.MethodBase;
+using static System.RuntimeType;
+
namespace System.Reflection
{
public partial class ConstructorInvoker
{
- private readonly Signature? _signature;
+ private readonly CreateUninitializedCache? _allocator;
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private object CreateUninitializedObject() => _allocator!.CreateUninitializedObject(_declaringType);
- internal unsafe ConstructorInvoker(RuntimeConstructorInfo constructor) : this(constructor, constructor.Signature.Arguments)
+ private bool ShouldAllocate
{
- _signature = constructor.Signature;
- _invokeFunc_RefArgs = InterpretedInvoke;
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get => _allocator is not null;
+ }
+ private unsafe Delegate CreateInvokeDelegateForInterpreted()
+ {
+ Debug.Assert(MethodInvokerCommon.UseInterpretedPath);
+ Debug.Assert(_strategy == InvokerStrategy.Ref4 || _strategy == InvokerStrategy.RefMany);
+
+ return (InvokeFunc_RefArgs)InterpretedInvoke;
}
- private unsafe object? InterpretedInvoke(object? obj, IntPtr* args)
+ private unsafe object? InterpretedInvoke(IntPtr _, object? obj, IntPtr* args)
{
- return RuntimeMethodHandle.InvokeMethod(obj, (void**)args, _signature!, isConstructor: obj is null);
+ return RuntimeMethodHandle.InvokeMethod(obj, (void**)args, _method.Signature, isConstructor: obj is null);
}
}
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs
index abdb8be14b27a3..61dce1500552c6 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.CoreCLR.cs
@@ -90,7 +90,7 @@ private MethodBaseInvoker Invoker
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
- return _invoker ??= new MethodBaseInvoker(this, Signature);
+ return _invoker ??= new MethodBaseInvoker(this, Signature.Arguments, ReturnType);
}
}
@@ -132,13 +132,17 @@ Signature LazyCreateSignature()
int argCount = (parameters != null) ? parameters.Length : 0;
if (Signature.Arguments.Length != argCount)
throw new TargetParameterCountException(SR.Arg_ParmCnt);
- object? retValue = argCount switch
+
+ object? retValue = Invoker.Strategy switch
{
- 0 => Invoker.InvokeWithNoArgs(obj, invokeAttr),
- 1 => Invoker.InvokeWithOneArg(obj, invokeAttr, binder, parameters!, culture),
- 2 or 3 or 4 => Invoker.InvokeWithFewArgs(obj, invokeAttr, binder, parameters!, culture),
- _ => Invoker.InvokeWithManyArgs(obj, invokeAttr, binder, parameters!, culture),
+ MethodBase.InvokerStrategy.Obj0 => Invoker.InvokeWithNoArgs(obj, invokeAttr),
+ MethodBase.InvokerStrategy.Obj1 => Invoker.InvokeWith1Arg(obj, invokeAttr, binder, parameters!, culture),
+ MethodBase.InvokerStrategy.Obj4 => Invoker.InvokeWith4Args(obj, invokeAttr, binder, parameters!, culture),
+ MethodBase.InvokerStrategy.ObjSpan => Invoker.InvokeWithSpanArgs(obj, invokeAttr, binder, parameters!, culture),
+ MethodBase.InvokerStrategy.Ref4 => Invoker.InvokeWith4RefArgs(obj, invokeAttr, binder, parameters, culture),
+ _ => Invoker.InvokeWithManyRefArgs(obj, invokeAttr, binder, parameters!, culture)
};
+
GC.KeepAlive(this);
return retValue;
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
index f79445292e7cbc..be0b0c90e8e40b 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Reflection
@@ -15,152 +14,188 @@ internal static unsafe class InstanceCalliHelper
// Zero parameter methods such as property getters:
[Intrinsic]
+ [MethodImpl(MethodImplOptions.NoInlining)]
internal static bool Call(delegate*