Replace MethodDescCallSite with UnmanagedCallersOnly for Priority 1 c…#124303
Replace MethodDescCallSite with UnmanagedCallersOnly for Priority 1 c…#124303AaronRobinsonMSFT merged 15 commits intodotnet:mainfrom
Conversation
…all sites Convert the following MethodDescCallSite/CallDescrWorker calls to use UnmanagedCallersOnlyCaller with [UnmanagedCallersOnly] managed wrappers: - EventSource.InitializeDefaultEventSources (corhost.cpp) - StartupHookProvider.CallStartupHook (ds-rt-coreclr.h) - LoaderAllocator constructor (loaderallocator.cpp) - ColorMarshaler.ConvertToManaged/ConvertToNative (interoputil.cpp) - CultureInfo get/set CurrentCulture/CurrentUICulture (threads.cpp) - CultureInfo(int) constructor (interoputil.cpp) - Resolver.GetJitContext/GetCodeInfo/GetLocalsSignature/GetStringLiteral (dynamicmethod.cpp) Contributes to dotnet#123864
There was a problem hiding this comment.
Pull request overview
This PR converts several MethodDescCallSite/CallDescrWorker invocations to use the more efficient UnmanagedCallersOnly pattern with UnmanagedCallersOnlyCaller. This work is part of a broader effort (#123864) to modernize VM-to-managed code calling conventions by replacing the expensive CallDescrWorker mechanism with reverse P/Invoke infrastructure.
Changes:
- Added
[UnmanagedCallersOnly]wrapper methods in managed code for EventSource initialization, startup hooks, culture info operations, color marshaling, dynamic method resolution, and loader allocator creation - Updated native code to use
UnmanagedCallersOnlyCallertemplate class instead ofMethodDescCallSite, with appropriate GC protection for object references - Added metadata signatures in
metasig.hand method definitions incorelib.hto support the new calling convention
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs | Added UnmanagedCallersOnly wrapper for CallStartupHook method |
| src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs | Added UnmanagedCallersOnly wrappers for CurrentCulture/CurrentUICulture getters/setters and CultureInfo constructor |
| src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs | Added UnmanagedCallersOnly wrapper for InitializeDefaultEventSources |
| src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | Added UnmanagedCallersOnly wrappers for ColorMarshaler conversion methods |
| src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs | Added UnmanagedCallersOnly wrappers for Resolver methods (GetJitContext, GetCodeInfo, GetLocalsSignature, GetStringLiteral) |
| src/coreclr/System.Private.CoreLib/src/System/Reflection/LoaderAllocator.cs | Added UnmanagedCallersOnly factory method Create to replace constructor invocation pattern |
| src/coreclr/vm/threads.cpp | Converted GetCulture/SetCulture to use UnmanagedCallersOnlyCaller with proper GC protection |
| src/coreclr/vm/loaderallocator.cpp | Simplified LoaderAllocator initialization to use factory method pattern |
| src/coreclr/vm/interoputil.cpp | Converted GetCultureInfoForLCID and color conversion methods to use UnmanagedCallersOnlyCaller |
| src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h | Converted startup hook application to use UnmanagedCallersOnlyCaller |
| src/coreclr/vm/dynamicmethod.cpp | Converted dynamic method resolver calls to use UnmanagedCallersOnlyCaller with proper GC protection for multi-field structures |
| src/coreclr/vm/corhost.cpp | Converted event source initialization to use UnmanagedCallersOnlyCaller |
| src/coreclr/vm/metasig.h | Added 10 new signature definitions for UnmanagedCallersOnly methods |
| src/coreclr/vm/corelib.h | Updated method definitions to reference new UnmanagedCallersOnly entry points with _UCO suffixes or CREATE for factory methods |
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
Eliminate temp variables in trivial UCO wrappers
…th bool, add CLR_BOOL_ARG macro
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <[email protected]>
|
@radekdoulik This is still failing with a signature mismatch. I'll try generating the data on linux. |
|
@radekdoulik Looks like problem with overloads. I'd forgotten about that. I added a check for |
janvorli
left a comment
There was a problem hiding this comment.
LGTM, thank you. I haven't tried to verify the sanity of the src/coreclr/vm/wasm/callhelpers-reverse.cpp changes, I assume this is generated, right?
Yep, all generated. Hoping we can get that into a better pipeline or get crossgen up soon. It is a bit cumbersome at present. The instructions are solid though. Thanks @radekdoulik ! |
…all sites
Convert the following
MethodDescCallSite/CallDescrWorkercalls to useUnmanagedCallersOnlyCallerwith[UnmanagedCallersOnly]managed wrappers:Contributes to #123864