V8 snapshots

239 views
Skip to first unread message

Francisco Moraes

unread,
Sep 1, 2017, 11:57:51 AM9/1/17
to v8-users
Hello,

I am trying to create a snapshot that includes most of code but I ran into the following assertion:

  CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());


Any clarifications about what would generate it that our JS code is doing and is not legal? I found that creating Unsafe Arrays is also not permitted but that is relatively easy to work around.

Francisco

Zac Hansen

unread,
Sep 2, 2017, 1:07:28 AM9/2/17
to v8-users
Can you post a minimal complete example that reproduces your problem?

Francisco Moraes

unread,
Sep 5, 2017, 12:42:03 PM9/5/17
to v8-users
I will give it a try sometime this week. I tried to remove our initialization JS file but that caused a failure further down the serialization as well, so still investigating.

Zac Hansen

unread,
Sep 5, 2017, 2:50:36 PM9/5/17
to v8-u...@googlegroups.com
That kind of error usually means you either haven't created a context or aren't in a context or haven't created an appropriate handle.  Or... Something else :-/. Maybe a lock?  V8 errors are very much a "you screwed up somewhere" notification and often nothing more 

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/kxtnaSSQL9c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Francisco Moraes

unread,
Sep 6, 2017, 10:20:33 AM9/6/17
to v8-users
Here's a simple recreate that I managed to create:

#include <string.h>

#include "v8.h"
#include "libplatform/libplatform.h"

int main(int argv, char **argc)
{
    const char *v8flags = "";
    v8::Platform *platform = v8::platform::CreateDefaultPlatform();
    v8::V8::SetFlagsFromString (v8flags, strlen (v8flags));
    v8::V8::InitializePlatform(platform);
    v8::V8::Initialize();

    v8::SnapshotCreator creator;
    v8::Isolate *isolate = creator.GetIsolate();
    
    v8::HandleScope handle_scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    const char* source = "function initialize(obj) { return true; }";
    v8::Context::Scope context_scope(context);
    v8::TryCatch try_catch(isolate);
    v8::Local<v8::String> source_string;
    v8::String::NewFromUtf8(isolate, source, v8::NewStringType::kNormal)
        .ToLocal(&source_string);
    v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "testscript"));
    v8::ScriptCompiler::Source sourcecode(source_string, origin);
    v8::Local<v8::Script> script;
    bool success = v8::ScriptCompiler::Compile(context, &sourcecode).ToLocal(&script);

    script->Run(context);
  
    creator.SetDefaultContext(context);
    v8::StartupData blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);

    return 1;
}

The interesting thing is if I call v8::V8::CreateSnapshotDataBlob it works as it does all the above work for me, so something in trying to use the SnapshotCreator is causing me some issue as I will need to handle custom embedder fields, etc...

Zac Hansen

unread,
Sep 6, 2017, 12:27:35 PM9/6/17
to v8-users
https://v8.paulfryzel.com/docs/master/classv8_1_1_snapshot_creator.html#a86b2023acdb88a9bd6eae2695f2b0a8a

Created a snapshot data blob. This must not be called from within a handle scope.

Francisco Moraes

unread,
Sep 6, 2017, 2:26:59 PM9/6/17
to v8-users
After fixing the issue about the handle scope, I can successfully create the snapshot for the test code, but when I tried something more complicated, I ran into this now:

Check failed: 0 == isolate->global_handles()->global_handles_count() (0 vs. 4).

Zac Hansen

unread,
Sep 6, 2017, 2:32:49 PM9/6/17
to v8-u...@googlegroups.com
Just a guess but how would he system know how to deal with objects held by global handles when making a snapshot?   You can't serialize the global handles in such a way that they would be useful in any way?

I'm guessing this is just a sanity check to make sure you aren't doing something unintended.  

I could be completely wrong but I'd say just free up your globals and if that changes the behavior then you weren't ready to make a snapshot anyhow.  

Francisco Moraes

unread,
Sep 6, 2017, 2:56:18 PM9/6/17
to v8-users
What's the best way to find what the Global Handles actually are? I found that I can print the handles but it still doesn't help me find what they actually are. Once I know what they are, I can find the culprit and eliminate it.

Zac Hansen

unread,
Sep 6, 2017, 3:00:28 PM9/6/17
to v8-u...@googlegroups.com
As far as I know they are only the ones you explicitly make to hold on to things outside of the scope of JavaScript.   Anything with the term "global" or "persistent" is a likely culprit. 

Again these are all guesses.   I would try taking a snapshot that works creating a global handle and trying again to see that it causes the same assertion before pursuing down this path to make sure I'm not just completely wrong.  

Zac Hansen

unread,
Sep 6, 2017, 3:26:36 PM9/6/17
to v8-u...@googlegroups.com
If that doesn't do it, again try to come up with a self contained example and post it.  Like I said before often v8 errors mean nothing more than "you screwed up somewhere" so just the error message is rather meaningless--at least to me.  

Francisco Moraes

unread,
Sep 7, 2017, 11:04:27 AM9/7/17
to v8-users
If you know of a way to find more information on what the global handles may be, it may be helpful. Otherwise, I will have to scrub everything until I find something that works. For instance:

(gdb) print isolate->global_handles()->Print()
Global handles:
  handle 0x7ffe3af84008 to 0x367b6c023fa9
  handle 0x7ffe3af84028 to 0x7e1669936c1

I would like to know what those 2 handles are that are causing the serialization to fail.

Jakob Gruber

unread,
Sep 7, 2017, 11:16:24 AM9/7/17
to v8-u...@googlegroups.com
You can use the `job` gdb macro (see gdbinit) to print heap objects. E.g. 'job 0x367b6c023fa9'.

You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Jakob Gruber

Software Engineer

jgr...@google.com

Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.

    

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.

Francisco Moraes

unread,
Sep 7, 2017, 4:33:20 PM9/7/17
to v8-users
Thanks. I am finding that my main hurdle is that there are several v8::Persistent objects which block creation of the snapshot. Is there any suggested work around for those other than rewriting the code ?

Zac Hansen

unread,
Sep 7, 2017, 6:29:33 PM9/7/17
to v8-u...@googlegroups.com
can you make a special code path just for making the snapshot that releases the persistent/globals then makes the snapshots and then exits?   Then you start up the "normal" code pay with the new snapshots that can create the persistent a/globals all it wants.  

Yang Guo

unread,
Sep 8, 2017, 6:57:48 AM9/8/17
to v8-users
V8's serializer simply does not support serializing handles. You can't have any open handle scopes when you serialize. You can store these handles somewhere on the context before serializing, and retrieve it after deserializing.
Reply all
Reply to author
Forward
0 new messages