v8 snapshot and javascript context

1,073 views
Skip to first unread message

shyam kumar

unread,
Dec 12, 2013, 9:22:41 PM12/12/13
to v8-u...@googlegroups.com
I want to know what v8 snapshot contains.I understand that it stores the javascript context at run time.
I would like to know that after saving the snapshot into file ,how do we pass the saved snaphot to the v8 and also how do we pass the external javascript to v8 .

Quick help appreciated as the project is in critical state.

Thanks in Advance
Shyamu

Sven Panne

unread,
Dec 13, 2013, 2:55:15 AM12/13/13
to v8-u...@googlegroups.com
On Fri, Dec 13, 2013 at 3:22 AM, shyam kumar <shya...@yahoo.co.in> wrote:
I want to know what v8 snapshot contains.I understand that it stores the javascript context at run time.

To be a bit more exact, the snapshot consists of 2 parts: One bigger per-Isolate part and a smaller per-Context part. This way one can quickly create new Contexts by "bolting on" the small part onto the big one. Both parts are in the snapshot.cc generated by mksnapshot during build time, which loads the needed JavaScript files and serializes them into 2 C++ arrays.
 
I would like to know that after saving the snapshot into file ,how do we pass the saved snaphot to the v8 and also how do we pass the external javascript to v8 . [...]

This is all done automatically when you mention your additional *.js files in tools/gyp/v8.gyp.

shyam kumar

unread,
Dec 13, 2013, 12:41:44 PM12/13/13
to v8-u...@googlegroups.com
thanks for the reply.I am new to v8 .Can you explain more in detail about per -Isolate and per-Context.

Sven Panne

unread,
Dec 16, 2013, 1:55:25 AM12/16/13
to v8-u...@googlegroups.com
On Fri, Dec 13, 2013 at 6:41 PM, shyam kumar <shya...@yahoo.co.in> wrote:
thanks for the reply.I am new to v8 .Can you explain more in detail about per -Isolate and per-Context.

Venkata Savilla

unread,
Dec 17, 2013, 2:54:04 AM12/17/13
to v8-u...@googlegroups.com
Hi Sven Panne ,
  V8 snapshot stores the context of compiled javascript code .Our requirement is to store the runtime javascript state and then resore the state  dynamically.
 
Regards
Shyam.

Sven Panne

unread,
Dec 17, 2013, 2:59:13 AM12/17/13
to v8-u...@googlegroups.com
On Tue, Dec 17, 2013 at 8:54 AM, Venkata Savilla <svn...@gmail.com> wrote:
Hi Sven Panne ,
  V8 snapshot stores the context of compiled javascript code .Our requirement is to store the runtime javascript state and then resore the state  dynamically.

What exactly should "runtime javascript state" mean? Furthermore, when exactly should state be saved/restored? A concrete example might help. Unless I am misunderstanding things, what you're trying to do is not possible, but to be sure I need to understand your use case in more detail.

Venkata Savilla

unread,
Dec 17, 2013, 4:10:15 AM12/17/13
to v8-u...@googlegroups.com
The use case is follows. 
 
when the users browses the website , some times browser crashes . 
I want to restore the  application to the previous state by  saving javascrpt context and DOM node data.
i want to launch the webiste with the same state(previous to chrash)  after the crash without hitting the webserver next time.

Sven Panne

unread,
Dec 17, 2013, 4:28:58 AM12/17/13
to v8-u...@googlegroups.com
On Tue, Dec 17, 2013 at 10:10 AM, Venkata Savilla <svn...@gmail.com> wrote:
The use case is follows. 
 
when the users browses the website , some times browser crashes . 
I want to restore the  application to the previous state by  saving javascrpt context and DOM node data.
i want to launch the webiste with the same state(previous to chrash)  after the crash without hitting the webserver next time.

So you want to restore a highly multi-threaded system to some given state. Unless I'm totally missing  something, this is fundamentally impossible. When exactly do you want to save the state of the system? Note that this will be a very heavy operation, subsystems have to be at some kind of safe point, you will need to know what to save etc. etc. Even if you manage to save the state, you will have a hard time restoring it, given things like ASLR, multiple threads running etc.

To be more specific about "safe points" for the v8 case: If you pick a random point in time, you have no guarantee at all that it is even possible to collect all necessary information. The heap might not be traversable at that point, the stack not walkable, some locks might be held by some threads, objects may be lying around half-initialized etc. Our snapshot mechanism takes great care to get the VM into a very defined state before it actually starts serializing the heap, furthermore there is no notion of "currently executing JavaScript" then.

Venkata Savilla

unread,
Dec 17, 2013, 5:08:12 AM12/17/13
to v8-u...@googlegroups.com
Thanks Sven .
Is there any alternation ways of saving javascript context .Please suggest .
 
Can we duplicate the render process to save document information.

Venkatesh S

unread,
Dec 20, 2013, 4:10:08 AM12/20/13
to v8-u...@googlegroups.com
if we turn of ASLR on the machine , is it possible to restore the state and assuming that it is a single threaded application.

Jakob Kummerow

unread,
Dec 20, 2013, 4:53:14 AM12/20/13
to v8-u...@googlegroups.com
No, there is no existing way to save and restore V8's state at arbitrary times. Sven has already explained why it's impossible to implement one. Assuming that V8 (or a Chrome renderer process) is single-threaded doesn't help, because it *isn't* single-threaded.

But even if what you're suggesting were possible, how would it help? Chances are, if you reset a given application to a state right before it crashed, it would just crash again, because the reason for the crash is already part of the application's state.

A much more robust approach is to save relevant high-level state on the application layer, e.g. like GMail saves drafts on the server while you type.


--

Reply all
Reply to author
Forward
0 new messages