-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Move TypeReference.ToObject to managed (CoreCLR) #70055
Move TypeReference.ToObject to managed (CoreCLR) #70055
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection Issue Details
OverviewThis PR moves API additions (CoreCLR-only)namespace System
{
public unsafe struct RuntimeTypeHandle
{
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe MethodTable* GetElementTypeMethodTable(CorElementType elementType);
}
}
namespace System.Runtime.CompilerServices
{
internal unsafe struct TypeHandle
{
public bool IsNull { get; }
public TypeDesc* AsTypeDesc();
public MethodTable* GetMethodTable();
}
internal unsafe struct TypeDesc
{
private readonly uint TypeAndFlags;
public MethodTable* GetMethodTable();
public CorElementType GetInternalCorElementType();
}
internal unsafe struct ParamTypeDesc
{
public readonly uint TypeAndFlags;
public readonly MethodTable* m_TemplateMT;
public readonly TypeHandle m_Arg;
public readonly void* m_hExposedClassObject;
public MethodTable* GetTemplateMethodTableInternal();
}
} Benchmarks
Benchmark code (click to expand):using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
[DisassemblyDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class ArrayGetValueBenchmark
{
private string text = "Hello world";
private int number = 42;
[Benchmark]
[BenchmarkCategory("REF_TYPE")]
public object? ToObject_String()
{
return TypedReference.ToObject(__makeref(text));
}
[Benchmark]
[BenchmarkCategory("VALUE_TYPE")]
public object? ToObject_Int()
{
return TypedReference.ToObject(__makeref(number));
}
}
|
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/TypedReference.cs
Outdated
Show resolved
Hide resolved
871e46c
to
2e8db94
Compare
The new tests are failing on Mono. Open an issue on it and disable the tests against it. |
Looks like the tests are not failing, but just can't even compile on Mono 🤔
So |
|
If it is causing the Mono AOT compiler the crash, we do not have a good way to deal with it today. I guess you can comment out the test for now. |
Ah, gotcha. Will do that, thank you! 🙂 |
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.
Thank you!
Overview
This PR moves
TypedReference.ToObject
to managed in CoreCLR.I've only added an FCall to handle a slow path that's only ever taken when
T
is a function pointer.This is to avoid having to port a whole lot of additional VM code to C# as well.
All other paths, both for reference types and value types (using the new
RuntimeHelpers.Box
API) are managed now.Benchmarks
Benchmark code (click to expand):