-
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 static helpers to managed #108167
Move static helpers to managed #108167
Conversation
…hodDesc fields after the normal fields.
Tagging subscribers to this area: @mangod9 |
…ss static data. Should result in very similar to native codegen patterns
…tics even when tls jit optimizations are disabled
...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/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticsHelpers.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticsHelpers.cs
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/StaticsHelpers.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
Show resolved
Hide resolved
…instead of static functions
…ton/runtime into thread_static_helpers
[StructLayout(LayoutKind.Sequential)] | ||
internal unsafe ref struct DynamicStaticsInfo | ||
{ | ||
internal const int ISCLASSINITED = 1; |
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.
Should this be called ISCLASSNOTINITED
to match the name in C++?
[MethodImpl(MethodImplOptions.InternalCall)] | ||
[Intrinsic] | ||
private static extern ref byte VolatileReadAsByref(ref IntPtr address); |
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.
[MethodImpl(MethodImplOptions.InternalCall)] | |
[Intrinsic] | |
private static extern ref byte VolatileReadAsByref(ref IntPtr address); | |
[Intrinsic] | |
private static extern ref byte VolatileReadAsByref(ref IntPtr address) => ref VolatileReadAsByref(ref address); |
Make it must-expand intrinsic and delete the FCall?
[MethodImpl(MethodImplOptions.InternalCall)] | ||
public static extern ref byte MaskStaticsPointer(ref byte staticsPtr); |
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.
[MethodImpl(MethodImplOptions.InternalCall)] | |
public static extern ref byte MaskStaticsPointer(ref byte staticsPtr); | |
public static ref byte MaskStaticsPointer(ref byte staticsPtr) | |
{ | |
fixed (byte* p = staticsPtr) | |
{ | |
return ref *(byte*)((nuint)p & ~(nuint)ISCLASSNOTINITED; | |
} | |
} |
Can this be implemented like this in C# to avoid FCall? It is not on any perf critical path, so a few extra instructions from pinning are not a big deal.
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.
Good point. I had it on the critical path initially, and planned to make it an intrinsic to make it just work with it written as an fcall as a correct stopgap... then I realized I didn't need it on the critical path, and didn't move on from the FCALL.
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static ref byte GetObjectAsRefByte(object obj) | ||
{ | ||
return ref Unsafe.Add(ref Unsafe.As<RawData>(obj)._data, -sizeof(MethodTable*)); |
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.
return ref Unsafe.Add(ref Unsafe.As<RawData>(obj)._data, -sizeof(MethodTable*)); | |
return ref Unsafe.Subtract(ref Unsafe.As<RawData>(obj)._data, sizeof(MethodTable*)); |
/// <summary> | ||
/// Given a statics pointer in the DynamicStaticsInfo, get the actual statics pointer. | ||
/// </summary> | ||
public static ref byte MaskStaticsPointer(ref byte staticsPtr) |
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.
Nit: This can be private method in StaticsHelpers. It is only used in that type.
// Thread static helpers | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
private sealed class RawData |
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.
We have RawData and GetRawData
in RuntimeHelpers.CoreCLR.cs that this should be able to use instead of defining a local clone.
Move the statics helpers from native code, occasionally using a HELPER_METHOD_FRAME, to managed code using QCalls for P/Invoke transition
Particularly notable parts of the change