V8 的点火装置究竟有什么作用?

What does V8's ignition really do?

https://v8.dev/docs/ignition 我们可以看到:

Ignition is a fast low-level register-based interpreter written using the backend of TurboFan

https://docs.google.com/document/d/11T2CRex9hXxoJwbYqVQ32yIPMh0uouUZLdyrtmMoL44/edit?ts=56f27d9d#

The aim of the Ignition project is to build an interpreter for V8 which executes a low-level bytecode, thus enabling run-once or non-hot code to be stored more compactly in bytecode form.

The interpreter itself consists of a set of bytecode handler code snippets, each of which handles a specific bytecode and dispatches to the handler for the next bytecode. These bytecode handlers

To compile a function to bytecode, the JavaScript code is parsed to generate its AST (Abstract Syntax Tree). The BytecodeGenerator walks this AST and generates bytecode for each of the AST nodes as appropriate.

Once the graph for a bytecode handler is produced it is passed through a simplified version of Turbofan’s pipeline and assigned to the corresponding entry in the interpreter table.

看来Ignition的工作是将BytecodeGenerator生成的字节码转换为字节码处理程序并通过Turbofan.

执行

但是在这里:

这里:

可以看到是ignition产生了字节码

此外,在此视频中 https://youtu.be/p-iiEDtpy6I?t=722 Ignition 据说是一个基线编译器。

那是什么? 基线编译器?字节码解释器? AST 到字节码转换器?

这张图片似乎最合适:

ignition 只是一个解释器,之前的一切都是 无名字节码 generator/optimizer 东西。

正如我在评论中提到的,遗憾的是有些文档已经过时,包括上面第一张图片的文档。 Full-codegen 和 Crankshaft 是 no longer used at all,它是纯粹的解析和 Ignition + TurboFan。 (你已经从过时的文档中删除了图片,遗憾的是,一些V8 文档)

Ignition 是一个高速字节码解释器。

V8 的解析器生成 Ignition 字节码。该字节码由 Ignition 执行(解释)。只有 运行 一次(启动代码等)或不是 运行 的代码通常停留在字节码级别并继续由 Ignition 执行。

"Hot" 代码进入第二阶段,TurboFan 开始运行:TurboFan 的输入是 Ignition 解释的相同字节码(而不是源代码,就像 Crankshaft 那样),然后它会主动编译为运行 直接(而不是被解释)的高度优化的机器代码。

This article 探讨了放弃 Full-codegen 和 Crankshaft 的动机(前者节省内存,后者难以实现,尤其是优化语言功能)。 TurboFan 的设计还帮助 V8 作者最大限度地减少了他们必须编写的特定于平台的代码量(通过具有中间表示,除其他外,他们还可以使用它来编写 Ignition 的字节码处理程序)。

这里是 V8 开发人员。

On https://v8.dev/docs/ignition we can see that:

Ignition is a fast low-level register-based interpreter written using the backend of TurboFan

是的,总结起来。要添加更多细节:

  • 名称“Ignition”指的是字节码生成器和字节码解释器。通常,整个事情也被视为一个大黑盒子,随便称为“解释器”,这有时会导致一些术语混淆。
  • 字节码生成器采用解析器为给定 JavaScript 函数生成的 AST,并从中生成字节码。
  • 字节码解释器获取字节码生成器生成的字节码,并通过将其发送到一组字节码处理程序来解释它来执行它。
  • 构成字节码解释器的字节码处理程序是使用 Turbofan 管道的一部分生成的。这发生在 V8 编译时,而不是 运行 时。换句话说,您需要 Turbofan 来 构建 (部分)Ignition,而不是 运行 Ignition。
  • 解析器(及其生成的 AST/Abstract 语法树不是 Ignition 的一部分。

Once the graph for a bytecode handler is produced it is passed through a simplified version of Turbofan’s pipeline and assigned to the corresponding entry in the interpreter table.

看来Ignition的工作是将BytecodeGenerator生成的字节码转换为字节码处理程序并通过Turbofan执行

设计文档的这一部分讨论了使用 Turbofan 的部分“提前”(即编译 V8 时)生成字节码处理程序。在 运行 时,字节码未 转换 为处理程序,它是由现有的固定处理程序集“处理”(=运行、执行、解释), Turbofan 不参与。

What is more, in this video https://youtu.be/p-iiEDtpy6I?t=722 Ignition is said to be a baseline compiler.

在那一刻,谈话指的是所有现代 JavaScript 引擎都有一个“基线编译器”的一般想法(在非常一般的概念意义上——我同意幻灯片可以使更清晰)。请注意,该幻灯片并未提及任何有关 Ignition 的内容。 下一张 幻灯片说 Ignition 在 V8 中扮演了这个角色。因此更准确的说法是“Ignition 取代了 基线编译器”或“Ignition 是基线 执行引擎”。或者您可以稍微重新定义您的术语并说“Ignition 是一个生成字节码然后解释它的编译器”。

ignition is just an interpreter and everything before is no-name bytecode generator/optimizer thing

该幻灯片将“解释器”框显示为“Ignition 字节码管道”的一部分。字节码 Generator/Optimizer 也是 Ignition 的一部分。

请指正我理解转换过程的错误:

  • JS 代码解析为 AST
  • AST 发送到 Ignition 以转换为字节码
  • 生成机器码
  • 如果字节码是最优的,发送给CPU处理
  • 如果字节码需要优化,则发送给Turbofan进行优化
  • Turbofan如果接收到字节码,会进一步优化,发送到电脑处理。