Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: third_party/WebKit/Source/platform/bindings/V8PerIsolateData.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/bindings/V8PerIsolateData.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6ba47d5d3947f9fc8055d86f5092314861d21602..35dafe98777b6209dbcb9aa88b3f61ae774c6c0c 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"
@@ -52,18 +53,34 @@ 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,
+ V8ContextSnapshotMode v8_context_snapshot_mode)
+ : v8_context_snapshot_mode_(v8_context_snapshot_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_snapshot_mode_ == V8ContextSnapshotMode::kUseSnapshot
+ ? &startup_data_
+ : nullptr),
+ interface_template_map_for_v8_context_snapshot_(GetIsolate()),
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) {
+ // If it fails to load the snapshot file, falls back to kDontUseSnapshot mode.
+ // TODO(peria): Remove this fallback routine.
+ if (v8_context_snapshot_mode_ == V8ContextSnapshotMode::kUseSnapshot &&
+ !startup_data_.data) {
+ v8_context_snapshot_mode_ = V8ContextSnapshotMode::kDontUseSnapshot;
+ }
+
// FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
GetIsolate()->Enter();
GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback);
@@ -72,6 +89,24 @@ V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner)
g_main_thread_per_isolate_data = this;
}
+// This constructor is used for taking a V8 context snapshot. It must run on the
+// main thread.
+V8PerIsolateData::V8PerIsolateData(intptr_t* reference_table)
+ : v8_context_snapshot_mode_(V8ContextSnapshotMode::kTakeSnapshot),
+ isolate_holder_(reference_table, nullptr),
+ interface_template_map_for_v8_context_snapshot_(GetIsolate()),
+ 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) {
+ CHECK(IsMainThread());
+
+ // SnapshotCreator enters the isolate, so we don't call Isolate::Enter() here.
+ g_main_thread_per_isolate_data = this;
+}
+
V8PerIsolateData::~V8PerIsolateData() {}
v8::Isolate* V8PerIsolateData::MainThreadIsolate() {
@@ -79,8 +114,21 @@ 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* reference_table,
+ V8ContextSnapshotMode context_mode) {
+ DCHECK(context_mode == V8ContextSnapshotMode::kDontUseSnapshot ||
+ reference_table);
+
+ V8PerIsolateData* data = nullptr;
+ if (context_mode == V8ContextSnapshotMode::kTakeSnapshot) {
+ CHECK(reference_table);
+ data = new V8PerIsolateData(reference_table);
+ } else {
+ data = new V8PerIsolateData(task_runner, reference_table, context_mode);
+ }
+ DCHECK(data);
+
v8::Isolate* isolate = data->GetIsolate();
isolate->SetData(gin::kEmbedderBlink, data);
return isolate;
@@ -164,6 +212,11 @@ v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindOrCreateOperationTemplate(
v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplate(
const DOMWrapperWorld& world,
const void* key) {
+ if (GetV8ContextSnapshotMode() == V8ContextSnapshotMode::kTakeSnapshot) {
+ const WrapperTypeInfo* type = reinterpret_cast<const WrapperTypeInfo*>(key);
+ return interface_template_map_for_v8_context_snapshot_.Get(type);
+ }
+
auto& map = SelectInterfaceTemplateMap(world);
auto result = map.find(key);
if (result != map.end())
@@ -175,8 +228,19 @@ 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 (GetV8ContextSnapshotMode() == V8ContextSnapshotMode::kTakeSnapshot) {
+ auto& map = interface_template_map_for_v8_context_snapshot_;
+ const WrapperTypeInfo* type = reinterpret_cast<const WrapperTypeInfo*>(key);
+ map.Set(type, value);
+ } else {
+ auto& map = SelectInterfaceTemplateMap(world);
+ map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value));
+ }
+}
+
+void V8PerIsolateData::ClearPersistentsForV8ContextSnapshot() {
+ interface_template_map_for_v8_context_snapshot_.Clear();
+ private_property_.reset();
}
const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache(
« no previous file with comments | « third_party/WebKit/Source/platform/bindings/V8PerIsolateData.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698