问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/58229838/how-to-convert-javascript-code-to-human-readable-opcodes-or-asm