OLD | NEW |
---|---|
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 Loading... | |
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 kDefault) {} | |
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, |
44 : access_mode_(access_mode) { | 48 intptr_t* reference, |
49 V8ContextMode context_mode) | |
50 : access_mode_(access_mode), v8_context_mode_(context_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 |
47 v8::Isolate::CreateParams params; | 53 if (v8_context_mode_ == kTakeSnapshot) { |
48 params.entry_hook = DebugImpl::GetFunctionEntryHook(); | 54 DCHECK(reference); |
49 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); | 55 snapshot_creator_.reset(new v8::SnapshotCreator(reference)); |
haraken
2017/05/20 19:10:02
It looks strange that we have to create the snapsh
peria
2017/05/30 08:25:43
Done.
| |
50 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), | 56 isolate_ = snapshot_creator_->GetIsolate(); |
51 base::SysInfo::AmountOfVirtualMemory()); | 57 isolate_->Exit(); |
haraken
2017/05/20 19:10:02
Just to confirm: Does "new v8::SnapshotCreator(ref
peria
2017/05/30 08:25:43
Acknowledged.
| |
52 params.array_buffer_allocator = allocator; | 58 } else { |
53 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait; | 59 CHECK(allocator) |
54 isolate_ = v8::Isolate::New(params); | 60 << "You need to invoke gin::IsolateHolder::Initialize first"; |
61 v8::Isolate::CreateParams params; | |
62 params.entry_hook = DebugImpl::GetFunctionEntryHook(); | |
63 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); | |
64 params.constraints.ConfigureDefaults( | |
65 base::SysInfo::AmountOfPhysicalMemory(), | |
66 base::SysInfo::AmountOfVirtualMemory()); | |
67 params.array_buffer_allocator = allocator; | |
68 params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait; | |
69 | |
70 params.external_references = reference; | |
71 if (v8_context_mode_ == kUseSnapshot) { | |
72 CHECK(reference); | |
73 V8Initializer::GetV8ContextData(&startup_data_.data, | |
74 &startup_data_.raw_size); | |
haraken
2017/05/20 19:10:02
Can we move this code to when LocalWindowProxy use
peria
2017/05/30 08:25:43
Function name seems wrong, but this actually loads
| |
75 if (startup_data_.data) { | |
76 params.snapshot_blob = &startup_data_; | |
77 } else { | |
78 params.snapshot_blob = nullptr; | |
79 v8_context_mode_ = kDefault; | |
haraken
2017/05/20 19:10:02
Why do we need to overwrite v8_context_mode_ here?
peria
2017/05/30 08:25:43
it is used to handle context creation (FromSnapsho
| |
80 } | |
81 } | |
82 isolate_ = v8::Isolate::New(params); | |
83 } | |
84 | |
55 isolate_data_.reset( | 85 isolate_data_.reset( |
56 new PerIsolateData(isolate_, allocator, access_mode, task_runner)); | 86 new PerIsolateData(isolate_, allocator, access_mode, task_runner)); |
57 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this)); | 87 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this)); |
58 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
59 { | 89 { |
60 void* code_range; | 90 void* code_range; |
61 size_t size; | 91 size_t size; |
62 isolate_->GetCodeRange(&code_range, &size); | 92 isolate_->GetCodeRange(&code_range, &size); |
63 Debug::CodeRangeCreatedCallback callback = | 93 Debug::CodeRangeCreatedCallback callback = |
64 DebugImpl::GetCodeRangeCreatedCallback(); | 94 DebugImpl::GetCodeRangeCreatedCallback(); |
(...skipping 13 matching lines...) Expand all Loading... | |
78 isolate_->GetCodeRange(&code_range, &size); | 108 isolate_->GetCodeRange(&code_range, &size); |
79 Debug::CodeRangeDeletedCallback callback = | 109 Debug::CodeRangeDeletedCallback callback = |
80 DebugImpl::GetCodeRangeDeletedCallback(); | 110 DebugImpl::GetCodeRangeDeletedCallback(); |
81 if (code_range && callback) | 111 if (code_range && callback) |
82 callback(code_range); | 112 callback(code_range); |
83 } | 113 } |
84 #endif | 114 #endif |
85 isolate_memory_dump_provider_.reset(); | 115 isolate_memory_dump_provider_.reset(); |
86 isolate_data_.reset(); | 116 isolate_data_.reset(); |
87 isolate_->Dispose(); | 117 isolate_->Dispose(); |
88 isolate_ = NULL; | 118 isolate_ = nullptr; |
89 } | 119 } |
90 | 120 |
91 // static | 121 // static |
92 void IsolateHolder::Initialize(ScriptMode mode, | 122 void IsolateHolder::Initialize(ScriptMode mode, |
93 V8ExtrasMode v8_extras_mode, | 123 V8ExtrasMode v8_extras_mode, |
94 v8::ArrayBuffer::Allocator* allocator) { | 124 v8::ArrayBuffer::Allocator* allocator) { |
95 CHECK(allocator); | 125 CHECK(allocator); |
96 V8Initializer::Initialize(mode, v8_extras_mode); | 126 V8Initializer::Initialize(mode, v8_extras_mode); |
97 g_array_buffer_allocator = allocator; | 127 g_array_buffer_allocator = allocator; |
98 } | 128 } |
(...skipping 10 matching lines...) Expand all Loading... | |
109 task_observer_.reset(); | 139 task_observer_.reset(); |
110 } | 140 } |
111 | 141 |
112 void IsolateHolder::EnableIdleTasks( | 142 void IsolateHolder::EnableIdleTasks( |
113 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) { | 143 std::unique_ptr<V8IdleTaskRunner> idle_task_runner) { |
114 DCHECK(isolate_data_.get()); | 144 DCHECK(isolate_data_.get()); |
115 isolate_data_->EnableIdleTasks(std::move(idle_task_runner)); | 145 isolate_data_->EnableIdleTasks(std::move(idle_task_runner)); |
116 } | 146 } |
117 | 147 |
118 } // namespace gin | 148 } // namespace gin |
OLD | NEW |