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, ...@@ -113,6 +113,16 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
Script::cast(obj)->set_wrapper(isolate()->heap()->undefined_value()); 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. // Past this point we should not see any (context-specific) maps anymore.
CHECK(!obj->IsMap()); CHECK(!obj->IsMap());
// There should be no references to the global object embedded. // There should be no references to the global object embedded.
...@@ -189,7 +199,6 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize( ...@@ -189,7 +199,6 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
int length = cached_data->length(); int length = cached_data->length();
PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms); 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()) { if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
String* name = isolate->heap()->empty_string(); String* name = isolate->heap()->empty_string();
......
...@@ -1852,6 +1852,15 @@ v8::ScriptCompiler::CachedData* ProduceCache(const char* source, ...@@ -1852,6 +1852,15 @@ v8::ScriptCompiler::CachedData* ProduceCache(const char* source,
return cache; 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) { TEST(CodeSerializerIsolates) {
const char* source = "function f() { return 'abc'; }; f() + 'def'"; const char* source = "function f() { return 'abc'; }; f() + 'def'";
v8::ScriptCompiler::CachedData* cache = ProduceCache(source); v8::ScriptCompiler::CachedData* cache = ProduceCache(source);
...@@ -1879,6 +1888,7 @@ TEST(CodeSerializerIsolates) { ...@@ -1879,6 +1888,7 @@ TEST(CodeSerializerIsolates) {
.ToLocalChecked(); .ToLocalChecked();
} }
CHECK(!cache->rejected); CHECK(!cache->rejected);
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext() v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext()) ->Run(isolate2->GetCurrentContext())
.ToLocalChecked(); .ToLocalChecked();
...@@ -1924,6 +1934,7 @@ TEST(CodeSerializerIsolatesEager) { ...@@ -1924,6 +1934,7 @@ TEST(CodeSerializerIsolatesEager) {
.ToLocalChecked(); .ToLocalChecked();
} }
CHECK(!cache->rejected); CHECK(!cache->rejected);
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext() v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext()) ->Run(isolate2->GetCurrentContext())
.ToLocalChecked(); .ToLocalChecked();
...@@ -2055,6 +2066,7 @@ TEST(CodeSerializerWithHarmonyScoping) { ...@@ -2055,6 +2066,7 @@ TEST(CodeSerializerWithHarmonyScoping) {
isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache) isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache)
.ToLocalChecked(); .ToLocalChecked();
} }
CheckDeserializedFlag(script);
v8::Local<v8::Value> result = script->BindToCurrentContext() v8::Local<v8::Value> result = script->BindToCurrentContext()
->Run(isolate2->GetCurrentContext()) ->Run(isolate2->GetCurrentContext())
.ToLocalChecked(); .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