4
头图

image.png

  1. What is V8?
  2. V8 overall execution process
  3. Detailed analysis of V8 process

What is V8?

V8 is Google's open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and Node.js etc. It implements ECMAScript and WebAssembly and runs on Windows 7 or later, macOS 10.12+, and Linux systems with x64, IA-32, ARM, or MIPS processors. V8 can run standalone or embedded in any C++ application.

V8 overall execution process

image.png

Glossary:

  1. source code: Javascript
  2. Parser Parser (parser) processed as AST
  3. AST Abstract Syntax Tree
  4. Ignition Interpreter converts AST to byteCode
  5. Sparkplug The non-optimizing compiler can be understood as precompiling byteCode (very fast)
  6. byteCode execute bytecode can be understood as a cross-platform encoding (non-platform machine code)
  7. Turbofan optimizing compiler compiles and optimizes the code for byteCode
  8. Machine Code Machine Code Code executed by each platform

V8 process detailed analysis

Source Code

It refers to the Javascript source code. As for the TypeScript you use in your development, it also needs to be compiled into Js before entering the browser. It can be understood that V8 only recognizes JS.
Take a function below for analysis:
function add(x,y){   // <- top level code  解析环节。
    return x + y;    // <- non top level
}

parser

In the parser part, students who have learned about compilation know that there are lexical analysis, syntax analysis...

image.png

image.png

AST

AST refers to a tree-like representation of the abstract syntax structure of source code.
image.png

Ignition ==> byteCode

After Parser, it generates bytecode, which is generated by class BytecodeGenerator inside V8.
image.png

Turbofan

image.png
Turbofan generates optimized machine code based on bytecode and hotspot function feedback types. Turbofan has many optimization processes, which are basically similar to the back-end optimization of the compilation principle, using sea-of-node.

Sparkplug

Sparkplug is designed to compile quickly. very fast. Being so fast that it compiles almost at any time, Sparkplug code can be layered more aggressively than TurboFan code.
image.png
  1. Sparkplug compiles byteCode
  2. Sparkplug compiles without optimization
  3. Sparkplug just needs to mirror the behavior of the parser Ignition without some kind of state mapping
  4. ...

finally

Two things:

  1. Visualization related architecture design, source code learning, daily development. I will share in depth step by step. If it helps you, please follow my follow-up content. Students in need can add my contact information (on my homepage, pull you into the group chat).
  2. javascript related content advanced contact my homepage WeChat, well that's it. bye~

    Oh yes, one more thing to wish all goddesses, Happy Goddess Day. BYE~

wlove
6.9k 声望1.8k 粉丝

wx:wywin2023