So far we have generated code that is 100% equivallent to the methods byte code. But in case of exception this is a little problematic. Let me explain.
For each generated method we have Prolog and Epilog that must be executed. If we skip the Epilog the native stack that us being by VM itself gets unstable-
Again since we have compiled the entire method we should not do a separate compilation for the exception handler.
Now that we wnat to execute the Epilog and also want to use the already compiled handler code.
This part does not seems to be hard- but we dont know in advance which method will catch the exception.
To solve the problem we can add an exception blog at the end of each method (a few bytes overhead for each method) and return a value from the native code to signal exception. The return value we used so far is always zero. So for exception we can use any non-zero value and also do the cleanup.
When we find exception block we execute that block and continue. The way the compiler generates methods byte code actually do the nice job of managing code flow properly so our compiler already converted those code to native code and we dont need anything extra.