0

I've tried the suggest in the url: How can I see the machine code generated by v8?

Here is what I did:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools

sudo apt-get install libv8-dev
sudo apt-get install g++
sudo apt-get install libgtk2.0-dev
sudo apt-get install g++-multilib

export PATH="$PATH":`pwd`/depot_tools

fetch v8

gclient sync

make ia32.release objectprint=on disassembler=on

v8/out/ia32.release/d8 --print-all-code hello.js > output.txt

(The script is just:print("hello"))

Below are the output:

kind = STUB
major_key = JSEntryStub
compiler = unknown
Instructions (size = 131)
0x35d06040     0  55             push ebp
0x35d06041     1  89e5           mov ebp,esp
0x35d06043     3  6a02           push 0x2
......
0x35d060c2    82  c3             ret
Handler Table (size = 12)

RelocInfo (size = 23)
0x35d06047  external reference (Isolate::context_address)  (0xa9533dc)
0x35d06050  external reference (Isolate::c_entry_fp_address)  (0xa953410)
......
kind = STUB
major_key = JSEntryStub
compiler = unknown
Instructions (size = 131)
0x35d06120     0  55             push ebb
......

Indeed,I have a batch of code,but it doesn't vary from the input script. By the way,the output is certainly too much(about 13M text) for a simple script.

Thanks.

Mao Mao
  • 1
  • 1
  • I suspect you're trying to do something that does not make sense. See also: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Tatsuyuki Ishi Jun 24 '17 at 13:49
  • Much of the code you gonna see produced by the jit is likely from the V8 runtime libraries, which (1) is a lot, and (2) the same for different scripts. Try searching the output for some unique identifiers from your code. – Andreas Rossberg Jun 24 '17 at 16:15

1 Answers1

2

With current V8 versions (5.9 or later), you probably want the --print-opt-code flag: initially, V8 generates byte code for its interpreter (which you can inspect with --print-bytecode); once a function is "hot" (i.e. a lot of time is spent executing it), it is sent to the optimizing compiler to generate machine code for it.

Note that you cannot use V8 as a general purpose JavaScript-to-machine-code compiler. The flags mentioned above are intended for debugging; there is no (supported or easy) way to produce working binaries from their output.

jmrk
  • 34,271
  • 7
  • 59
  • 74