Skip to content
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

Remove Helper Method Frames (HMF) from Reflection #109996

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AaronRobinsonMSFT
Copy link
Member

Convert RuntimeMethodHandle.GetDeclaringType() to managed and QCall.
Convert RuntimeTypeHandle.GetElementType() to managed.
Correct nullability in signature and usage.
Convert RuntimeTypeHandle.GetDeclaringType() to managed and QCalls.
Remove GetRuntimeTypeHelper().

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@AaronRobinsonMSFT
Copy link
Member Author

@EgorBot -intel -arm64 -perf

using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkRunner.Run<Bench>(args: args);

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}

@AaronRobinsonMSFT
Copy link
Member Author

@EgorBot -x64 -arm64 -profiler

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}

@EgorBo
Copy link
Member

EgorBo commented Nov 20, 2024

@AaronRobinsonMSFT the bot complained that -profiler flag should be used when there are not more than 3 [Benchmark] attributes. I think I should improve error reporting 🙂

@EgorBo
Copy link
Member

EgorBo commented Nov 20, 2024

@EgorBot -x64 -arm64

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}

@AaronRobinsonMSFT
Copy link
Member Author

@EgorBot -x64 -arm64 -profiler

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}

Comment on lines +979 to +985
if (pMT->IsArray)
{
IntPtr handle = GetHandleForArray(pMT);
return RuntimeTypeHandle.GetRuntimeTypeFromHandle(handle);
}
else
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pMT->IsArray)
{
IntPtr handle = GetHandleForArray(pMT);
return RuntimeTypeHandle.GetRuntimeTypeFromHandle(handle);
}
else
{

I do not think that this is needed. We got rid of the sharing of methodtable for arrays.

FCALL_CHECK;
}
CONTRACTL_END;
extern "C" TADDR QCALLTYPE RuntimeTypeHandle_GetDeclaringTypeHandleForGenericVariable(EnregisteredTypeHandle pTypeHandle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extern "C" TADDR QCALLTYPE RuntimeTypeHandle_GetDeclaringTypeHandleForGenericVariable(EnregisteredTypeHandle pTypeHandle)
extern "C" EnregisteredTypeHandle QCALLTYPE RuntimeTypeHandle_GetDeclaringTypeHandleForGenericVariable(EnregisteredTypeHandle pTypeHandle)

Should this return EnregisteredTypeHandle?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same for RuntimeTypeHandle::GetElementTypeHandleFromHandle)

CONTRACTL_END;

REFLECTCLASSBASEREF refType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pTypeUNSAFE);
FCIMPL1(TADDR, RuntimeTypeHandle::GetElementTypeHandleFromHandle, EnregisteredTypeHandle th)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FCIMPL1(TADDR, RuntimeTypeHandle::GetElementTypeHandleFromHandle, EnregisteredTypeHandle th)
FCIMPL1(TADDR, RuntimeTypeHandle::GetElementTypeHandle, EnregisteredTypeHandle th)

Omit FromHandle suffix? RuntimeTypeHandle_GetDeclaringTypeHandle does not have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants