[wasm][coreclr] Cache calli cookies#127016
Merged
radekdoulik merged 24 commits intodotnet:mainfrom May 5, 2026
Merged
Conversation
Avoid repeated expensive calls to get calli cookie by caching it
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
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. |
jkotas
reviewed
Apr 17, 2026
jkotas
reviewed
Apr 17, 2026
…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>
This was referenced Apr 27, 2026
jkotas
approved these changes
Apr 27, 2026
jkotas
reviewed
May 3, 2026
jkotas
reviewed
May 3, 2026
jkotas
reviewed
May 3, 2026
This was referenced May 4, 2026
Member
Author
|
/ba-g infra issues |
kotlarmilos
added a commit
that referenced
this pull request
May 7, 2026
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid repeated expensive calls to get calli cookie by caching it
Checked in HelloWorld