Commit 5dcedc18 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[snapshot] correctly mark SFIs with deserialized code.

We used to only mark top-level SFIs with the 'deserialized' bit.
Now we do it for every SFI that has cached code. This is the
first step to surface caching information in the future.

R=cbruni@chromium.org

Bug: chromium:769166
Change-Id: I12f21511419ce54fd07a2cc277a65866660c366a
Reviewed-on: https://chromium-review.googlesource.com/686715Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48184}
parent 552150b2
......@@ -113,6 +113,16 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
Script::cast(obj)->set_wrapper(isolate()->heap()->undefined_value());
}
if (obj->IsSharedFunctionInfo()) {
SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj);
// Mark SFI to indicate whether the code is cached.
bool was_deserialized = sfi->deserialized();
sfi->set_deserialized(sfi->is_compiled());
SerializeGeneric(obj, how_to_code, where_to_point);
sfi->set_deserialized(was_deserialized);
return;
}
// Past this point we should not see any (context-specific) maps anymore.
CHECK(!obj->IsMap());
// There should be no references to the global object embedded.
......@@ -189,7 +199,6 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
int length = cached_data->length();
PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
}
result->set_deserialized(true);
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
String* name = isolate->heap()->empty_string();
......
......@@ -1852,6 +1852,15 @@ v8::ScriptCompiler::CachedData* ProduceCache(const char* source,
return cache;
}
void CheckDeserializedFlag(v8::Local<v8::UnboundScript> script) {
i::Handle<i::SharedFunctionInfo> sfi = v8::Utils::OpenHandle(*script);
i::Handle<i::Script> i_script(Script::cast(sfi->script()));
i::SharedFunctionInfo::ScriptIterator iterator(i_script);
while (SharedFunctionInfo* next = iterator.Next()) {
CHECK_EQ(next->is_compiled(), next->deserialized());
}
}
TEST(CodeSerializerIsolates) {
const char* source = "function f() { return 'abc'; }; f() + 'def'";
v8::ScriptCompiler::CachedData* cache = ProduceCache(source);
......@@ -1879,6 +1888,7 @@ TEST(CodeSerializerIsolates) {
.ToLocalChecked();
}
CHECK(!cache->rejected);
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext())
.ToLocalChecked();
......@@ -1924,6 +1934,7 @@ TEST(CodeSerializerIsolatesEager) {
.ToLocalChecked();
}
CHECK(!cache->rejected);
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext())
.ToLocalChecked();
......@@ -2055,6 +2066,7 @@ TEST(CodeSerializerWithHarmonyScoping) {
isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache)
.ToLocalChecked();
}
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext())
.ToLocalChecked();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment