1

I'm using the v8 library to run JavaScript code in C++-project. And I want to log every bytecode instruction at run time. Is it possible or not? Or can I only log the assembly instructions? And if I can, then how? The trace log is required, not the result of disassembling bytecode.

2 Answers2

1

If you are using the d8 shell you can pass the flag --print-bytecode.

If you are embedding v8, you could set i::FLAG_print_bytecode = true before creating the isolate. You could check out test-api.cc for more examples of using the API.

Superfly
  • 571
  • 3
  • 13
  • Thank you. But I do not need the result of decompiling bytecode, namely the log of its execution. List of all executed bytecode instructions. I do not know if it's possible . – Alexey Novikov Apr 18 '18 at 12:56
  • We want to evaluate the complexity of JavaScript code by the number and types of bytecode instructions executed. – Alexey Novikov Apr 18 '18 at 13:15
1

If you build with the V8_TRACE_IGNITION symbol defined (by putting v8_enable_trace_ignition = true into your args.gn), you can then use the flag --trace-ignition.

Note that V8 optimizes hot functions after a while, at which point they'll no longer run in the interpreter and hence will no longer be traced. For your purposes, you can turn that off with --noopt; of course doing so will significantly degrade performance of computationally intensive programs (10x slower wouldn't be unexpected; the exact number depends a lot on what the code is doing).

Also, please be aware that counting bytecode instructions will be a very coarse approximation of program complexity. For example, a single bytecode could call a builtin that does an arbitrarily expensive operation.

jmrk
  • 34,271
  • 7
  • 59
  • 74