what is the relationship between natives_blob.bin and snapshot_blob.bin?

1871 views
Skip to first unread message

fengx...@gmail.com

unread,
Jul 12, 2018, 4:52:12 AM7/12/18
to v8-users
when v8 is compiled with options "v8_use_snapshot=true v8_use_external_startup_data=true", two files which are natives_blob.bin  and snapshot_blob.bin will be generated. when we use v8 in our embedder progroam, V8::InitializeExternalStartupData need be called to load the two files. After that, we need to new a isolate by calling Isolate::New that will call isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); if we don't supply a custom snapshot data by specifing CreateParams's snapshot_blob.  

But if v8 is complied with options "v8_use_snapshot=true v8_use_external_startup_data=false",  natives_blob.bin  and snapshot_blob.bin will not be generated. V8::InitializeExternalStartupData need not be called. Can I call Isolate::New with a custom snapshot data that was generated by SnapshotCreator Api. Notice in this case no natives_blob.bin is supplied. So is natives_blob.bin necessary ? Is natives_blob.bin complied into v8 binary?

we can still supply a custom snapshot to CreateParams even if v8 is complied with options "v8_use_snapshot=false", is that right?

what is the relationship between natives_blob.bin and snapshot_blob.bin? why not just generate one snapshot file?

Jakob Gruber

unread,
Jul 17, 2018, 3:31:11 AM7/17/18
to v8-u...@googlegroups.com
natives_blob.bin contains the minified source code of JS natives shipped with V8, while snapshot_blob.bin contains the startup and context snapshots. We are working on removing natives_blob.bin, hopefully this will happen sometime this year.

Given "v8_use_snapshot=true v8_use_external_startup_data=false", the serialized data is compiled into the binary.
Given "v8_use_snapshot=true v8_use_external_startup_data=true", serialized data is shipped as the external .bin files you mentioned.

I hope that helps a bit. I'm not sure I understand your remaining questions, could you clarify if things are still unclear?

fengx...@gmail.com

unread,
Jul 17, 2018, 5:55:04 AM7/17/18
to v8-users
Thanks for your kindly reply.

What do you mean "Js natives"? Are they some c++ native functions written in c++ on which v8's build-in js source codes depend? 

I noticed that "v8_use_external_startup_data" is only used when "v8_use_snapshot=true". So I thought "v8_use_external_startup_data" just controls whether snapshot data is compiled into the binary. But actually it controls both snapshot data and natives_blob data.

Given "v8_use_snapshot=true v8_use_external_startup_data=false", I can find the equivalent of snapshot_blob.bin that is snapshot.cc generated by mksnapshot, but I can't find the  equivalent of native_blob.bin.

Also I thought "v8_use_snapshot" is used to control the disable/enable of snapshot functionality, but actually it controls the generation of default snapshot data. Even if given "v8_use_snapshot=false", I can still feed v8 with my custom snapshot data.

在 2018年7月17日星期二 UTC+8下午3:31:11,Jakob Gruber写道:

Jakob Gruber

unread,
Jul 17, 2018, 6:44:05 AM7/17/18
to v8-u...@googlegroups.com
On Tue, Jul 17, 2018 at 11:55 AM, <fengx...@gmail.com> wrote:
Thanks for your kindly reply.

What do you mean "Js natives"? Are they some c++ native functions written in c++ on which v8's build-in js source codes depend? 

JS natives are builtin code shipped with V8 that are still implemented in JavaScript, see e.g.: https://cs.chromium.org/chromium/src/v8/src/js/array.js?l=1&rcl=f1b3e80faad6c84deabec8043bae524d1480293b
 

I noticed that "v8_use_external_startup_data" is only used when "v8_use_snapshot=true". So I thought "v8_use_external_startup_data" just controls whether snapshot data is compiled into the binary. But actually it controls both snapshot data and natives_blob data.

Given "v8_use_snapshot=true v8_use_external_startup_data=false", I can find the equivalent of snapshot_blob.bin that is snapshot.cc generated by mksnapshot, but I can't find the  equivalent of native_blob.bin.

The equivalent for natives_blob.bin is libraries.cc.
 

Also I thought "v8_use_snapshot" is used to control the disable/enable of snapshot functionality, but actually it controls the generation of default snapshot data. Even if given "v8_use_snapshot=false", I can still feed v8 with my custom snapshot data.

Right. Look for V8_USE_SNAPSHOT in the V8 source code to see what changes (spoiler: not much). It's mostly the build process that differs.
Reply all
Reply to author
Forward
0 new messages