Search code examples
javascriptassemblyv8jitjavascript-engine

Are there ways to see the assembly code for the code generated by any of the JavaScript jits, especially V8's?


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.)


Solution

  • 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".