首页 > 编程语言 >[VM] The JavaScript Virtual Machine

[VM] The JavaScript Virtual Machine

时间:2023-10-24 15:13:21浏览次数:30  
标签:instruction JavaScript VM VMs Machine PC registers memory CPU

Table of Content

  • Introudction to VMs
  • CPU - Understanding the Pysical Machine
  • VMs - Arrays, Objects, functions, prototype chains
  • DepotExplorer: collecting data from the VM
  • Deopt: Calling Coventions & Inlining
  • Megamohpism & Inline Cache: Object properties
  • Holey Arrays: Prototype chains resolutions
  • == vs ===: `valueOf()`

 

Introudce to VMs

VM is the thing in the middle of picture, which translate the code we write (left) into the numbers (right) which CPU can understand.

The thing in the middle is called assembly language, which is basically numbers ocverted to a humum readable text.

 

There are many VMs, the most used is call V8 for Javascript.

Pretty much everything store in CPU memory are just numbers. And it is VMs job to translate those numbers into what we use in javascript.

 

How CPU works

  • Registers: wroks like a local variable
  • ALU (Arithmetic logic unit): doing math operation
  • Program Counter (ofter called: PC): keep track location of memory

How They Work Together:

In a nutshell, as the CPU operates, it constantly fetches and processes instructions. The PC helps it keep track of where it is in the program, the registers provide a place to quickly access and store data, and the ALU does the actual computation. The harmonious interaction of these components allows the computer to function efficiently.

 


More detail

CPU (Central Processing Unit): Often referred to as the "brain" of the computer, it performs most of the processing and is responsible for executing instructions.

1. Registers:

  • Small, fast storage locations directly within the CPU.
  • Used to temporarily hold data that the CPU is currently processing.
  • Types:
    • Data registers: Store data that is being processed.
    • Address registers: Store memory addresses where data or instructions are located.
    • Special-purpose registers: Have specific functions (e.g., status register, which might indicate if the last operation resulted in a zero value).

2. ALU (Arithmetic Logic Unit):

  • Performs arithmetic and logic operations.
  • Takes inputs from registers, processes them based on the instruction (like addition, subtraction, etc.), and then sends the result back to a register or memory.

3. Program Counter (often just called the "PC"):

  • Special-purpose register that holds the address of the next instruction to be executed.
  • Each time an instruction is executed, the PC is updated to point to the next instruction.
  • Some instructions, like jumps or branches, directly modify the PC.

How They Work Together:

  1. Fetch: The CPU fetches the instruction from the memory address located in the PC.
  2. Increment: After fetching the instruction, the PC is incremented to point to the next instruction.
  3. Decode: The fetched instruction is decoded to determine which operation should be performed by the ALU.
  4. Execute: The operation is performed. Data might be fetched from registers for the ALU to process.
  5. Store: After execution, the result is stored in a register or in memory.

标签:instruction,JavaScript,VM,VMs,Machine,PC,registers,memory,CPU
From: https://www.cnblogs.com/Answer1215/p/17784834.html

相关文章

  • VMware最小化安装Centos7.6-无桌面
    目录安装包工具新建虚拟机安装centos7.6终端登陆系统设置ip地址关闭防火墙关闭SELINUXSELINUX=enforcing硬盘挂载安装包工具VMware®Workstation15Pro15.5.2build-15785246CentOS-7.6-x86_64-DVD-1810.iso链接:https://pan.baidu.com/s/1u2vMvwtpHxbNoRpvLERKmQ提取码:b8jt......
  • JavaScript在发送AJAX请求时,URL的域名地址是使用绝对地址还是相对地址?
    在使用JavaScript发送AJAX请求时,URL的域名地址通常是使用相对地址。相对地址指的是相对于当前页面的URL来确定请求的目标地址。当请求发送到服务器时,浏览器会自动将相对地址转换为完整的绝对URL。这样做的好处是能够更灵活地处理不同环境下的URL路径,同时减少了在JavaScript代码中......
  • MVC和MVVM
    MVCMVC全名是ModelViewController,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范。Model(模型)是应用程序中用于处理应用程序数据逻辑的部分。View(视图)应用程序中处理数据显示的部分。Controller(控制器)是应用程序中处理用户交互的部分。缺点:前后端职责纠缠不清......
  • 循序渐进介绍基于CommunityToolkit.Mvvm 和HandyControl的WPF应用端开发(1)
    在我们的SqlSugar的开发框架中,整合了Winform端、Vue3+ElementPlus的前端、以及基于UniApp+Vue+ThorUI的移动前端几个前端处理,基本上覆盖了我们日常的应用模式了,本篇随笔进一步介绍前端应用的领域,研究集成WPF的应用端,循序渐进介绍基于CommunityToolkit.Mvvm和HandyControl的WPF应用......
  • JavaScript 将对象转换为数组
    JavaScript将对象转换为数组在JavaScript中,你可以使用不同的方法将对象转换为数组,具体取决于对象的结构和你希望在数组中得到什么样的数据。以下是一些常见的方法:Object.keys()方法:这种方法将对象的键转换为数组。constobj={a:1,b:2,c:3};constarr=Object......
  • How to fix EventSource onmessage not working in JavaScript All in One
    HowtofixEventSourceonmessagenotworkinginJavaScriptAllinOneSSE:Server-SentEvents/服务端推送error❌window.addEventListener(`load`,(e)=>{console.log(`pageloaded✅`);if(!!window.EventSource){constimg=document.querySelecto......
  • JavaScript基础
    学习目标:掌握编程的基本思维掌握编程的基本语法typora-copy-images-to:mediaJavaScript基础JavaScript介绍JavaScript是什么JavaScript是一种运行在客户端的脚本语言Netscape在最初将其脚本语言命名为LiveScript,后来Netscape在与Sun合作之后将其改名为JavaScript。JavaScript最......
  • JVM概要
    JVM概要学前思考:JVM本质上是什么,是C/C++写的一个程序吗JVM和操作系统有什么区别和联系JVM为java程序提供哪些服务概览JVM由C/C++等可以和OS交互的语言编写,目的是在java程序运行时将字节码通过解释器或即时编译器转成对应平台的机器码,达到跨平台的作用。由此可以见JVM并不......
  • javascript: Sorting Algorithms
      /***fileSort.js*ide:vscodeJavaScriptSortingAlgorithms*插件:IntelliSense,JSDoc,CodeLens,DebuggerforChrome,静态代码检查:ESLint,JSHint,FlowLangugaeSupport,StandardJS-JavaScriptStandardStyle,koroFileHeader(文件头注释),测试插件:Mochasideba......
  • javascript: Sorting Algorithms
     /***fileSort.js*ide:vscodeJavaScriptSortingAlgorithms*插件:IntelliSense,JSDoc,CodeLens,DebuggerforChrome,静态代码检查:ESLint,JSHint,FlowLangugaeSupport,StandardJS-JavaScriptStandardStyle,koroFileHeader(文件头注释),测试插件:Mochasidebar,M......