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

Side by Side Diff: gin/isolate_holder.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Work for most comments 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::GetV8ContextData(&startup_data->data,
66 &startup_data->raw_size);
67 if (startup_data->data) {
68 params.snapshot_blob = startup_data;
69 }
Yuki 2017/05/30 14:35:56 What happens if GetV8ContextData fails to load the
peria 2017/06/01 08:33:32 I can't agree to make it an error. Even if Chrome
70 }
54 isolate_ = v8::Isolate::New(params); 71 isolate_ = v8::Isolate::New(params);
72
55 isolate_data_.reset( 73 isolate_data_.reset(
56 new PerIsolateData(isolate_, allocator, access_mode, task_runner)); 74 new PerIsolateData(isolate_, allocator, access_mode, task_runner));
57 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this)); 75 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
58 #if defined(OS_WIN) 76 #if defined(OS_WIN)
59 { 77 {
60 void* code_range; 78 void* code_range;
61 size_t size; 79 size_t size;
62 isolate_->GetCodeRange(&code_range, &size); 80 isolate_->GetCodeRange(&code_range, &size);
63 Debug::CodeRangeCreatedCallback callback = 81 Debug::CodeRangeCreatedCallback callback =
64 DebugImpl::GetCodeRangeCreatedCallback(); 82 DebugImpl::GetCodeRangeCreatedCallback();
65 if (code_range && size && callback) 83 if (code_range && size && callback)
66 callback(code_range, size); 84 callback(code_range, size);
67 } 85 }
68 #endif 86 #endif
69 } 87 }
70 88
89 IsolateHolder::IsolateHolder(v8::Isolate* isolate)
90 : isolate_(isolate), access_mode_(kSingleThread) {
Yuki 2017/05/30 14:35:56 Could you avoid copy&pasting? Can we have a helpe
peria 2017/06/01 08:33:32 Done. Will move to another CL.
91 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
92 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
93 isolate_data_.reset(
94 new PerIsolateData(isolate_, allocator, access_mode_, nullptr));
95 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
96 #if defined(OS_WIN)
97 {
98 void* code_range;
99 size_t size;
100 isolate_->GetCodeRange(&code_range, &size);
101 Debug::CodeRangeCreatedCallback callback =
102 DebugImpl::GetCodeRangeCreatedCallback();
103 if (code_range && size && callback)
104 callback(code_range, size);
105 }
106 #endif
107 }
108
71 IsolateHolder::~IsolateHolder() { 109 IsolateHolder::~IsolateHolder() {
72 if (task_observer_.get()) 110 if (task_observer_.get())
73 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); 111 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
74 #if defined(OS_WIN) 112 #if defined(OS_WIN)
75 { 113 {
76 void* code_range; 114 void* code_range;
77 size_t size; 115 size_t size;
78 isolate_->GetCodeRange(&code_range, &size); 116 isolate_->GetCodeRange(&code_range, &size);
79 Debug::CodeRangeDeletedCallback callback = 117 Debug::CodeRangeDeletedCallback callback =
80 DebugImpl::GetCodeRangeDeletedCallback(); 118 DebugImpl::GetCodeRangeDeletedCallback();
81 if (code_range && callback) 119 if (code_range && callback)
82 callback(code_range); 120 callback(code_range);
83 } 121 }
84 #endif 122 #endif
85 isolate_memory_dump_provider_.reset(); 123 isolate_memory_dump_provider_.reset();
86 isolate_data_.reset(); 124 isolate_data_.reset();
87 isolate_->Dispose(); 125 isolate_->Dispose();
88 isolate_ = NULL; 126 isolate_ = nullptr;
89 } 127 }
90 128
91 // static 129 // static
92 void IsolateHolder::Initialize(ScriptMode mode, 130 void IsolateHolder::Initialize(ScriptMode mode,
93 V8ExtrasMode v8_extras_mode, 131 V8ExtrasMode v8_extras_mode,
94 v8::ArrayBuffer::Allocator* allocator) { 132 v8::ArrayBuffer::Allocator* allocator) {
95 CHECK(allocator); 133 CHECK(allocator);
96 V8Initializer::Initialize(mode, v8_extras_mode); 134 V8Initializer::Initialize(mode, v8_extras_mode);
97 g_array_buffer_allocator = allocator; 135 g_array_buffer_allocator = allocator;
98 } 136 }
(...skipping 10 matching lines...) Expand all
109 task_observer_.reset(); 147 task_observer_.reset();
110 } 148 }
111 149
112 void IsolateHolder::EnableIdleTasks( 150 void IsolateHolder::EnableIdleTasks(
113 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) { 151 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) {
114 DCHECK(isolate_data_.get()); 152 DCHECK(isolate_data_.get());
115 isolate_data_->EnableIdleTasks(std::move(idle_task_runner)); 153 isolate_data_->EnableIdleTasks(std::move(idle_task_runner));
116 } 154 }
117 155
118 } // namespace gin 156 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698