'Why are most v8 javascript bytecodes 5 or 6 bytes long?

I have seen several examples of bytecodes printed out in VSCode. I would like to know why these codes are customarily 5 to 6 bytes long and prepended by 0x. And if possible, can you tell me where I can find literature to answer such a question.



Solution 1:[1]

(V8 developer here.)

This appears to be a misunderstanding. Let's look at the example in the article linked in comments:

$ 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)

Here, 0x2ddf8802cf6e is not a bytecode; it's the address in memory where the function's first bytecode (StackCheck) is stored. The binary representation of this bytecode is not included in this printout, but we can deduce its size: from the difference to the second bytecode, whose address ends in 0x...f, we can see that StackCheck takes one byte in memory. The second bytecode in this example, LdaSmi, takes two bytes (0x...71 - 0x...6f == 2).

The 0x prefix simply indicates to human readers that the number is presented in hexadecimal format.

You typically see 12 hexadecimal digits in memory addresses because today's so-called "64-bit" platforms (usually) have 48 bits of virtual address space, and each hex digit can represent 4 bits. You can imagine four leading 0 digits for the full 64-bit pointer: 0x00002ddf8802cf6e.

(Technically the pointers are sign-extended, so if the 48 relevant bits started with a 1-bit, you'd have four leading f digits. In my experience so far, this usually doesn't happen in practice.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jmrk