Uh oh!
There was an error while loading. Please reload this page.
[wasm][coreclr] Cache calli cookies - #127016
Conversation
Avoid repeated expensive calls to get calli cookie by caching it
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
Pull request overview
This PR reduces overhead in the WASM interpreter call path by caching the computed calli cookie on the MethodDesc, avoiding repeated (and potentially expensive) cookie computation for repeated invocations of the same managed method.
Changes:
- Cache and reuse a per-
MethodDesccalli cookie inInvokeManagedMethodon WASM. - Extend
MethodDescCodeData(portable entrypoints + interpreter builds) to store aCalliCookie. - Add
MethodDesc::{GetCalliCookie, SetCalliCookie}APIs to manage the cached value thread-safely.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/vm/wasm/helpers.cpp | Uses MethodDesc-cached cookie to avoid repeated GetCookieForCalliSig calls. |
| src/coreclr/vm/method.hpp | Adds CalliCookie storage in MethodDescCodeData and declares accessor APIs under the relevant feature flags. |
| src/coreclr/vm/method.cpp | Implements thread-safe cookie get/set using EnsureCodeDataExists + interlocked/volatile operations. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…Cookie typedef - Define InterpreterCalliCookie typedef: function pointer on WASM, CallStubHeader* on non-WASM (Jan's feedback) - Unify SetCalliCookie/GetCalliCookie API, removing the separate SetCallStub/GetCallStub and FEATURE_PORTABLE_ENTRYPOINTS branching in MethodDesc - Cache calli cookie on targetMethod in the WASM calli path in interpexec.cpp (Jan's feedback) - Re-read cookie after SetCalliCookie in wasm/helpers.cpp to use the race-winning value (Aaron's feedback) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
radekdoulik
commented
May 5, 2026
/ba-g infra issues |
Uh oh!
There was an error while loading. Please reload this page.
…127876) ## Problem PR #127016 updated `MethodDescCodeData::CallStub` added a new writer in `CInterpreterJitInfo::GetCookieForInterpreterCalliSig` that caches a calli signature `CallStubHeader*` on the P/Invoke target `MethodDesc`. PR #127016 added a small "calli cookie" cache. Each managed method has one slot where this cookie is stored. The problem is that two different parts of the runtime now write to that one slot: - The interpreter-to-native call path stores a helper that's set up for the method's own signature - The new code in #127016 stores a helper that's set up for the signature of a `calli` instruction inside an IL stub. On iOS, when an app tries to execute address 0 the kernel does not give us a normal crash. It assumes the page is unsigned/tampered and kills the process with `SIGKILL` and a `CODESIGNING / Invalid Page` reason. ## Proposed fix Drop the new `pContextMD->{Set,Get}CalliCookie` cache reads/writes in `CInterpreterJitInfo::GetCookieForInterpreterCalliSig`. The function now always computes the cookie via `GetCookieForCalliSig(sig, pContextMD)`, matching pre-#127016 behavior. Fixes#127869#127863#127867 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid repeated expensive calls to get calli cookie by caching it
Checked in HelloWorld