V8, Hydrogen, disassembly, and Vyacheslav Egorov's JSConf talk

164 views
Skip to first unread message

John Feminella

unread,
Oct 8, 2014, 11:56:49 AM10/8/14
to v8-u...@googlegroups.com
As an educational exercise, I'd like to inspect disassembled JS generated by JS, and compare both the optimized and unoptimized versions to see what changes and what doesn't.

In Vyacheslav Egorov's JSConf 2012 excellent slides (http://s3.mrale.ph/jsconf2012.pdf) he recommends compiling V8 like so:

=====
make ia32.release objectprint=on \
  disassembler=on

out/ia32.release/d8 --print-opt-code \
  --code-comments \
  --trace-hydrogen \
  test.js
=====

which will enable the disassembler for introspection by the curious.

I'm having a little trouble understanding the current state of affairs, though:

0. Is this the best way of doing things? How do I generate the *unoptimized* JS versus the *optimized* JS for test.js in this example?

1. Are Hydrogen and Crankshaft still relevant? For example, my limited understanding is that TurboFan will be replacing Hydrogen: https://codereview.chromium.org/426233002
Is there somewhere I can read about the relevance and lifecycle of different pieces like Hydrogen and Crankshaft and how they play a role in code generation/optimization?

2. Why does Vyacheslav suggest using --trace-hydrogen? Is that needed to see the disassembly?

Thanks for your help!

best,
~ jf

Jakob Kummerow

unread,
Oct 8, 2014, 12:54:33 PM10/8/14
to v8-u...@googlegroups.com
On Wed, Oct 8, 2014 at 5:56 PM, John Feminella <j...@jxf.me> wrote:
As an educational exercise, I'd like to inspect disassembled JS generated by JS, and compare both the optimized and unoptimized versions to see what changes and what doesn't.

In Vyacheslav Egorov's JSConf 2012 excellent slides (http://s3.mrale.ph/jsconf2012.pdf) he recommends compiling V8 like so:

=====
make ia32.release objectprint=on \
  disassembler=on

out/ia32.release/d8 --print-opt-code \
  --code-comments \
  --trace-hydrogen \
  test.js
=====

which will enable the disassembler for introspection by the curious.

I'm having a little trouble understanding the current state of affairs, though:

0. Is this the best way of doing things? How do I generate the *unoptimized* JS versus the *optimized* JS for test.js in this example?

I guess by "optimized JS" you mean "optimized machine code". Try "out/ia32.release/d8 --help | grep print | grep code". You probably want "--print-opt-code --print-unopt-code".

1. Are Hydrogen and Crankshaft still relevant?

Yes.
 
For example, my limited understanding is that TurboFan will be replacing Hydrogen: https://codereview.chromium.org/426233002
 
Is there somewhere I can read about the relevance and lifecycle of different pieces like Hydrogen and Crankshaft and how they play a role in code generation/optimization?

The short version is "full codegen, then Hydrogen". wingolog.org has some more in-depth articles.
 
2. Why does Vyacheslav suggest using --trace-hydrogen? Is that needed to see the disassembly?

No, it's needed for other things (c1visualizer, ir-hydra).

John Feminella

unread,
Oct 8, 2014, 1:46:57 PM10/8/14
to v8-u...@googlegroups.com
Thanks very much, Jakob! That was immensely helpful.

~ jf

Vyacheslav Egorov

unread,
Oct 9, 2014, 6:55:10 AM10/9/14
to v8-u...@googlegroups.com
Hi John, 

2. Why does Vyacheslav suggest using --trace-hydrogen? Is that needed to see the disassembly?

I suggest passing --trace-hydrogen because it is needed to see the HIR - high-level intermediate representation (also known as hydrogen) - which is much easier to read then raw assembly. (for example Slides 38 on show HIR, not disassembly)

Also if you --trace-hydrogen you can use a tool of mine called IRHydra[1] to inspect optimized code. It can show you source, HIR & disassembly all together[2]. 

 

Vyacheslav Egorov

On Wed, Oct 8, 2014 at 5:56 PM, John Feminella <j...@jxf.me> wrote:

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages