In current design, after calling a function in LLVM JITed/AOTed code, the caller will check whether the exception was thrown, no matter whether hw bound check is enabled or not, this introduces the compare and condition jump instructions. Theoretically we can disable it and use guard page for the exception check instead when hw bound check is enabled:
- Create a guard page for the module_inst or exec_env, when wasm_set_exception, after setting the module_inst->cur_exception, let runtime access the guard page, so as to trigger the signal handler
- In the signal handler, handle the exception, and longjmp into to the setjmp place to exit
By this way, we can reduce the check instructions in the caller, normally it can improve the performance. Experiments show that many cases can get performance improvement and few cases get a little perf drop, e.g. CoreMark.
Another benefit is that it can speedup the LLVM JIT/AOT compilation.