是否有办法查看由任何JavaScript jit(尤其是V8)生成的代码的汇编代码? [英] Are there ways to see the assembly code for the code generated by any of the JavaScript jits, especially V8's?

查看:118
本文介绍了是否有办法查看由任何JavaScript jit(尤其是V8)生成的代码的汇编代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web浏览器和nodeJS的主要JavaScript引擎使用just-in-time编译器已有多年了.

我只是在 Compiler Explorer 上观看了视频,其中显示了许多编译器为各种CPU输出的汇编代码./p>

这使我想起了我对JS引擎的jit生成的代码感到好奇.

这些引擎中有没有一个能让我们看到底层生成的代码的方法?

(如果这在SO上不合适,请随时将其迁移到正确的SE网站.)

解决方案

对于V8,有一个标志--print-opt-code,该标志为每个已优化的函数打印生成的优化汇编代码.请注意,仅当函数处于热"状态时才对其进行优化,而不是立即进行优化,因此对于简短的"hello,world"样式程序,该标志将不会打印任何内容.您可以通过多次调用使函数变热".

在较早的版本中,未优化的代码有一个--print-code标志,但是由于基线(非优化)编译器已被解释器替换,因此不再有未优化的代码.您可以使用--print-bytecode打印生成的字节码.

如果您使用的是Chrome,则可以通过将标志包装在--js-flags中来指定要传递给V8的标志,例如--js-flags="--print-opt-code".

The major JavaScript engines of web browsers and nodeJS have had just-in-time compilers for years.

I was just watching a video on Compiler Explorer showing the assembly code output by many compilers for various CPUs.

This reminded me that I've been curious about the code generated by the JS engines' jits.

Do any of those engines have ways for us to see that low-level generated code?

(If this is out of place on SO please feel free to migrate it to the correct SE site.)

解决方案

For V8, there is a flag --print-opt-code, which prints generated optimized assembly code for each function that gets optimized. Note that functions only get optimized when they're "hot", not right away, so for a short "hello, world" style program the flag won't print anything. You can make functions "hot" by calling them a lot.

In older versions, there was a --print-code flag for unoptimized code, but since the baseline (non-optimizing) compiler has been replaced by an interpreter, there is no unoptimized code any more. You can print the generated bytecode with --print-bytecode.

If you're using Chrome, you can specify flags to be passed to V8 by wrapping them in --js-flags, e.g. --js-flags="--print-opt-code".

这篇关于是否有办法查看由任何JavaScript jit(尤其是V8)生成的代码的汇编代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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