0
点赞
收藏
分享

微信扫一扫

JavaScript - V8

柠檬果然酸 2022-02-10 阅读 66

v8

JIT

执行高级语言一般是采用以下两种方式执行:

  1. 解释执行,将源代码通过编译器编译成中间代码(如汇编代码),之后直接使用解释器解释执行中间代码。
  2. 编译执行,将源代码通过编译器编译成中间代码,再有中间代码编译成机器代码(二进制),直接执行二进制代码。

V8使用的是 混合编译执行和解释执行两种手段,这种技术称为JIT。

AST 抽象语法树

在线查看AST : javascript-ast

对象的存储

  • 数字和字符串的索引分开存储
  • 数字存放到 element 正序排序
  • 字符串存放在 map 按照设值的顺序存放
function testObject(len1, len2){
	while(len1--){this[len1] = 1};
	while(len2--){this['p_'+len2]=1}
};

> new testObject(10,10)

在这里插入图片描述

在这里插入图片描述

函数声明和函数表达式

//函数声明
console.log(foo);      //foo()
function foo(){};


//函数表达式
console.log(foo);      //undefined
var foo = function(){};

垃圾回收

  • 新生代
  • 老生代

d8

官方文档: Using d8

调试命令

> d8 --help
# 查看垃圾回收状态
> d8 --trace-gc test.js
# 查看AST结构
> d8 --print-ast test.js  
# 查看作用域
> d8 --print-scopes test.js
# 查看生成的字节码
> d8 --print-bytecode test.js
# 查看被优化的代码
> d8 --trace-opt test.js
# 查看被反优化的代码
> d8 --trace-deopt test.js

下载地址

mac平台:
https://storage.googleapis.com/chromium-v8/official/canary/v8-mac64-dbg-8.4.109.zip
linux32平台:
https://storage.googleapis.com/chromium-v8/official/canary/v8-linux32-dbg-8.4.109.zip
linux64平台:
https://storage.googleapis.com/chromium-v8/official/canary/v8-linux64-dbg-8.4.109.zip
win32平台:
https://storage.googleapis.com/chromium-v8/official/canary/v8-win32-dbg-8.4.109.zip
win64平台:
https://storage.googleapis.com/chromium-v8/official/canary/v8-win64-dbg-8.4.109.zip
举报

相关推荐

0 条评论