Does nodejs / v8 store compiled machine code anywhere on disk?

Edit : Node uses byte code with Node 8.3, before that the sources were compiled directly into machine code.

I code a lot of Python and always bytecode is in .pyc files.

I was wondering if Node saves its machine code in similar files, for example, it makes sense to save the representation of the machine code on disk and reuse it if the source of the file has not changed.

If so, where does node / v8 store this machine code?

Edit 2 : as @dystroy mentions below, this is a hoax How can I see the machine code created by v8?

+4
source share
3 answers

The eighth issue of 88 introduced the Ignition bytecode interpreter. You can print bytecode using --print-bytecode (Node 8.3 and later).

 $ 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 Bytecode .

To see the machine code, use --print-opt-code --code-comments .

+3
source

V8 is just a time compiler. Therefore, JavaScript cannot be compiled only once, like the python compiler, which is static compilation. It compiles how and when it should be executed.

You cannot see the generated machine code for JavaScript because it is not saved. It does not make sense to store the code of the machine that was compiled, since compilation is repeated and depends on optimizing the runtime. You do not get fixed machine code, as for python, every time this happens.

+8
source

From the project page :

V8 compiles JavaScript source code directly into machine code when it is first executed. No intermediate byte codes, no translator.

That is why you will not find the bytecode, no.

Regarding the new question following your editing, I think this related question answers it mostly. Of course, there is no reason at all for V8 to write machine code on a disk with a default installation. Since this code changes a lot (see the Link above, explaining how dynamic classes are created), this would be a gigantic overhead.

+4
source

Source: https://habr.com/ru/post/1481979/


All Articles