最近重新看Google Chromium讲Ignition的一个ppt,最后提及JSC是Direct-threaded dispatch,而v8属于Indirect-threaded dispatch。
Contemporary JavaScript Engines
JavaScriptCore (Apple)
● Direct threaded (== bigger code and data, but fast).
● Register Machine.
● Custom assembler generating bytecode handlers in dispatch loop.
SpiderMonkey (Mozilla)
● Indirect threaded.
● Stack Machine.
● Interpreter implemented in C++ as either switch statement or goto table (depending on compiler).
Chakra (Microsoft)
● Register based bytecode and C++ based interpreter.
● Optimizing compiler can run concurrently with bytecode generation.
所谓解释器,根据解释执行的输入,有两种:AST与Bytecode。
但既然谈到虚拟机解释器,自然是有Bytecode的。
那么DTC和ITC又是指什么的?
根据一篇很老的论文,DTC指的是bytecode指令直接对应目标handler的跳转地址。而ITC则首先将这些handler的跳转地址存放到一个table中,间接跳转。(相当于CPU指令集间接寻址的概念,或者二级指针的概念),ITC的C语言实现依赖于一项被称为“computed goto”的GCC扩展特性。<