[wasm][interpreter] Defer managed calli cookie resolution to execution time#125455
Conversation
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
|
To consider: with the lazy approach, is the cache check overhead in execution phase ok? Is there better way how to cache the cookie? Also note that the unmanaged path is currently not deferring the cookie resolution to execution phase to avoid the cache check overhead. |
There was a problem hiding this comment.
Pull request overview
This PR changes how the interpreter handles calli signature cookies on portable entry point platforms (notably WASM): instead of requiring the compiler to resolve the cookie up-front, it defers cookie resolution to execution time (and caches it), avoiding compile-time asserts and eliminating the need for the WASM generator’s hard-coded “missing cookie” pre-generation list.
Changes:
- Interpreter compiler now encodes managed
callisites with a signature-token + runtime cookie cache slot (via a newCalliFlags::DeferredCookie). - Interpreter executor (
interpexec.cpp) routes portable-entry-point targets that have aMethodDescthroughCALL_INTERP_METHOD, and lazily resolves/caches cookies for portable entry points without aMethodDesc. - WASM build/gen cleanup removes the
missingCookieslist and removes the corresponding pre-generated interp-to-managed thunks/stubs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs | Removes the temporary missingCookies signature list from thunk/stub generation inputs. |
| src/coreclr/vm/wasm/callhelpers-interp-to-managed.cpp | Removes previously pre-generated signature thunk helpers and their entries from g_wasmThunks. |
| src/coreclr/vm/precode_portable.hpp | Adds PortableEntryPoint::TryGetMethodDesc API for non-asserting lookup. |
| src/coreclr/vm/precode_portable.cpp | Implements TryGetMethodDesc (returns nullptr rather than asserting). |
| src/coreclr/vm/interpexec.cpp | Adds runtime cookie resolution/caching path for deferred managed calli signatures on portable entry points. |
| src/coreclr/interpreter/inc/interpretershared.h | Adds CalliFlags::DeferredCookie to signal runtime resolution. |
| src/coreclr/interpreter/compiler.h | Extends EmitCalli to accept a deferredCookie parameter (defaulted). |
| src/coreclr/interpreter/compiler.cpp | Emits deferred-cookie data items for managed calli on portable entry points; keeps eager cookies for unmanaged calli. |
On portable entry point platforms, calli instructions targeting managed code previously required the compiler to compute a signature cookie at compile time via GetCookieForInterpreterCalliSig. This caused assertion failures for delegate shuffle thunks and
required a hard-coded missingCookies table in the WASM build generator to pre-generate interp-to-native stubs for every possible managed calli signature.
Implements #121222
Changes
Compiler (compiler.cpp):
Newobj helper MethodDesc (jitinterface.cpp, RuntimeHelpers.CoreCLR.cs, corelib.h):
token lookup.
Executor (interpexec.cpp):
entry point and a dummy MethodDesc; the call cookie is derived from the MethodDesc and the native code is invoked via InvokeCalliStub.
Portable entry points (precode_portable.cpp, precode_portable.hpp):
Generator cleanup (ManagedToNativeGenerator.cs, callhelpers-interp-to-managed.cpp):