AFAIK, there are roughly two kinds of code objects in V8. One is javascript bytecode interpreted by Ignition, and the other is machine code which is compiled & optimized by Turbofan. According to the execution/frames.h, V8 constructs a different stackframe for each kind of code object. It means V8 should know the kind of the callee
before it executes it.
When unoptimized code(JS Bytecode) calls the optimized one, I guess that Ignition could handle the case properly to build a new stackframe for an optimized one.
However, when the optimized code calls the unoptimized one, I’m curious about how V8 determines whether callee
is unoptimized or not. In general, machine code is literally executed by the processor directly. Thus nothing can help V8 determine the kind of callee
before it execute the call
instruction.
Also, in my understanding, V8 should trace the execution to detect whether some code dependency is compromised and to mark or deoptimize the invalidated code objects. I think it also requires v8 to monitor the execution of machine code.
So my question is:
-
Does V8 monitor the execution of (optimized) machine code? If so, how does it happen?
-
If
1
is false, then how does V8 check the invalidation of code dependency or detect whether thecallee
is compiled or not?