Add
or TypeOf
, or for loading properties - like LdaNamedProperty
. V8 also has some rather specific bytecodes, such as CreateObjectLiteral
or SuspendGenerator
. In the bytecodes.h header file you can find a complete list of V8 bytecodes.r0, r1, r2, ...
and the cumulative register. Almost all bytecodes use the cumulative register. It is similar to a regular register, except that it is clearly not indicated in bytecodes. For example, the Add r1
command adds the value from the r1
register to what is stored in the cumulative register. This makes bytecodes shorter and saves memory.Lda
or Sta
. The letter a
in Lda
and Sta
is an abbreviation of the word a ccumulator (cumulative register).LdaSmi [42]
command loads a small integer (Small Integer, Smi) 42
into the cumulative register. The Star r0
command writes the value that is in the cumulative register to the r0
register. function incrementX(obj) { return 1 + obj.x; } incrementX({x: 42}); // V8 , , ,
--print-bytecode
flag. In the case of Chrome, run it from the command line with the key - --js-flags="--print-bytecode"
. Here's the Chromium call with the keys. $ node --print-bytecode incrementX.js ... [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)
LdaSmi [1]
command loads constant 1
into the cumulative register.Star r0
command writes the value in the cumulative register, that is, 1
, to the r0
register.LdaNamedProperty
command loads the named property a0
into the cumulative register. The ai
construct refers to the ith argument of the incrementX()
function. In this example, we are accessing the named property at address a0
, that is, the first argument of incrementX()
. The name is determined by the constant 0
. LdaNamedProperty
uses 0
to look up the name in a separate table: - length: 1 0: 0x2ddf8db91611 <String[1]: x>
0
displayed on x
. As a result, it turns out that this byte code loads obj.x
4
? This is the index of the so-called feedback vector (feedback vector) of the increment(x)
function. The feedback vector contains runtime information that is used to optimize performance.r0
to the cumulative register, which results in a total of 43
. The number 6 —
another index of the feedback vector.Return
command returns the contents of the cumulative register. This is the completion of the incrementX()
function. What caused the incrementX()
, starts with the number 43
in the cumulative register and can continue to perform certain actions with this value.Source: https://habr.com/ru/post/336294/
All Articles