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

Side by Side Diff: gin/isolate_holder.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: . Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/public/isolate_holder.h" 5 #include "gin/public/isolate_holder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 16 matching lines...) Expand all
27 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr; 27 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
28 } // namespace 28 } // namespace
29 29
30 IsolateHolder::IsolateHolder( 30 IsolateHolder::IsolateHolder(
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
32 : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {} 32 : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {}
33 33
34 IsolateHolder::IsolateHolder( 34 IsolateHolder::IsolateHolder(
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 35 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
36 AccessMode access_mode) 36 AccessMode access_mode)
37 : IsolateHolder(std::move(task_runner), access_mode, kAllowAtomicsWait) {} 37 : IsolateHolder(std::move(task_runner),
38 access_mode,
39 kAllowAtomicsWait,
40 nullptr,
41 kDefault) {}
38 42
39 IsolateHolder::IsolateHolder( 43 IsolateHolder::IsolateHolder(
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
41 AccessMode access_mode, 45 AccessMode access_mode,
42 AllowAtomicsWaitMode atomics_wait_mode) 46 AllowAtomicsWaitMode atomics_wait_mode,
43 : access_mode_(access_mode) { 47 intptr_t* reference,
48 V8ContextMode context_mode)
49 : access_mode_(access_mode), v8_context_mode_(context_mode) {
44 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator; 50 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
45 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first"; 51
46 v8::Isolate::CreateParams params; 52 if (v8_context_mode_ == kTakeSnapshot) {
47 params.entry_hook = DebugImpl::GetFunctionEntryHook(); 53 DCHECK(reference);
48 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); 54 snapshot_creator_.reset(new v8::SnapshotCreator(reference));
49 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), 55 isolate_ = snapshot_creator_->GetIsolate();
50 base::SysInfo::AmountOfVirtualMemory()); 56 isolate_->Exit();
51 params.array_buffer_allocator = allocator; 57 } else {
52 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait; 58 CHECK(allocator)
53 isolate_ = v8::Isolate::New(params); 59 << "You need to invoke gin::IsolateHolder::Initialize first";
60 v8::Isolate::CreateParams params;
61 params.entry_hook = DebugImpl::GetFunctionEntryHook();
62 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
63 params.constraints.ConfigureDefaults(
64 base::SysInfo::AmountOfPhysicalMemory(),
65 base::SysInfo::AmountOfVirtualMemory());
66 params.array_buffer_allocator = allocator;
67 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait;
68 v8_context_mode_ = kDefault;
69 if (reference) {
70 V8Initializer::GetV8ContextData(&startup_data_.data,
71 &startup_data_.raw_size);
72 if (startup_data_.data) {
73 params.snapshot_blob = &startup_data_;
74 params.external_references = reference;
75 v8_context_mode_ = kUseSnapshot;
76 }
77 }
78 isolate_ = v8::Isolate::New(params);
79 }
80
54 isolate_data_.reset( 81 isolate_data_.reset(
55 new PerIsolateData(isolate_, allocator, access_mode, task_runner)); 82 new PerIsolateData(isolate_, allocator, access_mode, task_runner));
56 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this)); 83 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
57 #if defined(OS_WIN) 84 #if defined(OS_WIN)
58 { 85 {
59 void* code_range; 86 void* code_range;
60 size_t size; 87 size_t size;
61 isolate_->GetCodeRange(&code_range, &size); 88 isolate_->GetCodeRange(&code_range, &size);
62 Debug::CodeRangeCreatedCallback callback = 89 Debug::CodeRangeCreatedCallback callback =
63 DebugImpl::GetCodeRangeCreatedCallback(); 90 DebugImpl::GetCodeRangeCreatedCallback();
(...skipping 13 matching lines...) Expand all
77 isolate_->GetCodeRange(&code_range, &size); 104 isolate_->GetCodeRange(&code_range, &size);
78 Debug::CodeRangeDeletedCallback callback = 105 Debug::CodeRangeDeletedCallback callback =
79 DebugImpl::GetCodeRangeDeletedCallback(); 106 DebugImpl::GetCodeRangeDeletedCallback();
80 if (code_range && callback) 107 if (code_range && callback)
81 callback(code_range); 108 callback(code_range);
82 } 109 }
83 #endif 110 #endif
84 isolate_memory_dump_provider_.reset(); 111 isolate_memory_dump_provider_.reset();
85 isolate_data_.reset(); 112 isolate_data_.reset();
86 isolate_->Dispose(); 113 isolate_->Dispose();
87 isolate_ = NULL; 114 isolate_ = nullptr;
88 } 115 }
89 116
90 // static 117 // static
91 void IsolateHolder::Initialize(ScriptMode mode, 118 void IsolateHolder::Initialize(ScriptMode mode,
92 V8ExtrasMode v8_extras_mode, 119 V8ExtrasMode v8_extras_mode,
93 v8::ArrayBuffer::Allocator* allocator) { 120 v8::ArrayBuffer::Allocator* allocator) {
94 CHECK(allocator); 121 CHECK(allocator);
95 V8Initializer::Initialize(mode, v8_extras_mode); 122 V8Initializer::Initialize(mode, v8_extras_mode);
96 g_array_buffer_allocator = allocator; 123 g_array_buffer_allocator = allocator;
97 } 124 }
(...skipping 10 matching lines...) Expand all
108 task_observer_.reset(); 135 task_observer_.reset();
109 } 136 }
110 137
111 void IsolateHolder::EnableIdleTasks( 138 void IsolateHolder::EnableIdleTasks(
112 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) { 139 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) {
113 DCHECK(isolate_data_.get()); 140 DCHECK(isolate_data_.get());
114 isolate_data_->EnableIdleTasks(std::move(idle_task_runner)); 141 isolate_data_->EnableIdleTasks(std::move(idle_task_runner));
115 } 142 }
116 143
117 } // namespace gin 144 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698