如何在 V8 引擎中打印已编译的指令? [英] How to print the compiled instructions in V8 engine?

查看:49
本文介绍了如何在 V8 引擎中打印已编译的指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编译了 v8_hello_world 示例,它可以在控制台中打印hello world".我知道 V8 用 JIT 编译 JavaScript,但我想打印它编译的指令等详细消息.而且我也想知道这些指令的类型,那我该怎么办?

I have compiled the v8_hello_world sample and it could print "hello world" in the console. I know that V8 compiles the JavaScript with JIT, but I want to print the detailed message such as instructions it compiled. And I also want to know the types of these instructions, so what should I do?

非常感谢~

推荐答案

根据您感兴趣的生成代码的类型,您必须将相应的标志传递给 V8:

Depending on the type(s) of generated code you're interested in, you'll have to pass the corresponding flag(s) to V8:

>

  • --print-code 打印未优化的机器代码(由未优化的编译器full codegen"创建)
  • --print-bytecode 打印字节码(由Ignition"解释器创建)
  • --print-opt-code 打印优化的机器代码(由Crankshaft"或TurboFan"优化编译器创建)
    • --print-code prints unoptimized machine code (created by "full codegen", the unoptimizing compiler)
    • --print-bytecode prints bytecode (created by the "Ignition" interpreter)
    • --print-opt-code prints optimized machine code (created by either the "Crankshaft" or "TurboFan" optimizing compilers)

    这些标志(以及许多其他标志)由 --help 记录.由于当前正在对执行管道进行重大更改,因此根据您使用的 V8 版本,您可能会看到不同编译器编译的相同函数.

    These flags (and many others) are documented by --help. Since major changes to the execution pipeline are currently ongoing, depending on which version of V8 you're using, you might see the same function compiled by different compilers.

    如果您使用开发人员 shell d8,您可以直接在命令行上传递这些标志.在您自己的嵌入应用程序中,您可以使用 v8::V8::SetFlagsFromCommandLineargcargv 传递给 V8.在 d8.cc 中,您可以看到如何自己处理一些标志并将其他标志传递给 V8 的示例.

    If you use the developer shell d8, you can pass these flags directly on the command-line. In your own embedding application, you can use v8::V8::SetFlagsFromCommandLine to pass argc and argv to V8. In d8.cc you can see an example for how to handle some flags yourself and pass on others to V8.

    一年后更新:完整代码生成"和曲轴"不见了.--print-bytecode 仍然打印字节码,--print-opt-code 打印优化的机器代码(现在总是来自Turbofan").--print-code 可做的事情比以前少了,但对于生成的正则表达式代码和 wasm 代码仍然有用.

    Update one year later: "full codegen" and "Crankshaft" are gone. --print-bytecode still prints bytecode, --print-opt-code prints optimized machine code (now always from "Turbofan"). --print-code has less to do than before, but is still useful for generated regexp code and wasm code.

    这篇关于如何在 V8 引擎中打印已编译的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆