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

[mono][wasm] Allow AOTing methods with catch/filter clauses. #64867

Merged
merged 11 commits into from
Mar 1, 2022

Conversation

vargaz
Copy link
Contributor

@vargaz vargaz commented Feb 6, 2022

This works as follows:

  • During EH, when a catch clause is found in an AOTed method, the
    EH state is saved into TLS and a c++ exception is thrown.
  • The C++ exception is caught by the AOTed method, and the landing
    pad code calls mono_llvm_resume_exception_il_state ().
  • That call will run the catch clause and the rest of the method
    code using the interpreter, storing the possible return value
    back into the AOTed method's stack frame.
  • After the call, the method skips the rest of its code, and
    returns immediately to its caller.

@vargaz
Copy link
Contributor Author

vargaz commented Feb 6, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 6, 2022

Running the console benchmark:

BEFORE:

|        Exceptions, NoExceptionHandling |     0.4793us |
|                   Exceptions, TryCatch |     0.4888us |
|              Exceptions, TryCatchThrow |     0.0146ms |
|             Exceptions, TryCatchFilter |     0.4176us |
|       Exceptions, TryCatchFilterInline |     0.2308us |
|        Exceptions, TryCatchFilterThrow |     0.0169ms |
| Exceptions, TryCatchFilterThrowApplies |     0.0170ms |
|         Json, non-ASCII text serialize |     0.8488ms |
|       Json, non-ASCII text deserialize |     1.8116ms |
|                  Json, small serialize |     0.0936ms |
|                Json, small deserialize |     0.1772ms |
|                  Json, large serialize |    16.0582ms |
|                Json, large deserialize |    50.0947ms |

AFTER:

|        Exceptions, NoExceptionHandling |     0.2430us |
|                   Exceptions, TryCatch |     0.3731us |
|              Exceptions, TryCatchThrow |     0.0468ms |
|             Exceptions, TryCatchFilter |     0.5380us |
|       Exceptions, TryCatchFilterInline |     0.3169us |
|        Exceptions, TryCatchFilterThrow |     0.0185ms |
| Exceptions, TryCatchFilterThrowApplies |     0.0177ms |
|         Json, non-ASCII text serialize |     0.9475ms |
|       Json, non-ASCII text deserialize |     1.7774ms |
|                  Json, small serialize |     0.0790ms |
|                Json, small deserialize |     0.1241ms |
|                  Json, large serialize |    16.3476ms |
|                Json, large deserialize |    34.5957ms |

@vargaz
Copy link
Contributor Author

vargaz commented Feb 6, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 6, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 7, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 7, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 8, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

This works as follows:
* During EH, when a catch clause is found in an AOTed method, the
  EH state is saved into TLS and a c++ exception is thrown.
* The C++ exception is caught by the AOTed method, and the landing
  pad code calls mono_llvm_resume_exception_il_state ().
* That call will run the catch clause and the rest of the method
  code using the interpreter, storing the possible return value
  back into the AOTed method's stack frame.
* After the call, the method skips the rest of its code, and
  returns immediately to its caller.
@vargaz
Copy link
Contributor Author

vargaz commented Feb 27, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 27, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Feb 27, 2022

CI failures look unrelated.

Instead of throwing a c++ exception from mono_handle_exception ()
when an exception is caught in AOTed code, set context->has_resume_state,
so the intepreter will normally unwind until exiting interpreted code.
Then throw the c++ exception after the call to interp_exec_method ()
to unwind through the runtime code and the AOTed frames
which can't handle the exception.
@vargaz
Copy link
Contributor Author

vargaz commented Feb 28, 2022

/azp run runtime-wasm

@vargaz
Copy link
Contributor Author

vargaz commented Feb 28, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vargaz
Copy link
Contributor Author

vargaz commented Mar 1, 2022

CI failures look unrelated.

@vargaz vargaz merged commit 783e260 into dotnet:main Mar 1, 2022
@vargaz vargaz deleted the llvmonly-try branch March 1, 2022 06:59
@ghost ghost locked as resolved and limited conversation to collaborators Mar 31, 2022
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.

4 participants