Skip to content

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Jan 12, 2025

WASM aot supports the deopt mode for a method, in which case the method will be aot compiled but the exception handlers are later invoked via the interpreter, if an exception is thrown. This is an alternative to fully interpreting the method in question. A problem can arise if an exception is caught inside a finally handler, because the start of the finally handler will be executed with AOT and then, once the exception is caught, the rest of the handler would be executed with the interprer. This is because the implementation of ENDFINALLY in the interpreter requires some information to have been initialized when the handler is called, initialization which is missing since the handler was called by AOT.

The original code referenced this issue, but the condition to detect this situation was very relaxed, including common cases like try { try {} catch {} } finally { }. This commit changes the check so it is only hit for scenarios like try { } finally { try { } catch { } }.

fixes: #111281

WASM aot supports the `deopt` mode for a method, in which case the method will be aot compiled but the exception handlers are later invoked via the interpreter, if an exception is thrown. This is an alternative to fully interpreting the method in question. A problem can arise if an exception is caught inside a finally handler, because the start of the finally handler will be executed with AOT and then, once the exception is caught, the rest of the handler would be executed with the interprer. This is because the implementation of ENDFINALLY in the interpreter requires some information to have been initialized when the handler is called, initialization which is missing since the handler was called by AOT.

The original code referenced this issue, but the condition to detect this situation was very relaxed, including common cases like `try { try {} catch {} } finally { }`. This commit changes the check so it is only hit for scenarios like `try { } finally { try { } catch { } }`.
@BrzVlad
Copy link
Member Author

BrzVlad commented Jan 14, 2025

cc @pavelsavara @lewing

@pavelsavara
Copy link
Member

Do we also need to change the scope of IL trimming (of method body) to reap size benefits ?

@jeromelaban
Copy link
Contributor

@pavelsavara I'd tend to think, given @BrzVlad's explanation of EH that because the runtime's need for IL for running EH blocks, this particular AOT condition change won't impact IL stripping.

jeromelaban added a commit to unoplatform/Uno.DotnetRuntime.WebAssembly that referenced this pull request Jan 20, 2025
* chore: Apply patch from dotnet/runtime#111318

* ci: Update artifacts steps

* chore: Adjust patch

* chore: Adjust ubuntu

* chore: Adjust runners

* chore: adjust net install

* chore: Adjust net installer

* chore: remove container
@jeromelaban
Copy link
Contributor

FYI, we're using this change in production and it's doing great so far.

@lewing
Copy link
Member

lewing commented Jan 23, 2025

FYI, we're using this change in production and it's doing great so far.

That's useful data. We'll take it in 10 and look at servicing

@jeromelaban
Copy link
Contributor

That's useful data. We'll take it in 10 and look at servicing

I forgot to mention, it was backported to net8.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Wasm][AOT] methods with try/catch/finally blocks are not AOTed
4 participants