Vahag Vardanyan
Vahag Vardanyan

Reputation: 301

Get JavaScript bytecode

I have read that Javascript source code first compiles to the intermediate representation(bytecode). Then bytecode compiles to the native code using jit. So I compile webkit on my linux machine, and want to get bytecode of source file. But I can't figure how to do that?

How can I see/access the intermediate byte code that a javascript interpreter produces?

Upvotes: 3

Views: 3039

Answers (1)

user835611
user835611

Reputation: 2366

If you use Chrome or Node, the JS Engine V8 generates bytecode. Safari has a similar flag.

V8 introduced a bytecode interpreter, Ignition, in 2016. You can print the bytecode with --print-bytecode (Node 8.3 and newer).

$ node --print-bytecode incrementX.js -e 'function incrementX(obj) {return 1 + obj.x;} incrementX({x: 42});`
...
[generating bytecode for function: incrementX]
Parameter count 2
Frame size 8
  12 E> 0x2ddf8802cf6e @    StackCheck
  19 S> 0x2ddf8802cf6f @    LdaSmi [1]
        0x2ddf8802cf71 @    Star r0
  34 E> 0x2ddf8802cf73 @    LdaNamedProperty a0, [0], [4]
  28 E> 0x2ddf8802cf77 @    Add r0, [6]
  36 S> 0x2ddf8802cf7a @    Return
Constant pool (size = 1)
0x2ddf8802cf21: [FixedArray] in OldSpace
 - map = 0x2ddfb2d02309 <Map(HOLEY_ELEMENTS)>
 - length: 1
           0: 0x2ddf8db91611 <String[1]: x>
Handler Table (size = 16)

See Understanding V8's Bytecode.

Upvotes: 7

Related Questions