1. What is a V8?
  2. V8 overall execution process
  3. V8 process detail analysis

What is a V8?

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It works in Chrome, Node.js, etc. It implements ECMAScript and WebAssembly and runs on Windows 7 or later, macOS 10.12+, and Linux systems using X64, IA-32, ARM, or MIPS processors. V8 can run on its own or be embedded in any C++ application.

V8 overall execution process

Noun explanation:

  1. source code: Javascript
  2. Parser is processed as an AST Parser.
  3. AST Abstract syntax tree
  4. The Ignition interpreter converts the AST to byteCode
  5. The Sparkplug non-optimized compiler can be understood as precompiling byteCode (very fast)
  6. ByteCode execute can be understood as a cross-platform encoding (not platform machine code)
  7. The Turbofan optimization compiler compiles byteCode and optimizes the code
  8. Machine Code The Code executed by each platform

V8 process detail analysis

Source Code

If you’re developing with TypeScript, it also needs to be compiled into Js before it gets into the browser. V8 only recognizes Js.

Here’s a function for analysis:

Function add(x,y){// <- top level code return x + y; // <- non top level }Copy the code

parser

Parser part, those of you who know compilation know that there are lexical analysis, syntax analysis…

AST

An AST is a tree-like representation of the abstract syntactic structure of source code.

Ignition ==> byteCode

The Parser then generates BytecodeGenerator from V8’s internal class BytecodeGenerator.

Turbofan

Turbofan generates optimized machine code based on bytecode and hotspot function feedback types. Much of Turbofan’s optimization process is basically the same as the back end optimization of compilation principle, using sea-of-Node.

Sparkplug

Sparkplug is designed to compile quickly. Very fast. It’s so fast that it can compile almost at any time, so you can layer Sparkplug code more aggressively than TurboFan code.

  1. What Sparkplug compiles is byteCode
  2. Sparkplug compilation is not optimized
  3. Sparkplug just needs to mirror the parser Ignition behavior and doesn’t need some kind of state mapping
  4. .

The last

Two things:

  1. Visual architecture design, source code learning, daily development. I’m going to share it step by step. Please check out my follow-up if it’s helpful. If you need me, you can add my contact information (on my homepage, you can join the group chat).
  2. Javascript related content further contact me home wechat, well that’s it. bye~

Oh, yeah, one more thing happy Goddess Day to all the goddesses. BYE~