代码之家  ›  专栏  ›  技术社区  ›  MaBed

JIT编译器是否包含许多将字节码/源代码编译为机器代码的指令集?

  •  1
  • MaBed  · 技术社区  · 3 年前

    据我所知,JIT编译器可以获取字节码/源代码的一部分,并将它们转换为运行它的CPU的机器代码(指令)。

    这是否意味着JIT编译器必须知道多个指令集才能为不同的CPU型号生成机器代码?

    我试着搜索这是如何工作的,例如V8,但我没有发现任何有用的东西。

    1 回复  |  直到 3 年前
        1
  •  0
  •   Yassin Hajaj    3 年前

    你的假设是正确的。

    你可以在中看到 the Github mirror for V8 它需要定义它正在运行的体系结构。

    // Copyright 2022 the V8 project authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    #ifndef V8_CODEGEN_REGISTER_ARCH_H_
    #define V8_CODEGEN_REGISTER_ARCH_H_
    
    #include "src/codegen/register-base.h"
    
    #if V8_TARGET_ARCH_IA32
    #include "src/codegen/ia32/register-ia32.h"
    #elif V8_TARGET_ARCH_X64
    #include "src/codegen/x64/register-x64.h"
    #elif V8_TARGET_ARCH_ARM64
    #include "src/codegen/arm64/register-arm64.h"
    #elif V8_TARGET_ARCH_ARM
    #include "src/codegen/arm/register-arm.h"
    #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
    #include "src/codegen/ppc/register-ppc.h"
    #elif V8_TARGET_ARCH_MIPS64
    #include "src/codegen/mips64/register-mips64.h"
    #elif V8_TARGET_ARCH_LOONG64
    #include "src/codegen/loong64/register-loong64.h"
    #elif V8_TARGET_ARCH_S390
    #include "src/codegen/s390/register-s390.h"
    #elif V8_TARGET_ARCH_RISCV32 || V8_TARGET_ARCH_RISCV64
    #include "src/codegen/riscv/register-riscv.h"
    #else
    #error Unknown architecture.
    #endif
    
    #endif  // V8_CODEGEN_REGISTER_ARCH_H_