Index: third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
diff --git a/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp b/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
index 19eee733f61eadc76f64c8a9cac86fa1179742cb..03a3f4609db7d385884c80d6b6a5db4391760b2c 100644 |
--- a/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
+++ b/third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp |
@@ -27,6 +27,7 @@ |
#include <memory> |
+#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/ScriptForbiddenScope.h" |
#include "platform/WebTaskRunner.h" |
#include "platform/bindings/DOMDataStore.h" |
@@ -51,18 +52,29 @@ static void MicrotasksCompletedCallback(v8::Isolate* isolate) { |
V8PerIsolateData::From(isolate)->RunEndOfScopeTasks(); |
} |
-V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) |
+V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner, |
+ intptr_t* table, |
+ V8ContextMode context_mode) |
: isolate_holder_( |
task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr, |
gin::IsolateHolder::kSingleThread, |
IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait |
- : gin::IsolateHolder::kAllowAtomicsWait), |
+ : gin::IsolateHolder::kAllowAtomicsWait, |
+ table, |
+ context_mode == V8ContextMode::kUseSnapshot ? &startup_data_ |
Yuki
2017/05/30 14:35:58
Better to set v8_context_mode_ first, and use memb
peria
2017/06/01 08:33:34
Done.
|
+ : nullptr), |
+ v8_context_mode_(context_mode), |
string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))), |
private_property_(V8PrivateProperty::Create()), |
constructor_mode_(ConstructorMode::kCreateNewObject), |
use_counter_disabled_(false), |
is_handling_recursion_level_error_(false), |
is_reporting_exception_(false) { |
+ // In case if failed to load snapshot file |
+ if (v8_context_mode_ == V8ContextMode::kUseSnapshot && !startup_data_.data) { |
+ v8_context_mode_ = V8ContextMode::kDontUseSnapshot; |
Yuki
2017/05/30 14:35:58
Probably I asked this question before.
Do we reall
peria
2017/06/01 08:33:34
Let's chat again.
|
+ } |
+ |
// FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. |
GetIsolate()->Enter(); |
GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback); |
@@ -71,6 +83,23 @@ V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) |
g_main_thread_per_isolate_data = this; |
} |
+V8PerIsolateData::V8PerIsolateData(intptr_t* table) |
+ : snapshot_creator_(new v8::SnapshotCreator(table)), |
+ isolate_holder_(snapshot_creator_->GetIsolate()), |
+ v8_context_mode_(V8ContextMode::kTakeSnapshot), |
+ string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))), |
+ private_property_(V8PrivateProperty::Create()), |
+ constructor_mode_(ConstructorMode::kCreateNewObject), |
+ use_counter_disabled_(false), |
+ is_handling_recursion_level_error_(false), |
+ is_reporting_exception_(false) { |
+ // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. |
+ // SnapshotCreator enters the isolate, so don't do it again. |
+ GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback); |
+ GetIsolate()->AddMicrotasksCompletedCallback(&MicrotasksCompletedCallback); |
+ g_main_thread_per_isolate_data = this; |
+} |
+ |
V8PerIsolateData::~V8PerIsolateData() {} |
v8::Isolate* V8PerIsolateData::MainThreadIsolate() { |
@@ -78,8 +107,24 @@ v8::Isolate* V8PerIsolateData::MainThreadIsolate() { |
return g_main_thread_per_isolate_data->GetIsolate(); |
} |
-v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner) { |
- V8PerIsolateData* data = new V8PerIsolateData(task_runner); |
+v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner, |
+ intptr_t* table, |
+ V8ContextMode context_mode) { |
+ V8PerIsolateData* data = nullptr; |
+ if (context_mode == V8ContextMode::kTakeSnapshot) { |
+ CHECK(table); |
+ data = new V8PerIsolateData(table); |
+ v8::Isolate* isolate = data->GetIsolate(); |
+ CHECK(isolate); |
+ isolate->SetData(gin::kEmbedderBlink, data); |
+ return isolate; |
+ } |
+ |
+ if (!RuntimeEnabledFeatures::v8ContextSnapshotEnabled()) { |
+ context_mode = V8ContextMode::kDontUseSnapshot; |
+ table = nullptr; |
+ } |
+ data = new V8PerIsolateData(task_runner, table, context_mode); |
v8::Isolate* isolate = data->GetIsolate(); |
isolate->SetData(gin::kEmbedderBlink, data); |
return isolate; |
@@ -163,6 +208,14 @@ v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindOrCreateOperationTemplate( |
v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplate( |
const DOMWrapperWorld& world, |
const void* key) { |
+ if (GetV8ContextMode() == V8ContextMode::kTakeSnapshot) { |
+ auto& map = interface_template_persistent_map_; |
+ auto result = map.find(key); |
+ if (result != map.end()) |
+ return result->value.Get(GetIsolate()); |
+ return v8::Local<v8::FunctionTemplate>(); |
+ } |
+ |
auto& map = SelectInterfaceTemplateMap(world); |
auto result = map.find(key); |
if (result != map.end()) |
@@ -174,8 +227,18 @@ void V8PerIsolateData::SetInterfaceTemplate( |
const DOMWrapperWorld& world, |
const void* key, |
v8::Local<v8::FunctionTemplate> value) { |
- auto& map = SelectInterfaceTemplateMap(world); |
- map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); |
+ if (GetV8ContextMode() == V8ContextMode::kTakeSnapshot) { |
+ auto& map = interface_template_persistent_map_; |
+ map.insert(key, CopyablePersistent(GetIsolate(), value)); |
+ } else { |
+ auto& map = SelectInterfaceTemplateMap(world); |
+ map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); |
+ } |
+} |
+ |
+void V8PerIsolateData::ClearPersistents() { |
+ interface_template_persistent_map_.clear(); |
+ private_property_.reset(); |
} |
const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache( |