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..50ba239777a82091f646b78d43fa0ea6ebf16340 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) |
- : isolate_holder_( |
+V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner, |
+ intptr_t* table, |
+ V8ContextMode v8_context_mode) |
+ : v8_context_mode_(v8_context_mode), |
+ isolate_holder_( |
task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr, |
gin::IsolateHolder::kSingleThread, |
IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait |
- : gin::IsolateHolder::kAllowAtomicsWait), |
+ : gin::IsolateHolder::kAllowAtomicsWait, |
+ table, |
+ v8_context_mode_ == V8ContextMode::kUseSnapshot ? &startup_data_ |
+ : nullptr), |
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 the snapshot file |
+ if (v8_context_mode_ == V8ContextMode::kUseSnapshot && !startup_data_.data) { |
+ v8_context_mode_ = V8ContextMode::kDontUseSnapshot; |
+ } |
+ |
// FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. |
GetIsolate()->Enter(); |
GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback); |
@@ -71,6 +83,22 @@ V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) |
g_main_thread_per_isolate_data = this; |
} |
+V8PerIsolateData::V8PerIsolateData(intptr_t* reference_table) |
+ : v8_context_mode_(V8ContextMode::kTakeSnapshot), |
+ isolate_holder_(reference_table, nullptr), |
+ 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; |
Yuki
2017/06/01 14:15:51
Let's avoid copy&pasting. Then, we'll simply have
peria
2017/06/20 10:20:14
I feel this routine should not be run on non-main
|
+} |
+ |
V8PerIsolateData::~V8PerIsolateData() {} |
v8::Isolate* V8PerIsolateData::MainThreadIsolate() { |
@@ -78,8 +106,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, |
Yuki
2017/06/01 14:15:51
nit: s/table/reference_table/
peria
2017/06/20 10:20:14
Done.
|
+ V8ContextMode context_mode) { |
+ V8PerIsolateData* data = nullptr; |
Yuki
2017/06/01 14:15:51
Nice to have DCHECK(context_mode == kDontUseSnapsh
peria
2017/06/20 10:20:14
Done.
|
+ if (context_mode == V8ContextMode::kTakeSnapshot) { |
+ CHECK(table); |
+ data = new V8PerIsolateData(table); |
+ v8::Isolate* isolate = data->GetIsolate(); |
Yuki
2017/06/01 14:15:51
Better to share these lines of code with the latte
peria
2017/06/20 10:20:14
Done.
|
+ 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 +207,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_map_for_v8_snapshot_; |
+ 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 +226,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_map_for_v8_snapshot_; |
+ map.insert(key, CopyablePersistent(GetIsolate(), value)); |
+ } else { |
+ auto& map = SelectInterfaceTemplateMap(world); |
+ map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); |
+ } |
+} |
+ |
+void V8PerIsolateData::ClearPersistentsForV8Snapshot() { |
+ interface_template_map_for_v8_snapshot_.clear(); |
+ private_property_.reset(); |
} |
const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache( |