V8 引擎是否使用 C++ 替换了之前在 JavaScript 中编写的部分代码库?
Has the V8 engine used C++ to replace parts of the codebase previously written in JavaScript?
之前看过V8引擎源码。我可以在其中找到 JavaScript 实现的代码,例如Array.js。
最近又想找数组排序的源码,发现JS部分被去掉了。我能找到的只是数组-sort.tq,它在[v8/third_party/v8/builtins].
是不是我找的方法有问题?还是只是去掉了 JS 部分? JavaScript 开发人员很难了解实施细节。
一些内置函数(例如 Array.prototype.sort
)现在是用 Torque 而不是 C++ 或 JavaScript 编写的。 Torque 是为 V8 构建的语言:
The language was designed to be simple enough to make it easy to directly translate the ECMAScript specification into an implementation in V8, but powerful enough to express the low-level V8 optimization tricks in a robust way, like creating fast-paths based on tests for specific object-shapes.
...
Torque provides language constructs to represent high-level, semantically-rich tidbits of V8 implementation, and the Torque compiler converts these morsels into efficient assembly code using the CodeStubAssembler
.
(更多关于 CodeStubAssembler
here。)
更多内容在 Torque builtins blog post。
所以是的,Array.prototype.sort
和许多其他 Array
方法现在是用 Torque 编写的,它被编译成高效的汇编代码,供 V8 的 JavaScript 解释器使用(Ignition)和 JavaScript 编译器 (TurboFan)。 (是的,V8 两者都有。:-) More here,但简而言之:V8 将 JavaScript 解析为字节码,然后用 Ignition 对其进行解释。热点 [运行 很多的区域] 在需要时通过 TurboFan 编译为本机代码。)
之前看过V8引擎源码。我可以在其中找到 JavaScript 实现的代码,例如Array.js。
最近又想找数组排序的源码,发现JS部分被去掉了。我能找到的只是数组-sort.tq,它在[v8/third_party/v8/builtins].
是不是我找的方法有问题?还是只是去掉了 JS 部分? JavaScript 开发人员很难了解实施细节。
一些内置函数(例如 Array.prototype.sort
)现在是用 Torque 而不是 C++ 或 JavaScript 编写的。 Torque 是为 V8 构建的语言:
The language was designed to be simple enough to make it easy to directly translate the ECMAScript specification into an implementation in V8, but powerful enough to express the low-level V8 optimization tricks in a robust way, like creating fast-paths based on tests for specific object-shapes.
...
Torque provides language constructs to represent high-level, semantically-rich tidbits of V8 implementation, and the Torque compiler converts these morsels into efficient assembly code using the
CodeStubAssembler
.
(更多关于 CodeStubAssembler
here。)
更多内容在 Torque builtins blog post。
所以是的,Array.prototype.sort
和许多其他 Array
方法现在是用 Torque 编写的,它被编译成高效的汇编代码,供 V8 的 JavaScript 解释器使用(Ignition)和 JavaScript 编译器 (TurboFan)。 (是的,V8 两者都有。:-) More here,但简而言之:V8 将 JavaScript 解析为字节码,然后用 Ignition 对其进行解释。热点 [运行 很多的区域] 在需要时通过 TurboFan 编译为本机代码。)