0

I compiled v8 with the disassembler option:

tools/dev/v8gen.py x64.debug -- v8_enable_disassembler=true  v8_enable_object_print=true
ninja -C out.gn/x64.debug

However, when I attempt to print out the disassembly, d8 does not output anything (no error messages either):

./d8 --print-code test.js

test.js contains the following:

function add(a, b){
  return a + b;
}
SivaDotRender
  • 1,581
  • 4
  • 21
  • 37
  • Possible duplicate of [How can I see the machine code generated by v8?](https://stackoverflow.com/questions/277423/how-can-i-see-the-machine-code-generated-by-v8) – Avery Jan 22 '18 at 23:02

1 Answers1

2

V8 compiles functions lazily (i.e. when they are first called), so when your file only contains function add(...) {...}, that is one reason why you're not seeing any output. Try adding a call, e.g. add(1, 1).

Also, recent versions of V8 use a bytecode interpreter instead of generating machine code right away. You can print the bytecode using --print-bytecode.

Machine code is only generated by the optimizing compiler once a function is "hot" (for a small function like add in your test, that means calling it a few thousand times); --print-opt-code prints the optimized machine code.

(Side note: In Debug builds of V8, disassembler support is always enabled, so you don't need any custom flags.)

jmrk
  • 34,271
  • 7
  • 59
  • 74