Skip to content
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

[wasm] Implement MINT_SWITCH opcode in jiterpreter #107423

Merged
merged 3 commits into from
Sep 7, 2024
Merged

Conversation

kg
Copy link
Contributor

@kg kg commented Sep 5, 2024

This PR implements basic support for switches in the jiterpreter, with a configurable size limit (big ones would eat up all the available trace space) that can be set to 0 in order to disable them.

Switch targets that go backwards (Vlad says these should be exceedingly rare) will cause a runtime bailout, as will switches that are too big. In local testing these bailouts are very rare, even with the current low threshold.

If a switch targets places outside of the trace, only those switch targets that are outside will cause bailouts - the rest of them will still work. So even for large traces where half the switch arms aren't reachable, this is still an improvement over how it was before, I think.

In the future if we raise the max trace size we can also raise the size limit on switches - from looking at instrumentation, a limit of 64 or so is probably ideal.

This PR also fixes a bug I noticed - if the jiterpreter trace table filled up we were still generating+compiling a trace and then failing to put it into the table, which wasted CPU time.

Introduce runtime option for max switch size
Disable trace generation once the trace table fills up, since there's no point to it
@kg kg added arch-wasm WebAssembly architecture area-Codegen-Interpreter-mono labels Sep 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

@kg kg marked this pull request as ready for review September 5, 2024 22:16
Copy link
Member

@pavelsavara pavelsavara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrzVlad could you please review the logic please ?

mono_assert(getU16(ip) === MintOpcode.MINT_SWITCH, "decodeSwitch called on a non-switch");
const n = getArgU32(ip, 2);
const result = [];
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not dead code

src/mono/browser/runtime/jiterpreter-support.ts Outdated Show resolved Hide resolved
@kg kg merged commit 5c4686f into dotnet:main Sep 7, 2024
79 of 81 checks passed
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
* Implement MINT_SWITCH opcode (without support for backward jumps)
* Introduce runtime option for max switch size (set to 0 to disable switches)
* Disable trace generation once the trace table fills up, since there's no point to it
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
* Implement MINT_SWITCH opcode (without support for backward jumps)
* Introduce runtime option for max switch size (set to 0 to disable switches)
* Disable trace generation once the trace table fills up, since there's no point to it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants