/ 7 分钟阅读
本文最后更新于 1994 天前,文中所述的信息可能已发生改变或更新。
未完成,长期更新
常指 Runtime system(区别于程序生命周期的 Runtime),也叫作 runtime environment。
Most programming languages have some form of runtime system that provides an environment in which programs run. This environment may address a number of issues including the management of application memory, how the program accesses variables, mechanisms for passing parameters between procedures, interfacing with the operating system, and otherwise. The compiler makes assumptions depending on the specific runtime system to generate correct code. Typically the runtime system will have some responsibility for setting up and managing the stack and heap, and may include features such as garbage collection, threads or other dynamic features built into the language.
JavaScript 引擎,用于 Chrome,但与浏览器引擎区别的是 JavaScript 引擎只专注于 JavaScript,他不理解任何 DOM 相关概念。
2017 年 5 月 15 日,V8 团队发布 Launching Ignition and TurboFan,宣布新 pipeline 更换为 Ignition(interpreter) 和 TurboFan(compiler)
JavaScript 引擎、虚拟机、运行时环境是一回事儿吗?
浏览器引擎之一,包括渲染引擎,统合 JavaScript 引擎。Safari 使用 WebKit,另外还有:
下图为 WebKit 主要流程:

Compiler 是将一种语言(通常是高等语言)处理为另一种语言(assembly language、object code、machine code)的计算机程序。
例如,babel 就是一个 js Compiler,将 ES6 以上编译到 ES5.
它需要做的可能包含:
进行某个操作时,需要先准备好某些资源,这一步骤占用的时间或资源就是 overhead。
举个例子,开车去某个地方,去停车场把车开出来就是 overhead,如果你去小区不远处的小卖部,就完全没必要开车,因为这个 overhead 对这件事来说成本太高了。
Ahead-of-time compilation,提前将高级语言(如 C)或 IR(如 Java bytecode)根据架构编译为可运行代码。(不需要 Interpreter)
Just-in-time compilation(也称为 dynamic translation 或 run-time compilations),是 ahead-of-time compilation (AOT) 和 interpretation 的组合。(可以看出 JIT 和 Interpreter 的奇妙关系)
在运行时(而不是执行之前)编译,这个过程包括把源代码或 bytecode 转换成机器码并立即运行。JIT 会造成 overhead,但 compile 和 recompile 带来的速度提升可以弥补 overhead。
interpreter 可以直接执行脚本语言或编程语言而不用事先编译。
三种 interpreter:
相对于 compile 的原意是编撰,compiler 就是编撰者;
interpret 是口译,interpreter 就是口译者;
在计算机领域 compiler 是编译器,interpreter 是解释器,这两者的区别用原意解释到更容易理解:
一般来说:
一种语言是编译型或解释型的定义由官方实现决定,事实上一种语言是编译型或是解释型不是绝对的。
compiler 或 virtual machine 使用的一种数据结构或代码。
V8 的 IR 是 Sea-of-Nodes。
分为系统虚拟机和进程虚拟机,系统虚拟机模拟整个计算机,此处主要讨论进程虚拟机。
进程虚拟机也叫 application virtual machine 或 Managed Runtime Environment (MRE)(重点,运行时环境)。
进程虚拟机建立在真实系统上,为高级语言提供运行环境,例如 JVM。
A process VM provides a high-level abstraction – that of a high-level programming language (compared to the low-level ISA abstraction of the system VM). Process VMs are implemented using an interpreter; performance comparable to compiled programming languages can be achieved by the use of just-in-time compilation.
汇编语言是 CPU 的母语,的人类可读版本。assembler 可以将汇编语言编译为 Machine Code。
字节码,虽然和机器码一样都是处理成一堆 0 和 1,但是 CPU 根本看不懂,不过,虚拟机倒是懂。
例如 Java class 文件、JavaScript 的 bytecode
一堆 0 和 1,计算机真正的母语,可以直接运行每一条指令,例如 store、load、jump、ALU 操作。
/ 7 分钟阅读
本文最后更新于 1994 天前,文中所述的信息可能已发生改变或更新。
未完成,长期更新
常指 Runtime system(区别于程序生命周期的 Runtime),也叫作 runtime environment。
Most programming languages have some form of runtime system that provides an environment in which programs run. This environment may address a number of issues including the management of application memory, how the program accesses variables, mechanisms for passing parameters between procedures, interfacing with the operating system, and otherwise. The compiler makes assumptions depending on the specific runtime system to generate correct code. Typically the runtime system will have some responsibility for setting up and managing the stack and heap, and may include features such as garbage collection, threads or other dynamic features built into the language.
JavaScript 引擎,用于 Chrome,但与浏览器引擎区别的是 JavaScript 引擎只专注于 JavaScript,他不理解任何 DOM 相关概念。
2017 年 5 月 15 日,V8 团队发布 Launching Ignition and TurboFan,宣布新 pipeline 更换为 Ignition(interpreter) 和 TurboFan(compiler)
JavaScript 引擎、虚拟机、运行时环境是一回事儿吗?
浏览器引擎之一,包括渲染引擎,统合 JavaScript 引擎。Safari 使用 WebKit,另外还有:
下图为 WebKit 主要流程:

Compiler 是将一种语言(通常是高等语言)处理为另一种语言(assembly language、object code、machine code)的计算机程序。
例如,babel 就是一个 js Compiler,将 ES6 以上编译到 ES5.
它需要做的可能包含:
进行某个操作时,需要先准备好某些资源,这一步骤占用的时间或资源就是 overhead。
举个例子,开车去某个地方,去停车场把车开出来就是 overhead,如果你去小区不远处的小卖部,就完全没必要开车,因为这个 overhead 对这件事来说成本太高了。
Ahead-of-time compilation,提前将高级语言(如 C)或 IR(如 Java bytecode)根据架构编译为可运行代码。(不需要 Interpreter)
Just-in-time compilation(也称为 dynamic translation 或 run-time compilations),是 ahead-of-time compilation (AOT) 和 interpretation 的组合。(可以看出 JIT 和 Interpreter 的奇妙关系)
在运行时(而不是执行之前)编译,这个过程包括把源代码或 bytecode 转换成机器码并立即运行。JIT 会造成 overhead,但 compile 和 recompile 带来的速度提升可以弥补 overhead。
interpreter 可以直接执行脚本语言或编程语言而不用事先编译。
三种 interpreter:
相对于 compile 的原意是编撰,compiler 就是编撰者;
interpret 是口译,interpreter 就是口译者;
在计算机领域 compiler 是编译器,interpreter 是解释器,这两者的区别用原意解释到更容易理解:
一般来说:
一种语言是编译型或解释型的定义由官方实现决定,事实上一种语言是编译型或是解释型不是绝对的。
compiler 或 virtual machine 使用的一种数据结构或代码。
V8 的 IR 是 Sea-of-Nodes。
分为系统虚拟机和进程虚拟机,系统虚拟机模拟整个计算机,此处主要讨论进程虚拟机。
进程虚拟机也叫 application virtual machine 或 Managed Runtime Environment (MRE)(重点,运行时环境)。
进程虚拟机建立在真实系统上,为高级语言提供运行环境,例如 JVM。
A process VM provides a high-level abstraction – that of a high-level programming language (compared to the low-level ISA abstraction of the system VM). Process VMs are implemented using an interpreter; performance comparable to compiled programming languages can be achieved by the use of just-in-time compilation.
汇编语言是 CPU 的母语,的人类可读版本。assembler 可以将汇编语言编译为 Machine Code。
字节码,虽然和机器码一样都是处理成一堆 0 和 1,但是 CPU 根本看不懂,不过,虚拟机倒是懂。
例如 Java class 文件、JavaScript 的 bytecode
一堆 0 和 1,计算机真正的母语,可以直接运行每一条指令,例如 store、load、jump、ALU 操作。