blob: e4f3f67d75d14ca2d57a687f7e60884e677d5799 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Internal.TypeSystem;
namespace ILCompiler
{
/// <summary>
/// Controls the way calling convention conversion is performed in
/// <see cref="System.Reflection.MethodBase.Invoke(object, object[])"/>
/// scenarios.
/// </summary>
public abstract class DynamicInvokeThunkGenerationPolicy
{
/// <summary>
/// Gets a value indicating whether reflection-invokable method '<paramref name="targetMethod"/>'
/// should get a static calling convention conversion thunk. Static calling convention
/// conversion thunks speed up reflection invoke of the method at the cost of extra code generation.
/// </summary>
public abstract bool HasStaticInvokeThunk(MethodDesc targetMethod);
}
/// <summary>
/// A thunk generation policy that generates no static invocation thunks.
/// </summary>
public sealed class NoDynamicInvokeThunkGenerationPolicy : DynamicInvokeThunkGenerationPolicy
{
public override bool HasStaticInvokeThunk(MethodDesc targetMethod) => false;
}
/// <summary>
/// A thunk generation policy that uses static invocation thunks whenever possible.
/// </summary>
public sealed class DefaultDynamicInvokeThunkGenerationPolicy : DynamicInvokeThunkGenerationPolicy
{
public override bool HasStaticInvokeThunk(MethodDesc targetMethod)
{
// Place an upper limit on how many parameters a method can have to still get a static stub.
// From the past experience, methods taking 8000+ parameters get a stub that can hit various limitations
// in the codegen. On Project N, we were limited to 256 parameters because of MDIL limitations.
// We don't have such limitations here, but it's a nice round number.
// Reflection invoke will still work, but will go through the calling convention converter.
return targetMethod.Signature.Length <= 256;
}
}
}
|