pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
887 stars 119 forks source link

support for v8 snapshot #152

Closed syabyr closed 2 years ago

syabyr commented 3 years ago

Hi V8pp Team.

In some situation I want to load v8 snapshot in v8pp based project Is it possible to add this feature?

thanks.

jacobsologub commented 3 years ago

Information about snapshots: https://v8.dev/blog/custom-startup-snapshots

If you are using v8pp::context and currently not passing in an v8::Isolate then you'd need to do that by setting up your own v8::Isolate with a configured v8::Isolate::CreateParams that has a snapshot blob.

https://github.com/pmed/v8pp/blob/c6caf79e401df4d982857d79b4ba23f57f0a7b52/v8pp/context.cpp#L167

syabyr commented 3 years ago

After some trying,I found it`s not easy to create a snapshot with v8pp. some external reference should be passed when creating isolate,such as: reinterpret_cast(v8pp::module::var_set), reinterpret_cast(v8pp::module::var_set)

but there still some external reference can not be found:

Unknown external reference 0x20f6000.

Program received signal SIGILL, Illegal instruction. [Switching to Thread 0x7fffedca3700 (LWP 31228)] (gdb) p (char*)0x20f6000 $10 = 0x20f6000 "\240\210\021\001"
pmed commented 3 years ago

I'm doubt it's possible to create a viable V8 snapshot with a wrapped C++ entities. At least the snapshots documentation from the link above states that

There is an important limitation to this: the snapshot can only capture V8’s heap. Any interaction from V8 with the outside is off-limits when creating the snapshot. Such interactions include:

defining and calling API callbacks (i.e. functions created via v8::FunctionTemplate) creating typed arrays, since the backing store may be allocated outside of V8