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

Unified Diff: gin/isolate_holder.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: . Created 3 years, 8 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
Index: gin/isolate_holder.cc
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index caea27e7a569cad1b99efef6093c0da570deb4a8..5db5a9b7d03e79b9f50217ef8ffe02e86beebe15 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -34,23 +34,50 @@ IsolateHolder::IsolateHolder(
IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode)
- : IsolateHolder(std::move(task_runner), access_mode, kAllowAtomicsWait) {}
+ : IsolateHolder(std::move(task_runner),
+ access_mode,
+ kAllowAtomicsWait,
+ nullptr,
+ kDefault) {}
IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
- AllowAtomicsWaitMode atomics_wait_mode)
- : access_mode_(access_mode) {
+ AllowAtomicsWaitMode atomics_wait_mode,
+ intptr_t* reference,
+ V8ContextMode context_mode)
+ : access_mode_(access_mode), v8_context_mode_(context_mode) {
v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
- CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
- v8::Isolate::CreateParams params;
- params.entry_hook = DebugImpl::GetFunctionEntryHook();
- params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
- params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
- base::SysInfo::AmountOfVirtualMemory());
- params.array_buffer_allocator = allocator;
- params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait;
- isolate_ = v8::Isolate::New(params);
+
+ if (v8_context_mode_ == kTakeSnapshot) {
+ DCHECK(reference);
+ snapshot_creator_.reset(new v8::SnapshotCreator(reference));
+ isolate_ = snapshot_creator_->GetIsolate();
+ isolate_->Exit();
+ } else {
+ CHECK(allocator)
+ << "You need to invoke gin::IsolateHolder::Initialize first";
+ v8::Isolate::CreateParams params;
+ params.entry_hook = DebugImpl::GetFunctionEntryHook();
+ params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
+ params.constraints.ConfigureDefaults(
+ base::SysInfo::AmountOfPhysicalMemory(),
+ base::SysInfo::AmountOfVirtualMemory());
+ params.array_buffer_allocator = allocator;
+ params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait;
+ v8_context_mode_ = kDefault;
+ if (reference) {
+ V8Initializer::GetV8ContextData(&startup_data_.data,
+ &startup_data_.raw_size);
+ if (startup_data_.data) {
+ params.snapshot_blob = &startup_data_;
+ params.external_references = reference;
+ v8_context_mode_ = kUseSnapshot;
+ }
+ }
+ isolate_ = v8::Isolate::New(params);
+ }
+
isolate_data_.reset(
new PerIsolateData(isolate_, allocator, access_mode, task_runner));
isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
@@ -84,7 +111,7 @@ IsolateHolder::~IsolateHolder() {
isolate_memory_dump_provider_.reset();
isolate_data_.reset();
isolate_->Dispose();
- isolate_ = NULL;
+ isolate_ = nullptr;
}
// static

Powered by Google App Engine
This is Rietveld 408576698