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 |
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 |
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 |
| 119 //static |
| 120 const char* IsolateHolder::GetV8NativesData() { |
| 121 if (!g_mapped_natives) |
| 122 return NULL; |
| 123 return reinterpret_cast<const char*>(g_mapped_natives->data()); |
| 124 } |
| 125 |
| 126 //static |
| 127 const char* IsolateHolder::GetV8SnapshotData() { |
| 128 if (!g_mapped_snapshot) |
| 129 return NULL; |
| 130 return reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
| 131 } |
| 132 |
| 133 //static |
| 134 int IsolateHolder::GetV8NativesSize() { |
| 135 if (!g_mapped_natives) |
| 136 return 0; |
| 137 return g_mapped_natives->length(); |
| 138 } |
| 139 |
| 140 //static |
| 141 int IsolateHolder::GetV8SnapshotSize() { |
| 142 if (!g_mapped_snapshot) |
| 143 return 0; |
| 144 return g_mapped_snapshot->length(); |
| 145 } |
| 146 #endif // OS_ANDROID |
| 147 |
99 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 148 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
100 | 149 |
101 IsolateHolder::IsolateHolder() { | 150 IsolateHolder::IsolateHolder() { |
102 CHECK(g_array_buffer_allocator) | 151 CHECK(g_array_buffer_allocator) |
103 << "You need to invoke gin::IsolateHolder::Initialize first"; | 152 << "You need to invoke gin::IsolateHolder::Initialize first"; |
104 v8::Isolate::CreateParams params; | 153 v8::Isolate::CreateParams params; |
105 params.entry_hook = DebugImpl::GetFunctionEntryHook(); | 154 params.entry_hook = DebugImpl::GetFunctionEntryHook(); |
106 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); | 155 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); |
107 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), | 156 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), |
108 base::SysInfo::AmountOfVirtualMemory(), | 157 base::SysInfo::AmountOfVirtualMemory(), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); | 227 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); |
179 } | 228 } |
180 | 229 |
181 void IsolateHolder::RemoveRunMicrotasksObserver() { | 230 void IsolateHolder::RemoveRunMicrotasksObserver() { |
182 DCHECK(task_observer_.get()); | 231 DCHECK(task_observer_.get()); |
183 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); | 232 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); |
184 task_observer_.reset(); | 233 task_observer_.reset(); |
185 } | 234 } |
186 | 235 |
187 } // namespace gin | 236 } // namespace gin |
OLD | NEW |