Daniel Stephens
Daniel Stephens

Reputation: 3219

How to convert Javascript code to human-readable opcodes or asm?

As far as I know, Javascript code can either result in JS bytecode or asm instructions (if the internal JIT-compiler was able to convert the code directly to machine instructions).

Is there any way to convert Javascript code to human-readable JS byte code (or asm instructions) - depending on how the V8 engine converts it?

Upvotes: 0

Views: 1177

Answers (2)

jmrk
jmrk

Reputation: 40521

You can run d8 or node with --print-bytecode --print-opt-code to print both bytecode and optimized assembly code to stdout when it is generated. You can use --print-bytecode-filter=foo and --print-opt-code-filter=foo if you're only interested in function foo. You will need a debug build, or a release build with v8_enable_disassembler = true in its args.gn (regular release builds don't include the disassembler code in order to save binary size). Optimized code will be generated when a function is "hot", i.e. has spent some time running.

Upvotes: 5

anegru
anegru

Reputation: 1123

You can use bytenode from npm to create an executable for your node app. If you want to read the executable you might use tools like objdump, strace, radare2. You can also open the executable in vim and use the option :%!xxd to get a more human friendly view.

Upvotes: 0

Related Questions