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

Side by Side Diff: gin/isolate_holder.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Support runtime feature on templates Created 3 years, 6 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 17 matching lines...) Expand all
28 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr; 28 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
29 } // namespace 29 } // namespace
30 30
31 IsolateHolder::IsolateHolder( 31 IsolateHolder::IsolateHolder(
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 32 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
33 : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {} 33 : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {}
34 34
35 IsolateHolder::IsolateHolder( 35 IsolateHolder::IsolateHolder(
36 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 36 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
37 AccessMode access_mode) 37 AccessMode access_mode)
38 : IsolateHolder(std::move(task_runner), access_mode, kAllowAtomicsWait) {} 38 : IsolateHolder(std::move(task_runner),
39 access_mode,
40 kAllowAtomicsWait,
41 nullptr,
42 nullptr) {}
39 43
40 IsolateHolder::IsolateHolder( 44 IsolateHolder::IsolateHolder(
41 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
42 AccessMode access_mode, 46 AccessMode access_mode,
43 AllowAtomicsWaitMode atomics_wait_mode) 47 AllowAtomicsWaitMode atomics_wait_mode,
48 intptr_t* reference,
49 v8::StartupData* startup_data)
44 : access_mode_(access_mode) { 50 : access_mode_(access_mode) {
45 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator; 51 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
46 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first"; 52 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
53
47 v8::Isolate::CreateParams params; 54 v8::Isolate::CreateParams params;
48 params.entry_hook = DebugImpl::GetFunctionEntryHook(); 55 params.entry_hook = DebugImpl::GetFunctionEntryHook();
49 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); 56 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
50 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), 57 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
51 base::SysInfo::AmountOfVirtualMemory()); 58 base::SysInfo::AmountOfVirtualMemory());
52 params.array_buffer_allocator = allocator; 59 params.array_buffer_allocator = allocator;
53 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait; 60 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait;
61 params.external_references = reference;
62
63 if (startup_data) {
64 CHECK(reference);
65 V8Initializer::GetBlinkV8SnapshotData(&startup_data->data,
66 &startup_data->raw_size);
67 if (startup_data->data) {
68 params.snapshot_blob = startup_data;
69 }
70 }
54 isolate_ = v8::Isolate::New(params); 71 isolate_ = v8::Isolate::New(params);
55 isolate_data_.reset( 72
56 new PerIsolateData(isolate_, allocator, access_mode, task_runner)); 73 SetUp(std::move(task_runner));
57 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
58 #if defined(OS_WIN)
59 {
60 void* code_range;
61 size_t size;
62 isolate_->GetCodeRange(&code_range, &size);
63 Debug::CodeRangeCreatedCallback callback =
64 DebugImpl::GetCodeRangeCreatedCallback();
65 if (code_range && size && callback)
66 callback(code_range, size);
67 }
68 #endif
69 } 74 }
70 75
71 IsolateHolder::IsolateHolder(intptr_t* reference_table, 76 IsolateHolder::IsolateHolder(intptr_t* reference_table,
72 v8::StartupData* existing_blob) 77 v8::StartupData* existing_blob)
73 : snapshot_creator_( 78 : snapshot_creator_(
74 new v8::SnapshotCreator(reference_table, existing_blob)), 79 new v8::SnapshotCreator(reference_table, existing_blob)),
75 access_mode_(kSingleThread) { 80 isolate_(snapshot_creator_->GetIsolate()),
81 access_mode_(AccessMode::kSingleThread) {
82 SetUp(nullptr);
83 }
84
85 void IsolateHolder::SetUp(
Yuki 2017/06/21 09:23:21 nit: Better to put this definition at the end of t
peria 2017/06/23 02:22:05 Done.
86 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
76 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator; 87 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
77 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first"; 88 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
78 isolate_ = snapshot_creator_->GetIsolate();
79 isolate_data_.reset( 89 isolate_data_.reset(
80 new PerIsolateData(isolate_, allocator, access_mode_, nullptr)); 90 new PerIsolateData(isolate_, allocator, access_mode_, task_runner));
81 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this)); 91 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
82 #if defined(OS_WIN) 92 #if defined(OS_WIN)
83 { 93 {
84 void* code_range; 94 void* code_range;
85 size_t size; 95 size_t size;
86 isolate_->GetCodeRange(&code_range, &size); 96 isolate_->GetCodeRange(&code_range, &size);
87 Debug::CodeRangeCreatedCallback callback = 97 Debug::CodeRangeCreatedCallback callback =
88 DebugImpl::GetCodeRangeCreatedCallback(); 98 DebugImpl::GetCodeRangeCreatedCallback();
89 if (code_range && size && callback) 99 if (code_range && size && callback)
90 callback(code_range, size); 100 callback(code_range, size);
(...skipping 11 matching lines...) Expand all
102 isolate_->GetCodeRange(&code_range, &size); 112 isolate_->GetCodeRange(&code_range, &size);
103 Debug::CodeRangeDeletedCallback callback = 113 Debug::CodeRangeDeletedCallback callback =
104 DebugImpl::GetCodeRangeDeletedCallback(); 114 DebugImpl::GetCodeRangeDeletedCallback();
105 if (code_range && callback) 115 if (code_range && callback)
106 callback(code_range); 116 callback(code_range);
107 } 117 }
108 #endif 118 #endif
109 isolate_memory_dump_provider_.reset(); 119 isolate_memory_dump_provider_.reset();
110 isolate_data_.reset(); 120 isolate_data_.reset();
111 isolate_->Dispose(); 121 isolate_->Dispose();
112 isolate_ = NULL; 122 isolate_ = nullptr;
113 } 123 }
114 124
115 // static 125 // static
116 void IsolateHolder::Initialize(ScriptMode mode, 126 void IsolateHolder::Initialize(ScriptMode mode,
117 V8ExtrasMode v8_extras_mode, 127 V8ExtrasMode v8_extras_mode,
118 v8::ArrayBuffer::Allocator* allocator) { 128 v8::ArrayBuffer::Allocator* allocator) {
119 CHECK(allocator); 129 CHECK(allocator);
120 V8Initializer::Initialize(mode, v8_extras_mode); 130 V8Initializer::Initialize(mode, v8_extras_mode);
121 g_array_buffer_allocator = allocator; 131 g_array_buffer_allocator = allocator;
122 } 132 }
(...skipping 10 matching lines...) Expand all
133 task_observer_.reset(); 143 task_observer_.reset();
134 } 144 }
135 145
136 void IsolateHolder::EnableIdleTasks( 146 void IsolateHolder::EnableIdleTasks(
137 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) { 147 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) {
138 DCHECK(isolate_data_.get()); 148 DCHECK(isolate_data_.get());
139 isolate_data_->EnableIdleTasks(std::move(idle_task_runner)); 149 isolate_data_->EnableIdleTasks(std::move(idle_task_runner));
140 } 150 }
141 151
142 } // namespace gin 152 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698