OSR optimization will be triggered when a loop is executed enough times. Marking and triggering an optimization task will occur in JumpLoop handler. Two questions about OSR in V8:
Unlike ordinary function optimization, triggering an OSR optimization job will not in the next turn after marking. It may take a long period of time between marking and triggering a opt-job, why? What's the condition?
How to continue to execute the interrupted function in optimized code?
Re 1. For several reasons, non-OSR optimization is generally preferable (in short, the generated code will be better). Doing OSR is only worth it when the function in question spends a really long time in a loop. So the purpose of waiting a bit is to see if the loop will finish soon enough.
Re 2. That's the "magic" of on-stack replacement: the contents of the stack frame are converted to the format that the optimized code for that function needs, and then a special entry point in the optimized code is taken that's able to resume execution from exactly the point where it was interrupted. (That's one of the reasons why non-OSR code is preferable: it doesn't need this special entry point.)