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 <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 37 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
38 base::MemoryMappedFile* g_mapped_natives = NULL; | 38 base::MemoryMappedFile* g_mapped_natives = NULL; |
39 base::MemoryMappedFile* g_mapped_snapshot = NULL; | 39 base::MemoryMappedFile* g_mapped_snapshot = NULL; |
40 | 40 |
41 bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, | 41 bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, |
42 int natives_fd = -1, int snapshot_fd = -1) { | 42 int natives_fd = -1, int snapshot_fd = -1) { |
43 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 43 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
44 | 44 |
45 g_mapped_natives = new base::MemoryMappedFile; | 45 g_mapped_natives = new base::MemoryMappedFile; |
46 if (!g_mapped_natives->IsValid()) { | 46 if (!g_mapped_natives->IsValid()) { |
47 #ifdef OS_ANDROID | |
rmcilroy
2014/11/07 23:46:00
Why does MapV8Files need changing here? Doesn't th
baixo1
2014/11/10 15:59:48
Yes, it does work. I undid the changes.
| |
47 if (natives_fd == -1 | 48 if (natives_fd == -1 |
48 ? !g_mapped_natives->Initialize(base::File(*natives_path, flags)) | 49 ? !g_mapped_natives->Initialize(base::File(*natives_path, flags)) |
49 : !g_mapped_natives->Initialize(base::File(natives_fd))) { | 50 : !g_mapped_natives->Initialize(base::File(natives_fd)) |
51 #else | |
52 if (!g_mapped_natives->Initialize(base::File(*natives_path, flags)) | |
53 #endif | |
54 ) { | |
50 delete g_mapped_natives; | 55 delete g_mapped_natives; |
51 g_mapped_natives = NULL; | 56 g_mapped_natives = NULL; |
52 LOG(FATAL) << "Couldn't mmap v8 natives data file"; | 57 LOG(FATAL) << "Couldn't mmap v8 natives data file"; |
53 return false; | 58 return false; |
54 } | 59 } |
55 } | 60 } |
56 | 61 |
57 g_mapped_snapshot = new base::MemoryMappedFile; | 62 g_mapped_snapshot = new base::MemoryMappedFile; |
58 if (!g_mapped_snapshot->IsValid()) { | 63 if (!g_mapped_snapshot->IsValid()) { |
64 #ifdef OS_ANDROID | |
59 if (snapshot_fd == -1 | 65 if (snapshot_fd == -1 |
60 ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags)) | 66 ? !g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags)) |
61 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd))) { | 67 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd)) |
68 #else | |
69 if (!g_mapped_snapshot->Initialize(base::File(*snapshot_path, flags)) | |
70 #endif | |
71 ) { | |
62 delete g_mapped_snapshot; | 72 delete g_mapped_snapshot; |
63 g_mapped_snapshot = NULL; | 73 g_mapped_snapshot = NULL; |
64 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; | 74 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; |
65 return false; | 75 return false; |
66 } | 76 } |
67 } | 77 } |
68 | 78 |
69 return true; | 79 return true; |
70 } | 80 } |
71 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 81 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
72 | 82 |
73 } // namespace | 83 } // namespace |
74 | 84 |
75 | 85 |
76 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 86 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
77 // static | 87 // static |
78 bool IsolateHolder::LoadV8Snapshot() { | 88 bool IsolateHolder::LoadV8Snapshot() { |
79 if (g_mapped_natives && g_mapped_snapshot) | 89 if (g_mapped_natives && g_mapped_snapshot) |
80 return true; | 90 return true; |
81 | 91 |
82 base::FilePath data_path; | 92 base::FilePath data_path; |
83 PathService::Get(base::DIR_ANDROID_APP_DATA, &data_path); | 93 PathService::Get( |
94 #if defined(OS_ANDROID) | |
95 base::DIR_ANDROID_APP_DATA, | |
96 #elif defined(OS_POSIX) | |
97 base::DIR_EXE, | |
98 #endif | |
99 &data_path); | |
84 DCHECK(!data_path.empty()); | 100 DCHECK(!data_path.empty()); |
85 | 101 |
86 base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin"); | 102 base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin"); |
87 base::FilePath snapshot_path = data_path.AppendASCII("snapshot_blob.bin"); | 103 base::FilePath snapshot_path = data_path.AppendASCII("snapshot_blob.bin"); |
88 | 104 |
89 return MapV8Files(&natives_path, &snapshot_path); | 105 return MapV8Files(&natives_path, &snapshot_path); |
90 } | 106 } |
91 | 107 |
108 #ifdef OS_ANDROID | |
rmcilroy
2014/11/07 23:46:01
Why ifdef OS_ANDROID here? Ideally we should keep
baixo1
2014/11/10 15:59:48
Done.
| |
92 //static | 109 //static |
93 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { | 110 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { |
94 if (g_mapped_natives && g_mapped_snapshot) | 111 if (g_mapped_natives && g_mapped_snapshot) |
95 return true; | 112 return true; |
96 | 113 |
97 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); | 114 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); |
98 } | 115 } |
116 #endif // OS_ANDROID | |
117 | |
118 #ifndef OS_ANDROID | |
rmcilroy
2014/11/07 23:46:01
why ifndef OS_ANDROID here? I know we aren't call
baixo1
2014/11/10 15:59:48
Done.
| |
119 //static | |
120 void IsolateHolder::GetV8ExternalSnapshotData(const char** natives_data_out, | |
121 int* natives_size_out, | |
122 const char** snapshot_data_out, | |
123 int* snapshot_size_out) { | |
124 if (!g_mapped_natives || !g_mapped_snapshot) { | |
125 *natives_data_out = *snapshot_data_out = NULL; | |
126 *natives_size_out = *snapshot_size_out = 0; | |
127 return; | |
128 } | |
129 *natives_data_out = reinterpret_cast<const char*>(g_mapped_natives->data()); | |
130 *snapshot_data_out = reinterpret_cast<const char*>(g_mapped_snapshot->data()); | |
131 *natives_size_out = g_mapped_natives->length(); | |
132 *snapshot_size_out = g_mapped_snapshot->length(); | |
133 } | |
134 #endif // OS_ANDROID | |
135 | |
99 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 136 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
100 | 137 |
101 IsolateHolder::IsolateHolder() { | 138 IsolateHolder::IsolateHolder() { |
102 CHECK(g_array_buffer_allocator) | 139 CHECK(g_array_buffer_allocator) |
103 << "You need to invoke gin::IsolateHolder::Initialize first"; | 140 << "You need to invoke gin::IsolateHolder::Initialize first"; |
104 v8::Isolate::CreateParams params; | 141 v8::Isolate::CreateParams params; |
105 params.entry_hook = DebugImpl::GetFunctionEntryHook(); | 142 params.entry_hook = DebugImpl::GetFunctionEntryHook(); |
106 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); | 143 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); |
107 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), | 144 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), |
108 base::SysInfo::AmountOfVirtualMemory(), | 145 base::SysInfo::AmountOfVirtualMemory(), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); | 215 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); |
179 } | 216 } |
180 | 217 |
181 void IsolateHolder::RemoveRunMicrotasksObserver() { | 218 void IsolateHolder::RemoveRunMicrotasksObserver() { |
182 DCHECK(task_observer_.get()); | 219 DCHECK(task_observer_.get()); |
183 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); | 220 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); |
184 task_observer_.reset(); | 221 task_observer_.reset(); |
185 } | 222 } |
186 | 223 |
187 } // namespace gin | 224 } // namespace gin |
OLD | NEW |