| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/snapshot/natives.h" | 5 #include "src/snapshot/natives.h" |
| 6 | 6 |
| 7 #include "src/base/logging.h" | 7 #include "src/base/logging.h" |
| 8 #include "src/list.h" | 8 #include "src/list.h" |
| 9 #include "src/list-inl.h" | 9 #include "src/list-inl.h" |
| 10 #include "src/snapshot/snapshot-source-sink.h" | 10 #include "src/snapshot/snapshot-source-sink.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 static StartupData* natives_blob_ = NULL; | 150 static StartupData* natives_blob_ = NULL; |
| 151 | 151 |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Read the Natives blob, as previously set by SetNativesFromFile. | 154 * Read the Natives blob, as previously set by SetNativesFromFile. |
| 155 */ | 155 */ |
| 156 void ReadNatives() { | 156 void ReadNatives() { |
| 157 if (natives_blob_ && NativesHolder<CORE>::empty()) { | 157 if (natives_blob_ && NativesHolder<CORE>::empty()) { |
| 158 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); | 158 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); |
| 159 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); | 159 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 160 NativesHolder<CODE_STUB>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 160 NativesHolder<EXPERIMENTAL>::set( | 161 NativesHolder<EXPERIMENTAL>::set( |
| 161 NativesStore::MakeFromScriptsSource(&bytes)); | 162 NativesStore::MakeFromScriptsSource(&bytes)); |
| 162 NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes)); | 163 NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 163 DCHECK(!bytes.HasMore()); | 164 DCHECK(!bytes.HasMore()); |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 | 168 |
| 168 /** | 169 /** |
| 169 * Set the Natives (library sources) blob, as generated by js2c + the build | 170 * Set the Natives (library sources) blob, as generated by js2c + the build |
| 170 * system. | 171 * system. |
| 171 */ | 172 */ |
| 172 void SetNativesFromFile(StartupData* natives_blob) { | 173 void SetNativesFromFile(StartupData* natives_blob) { |
| 173 DCHECK(!natives_blob_); | 174 DCHECK(!natives_blob_); |
| 174 DCHECK(natives_blob); | 175 DCHECK(natives_blob); |
| 175 DCHECK(natives_blob->data); | 176 DCHECK(natives_blob->data); |
| 176 DCHECK(natives_blob->raw_size > 0); | 177 DCHECK(natives_blob->raw_size > 0); |
| 177 | 178 |
| 178 natives_blob_ = natives_blob; | 179 natives_blob_ = natives_blob; |
| 179 ReadNatives(); | 180 ReadNatives(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 | 183 |
| 183 /** | 184 /** |
| 184 * Release memory allocated by SetNativesFromFile. | 185 * Release memory allocated by SetNativesFromFile. |
| 185 */ | 186 */ |
| 186 void DisposeNatives() { | 187 void DisposeNatives() { |
| 187 NativesHolder<CORE>::Dispose(); | 188 NativesHolder<CORE>::Dispose(); |
| 189 NativesHolder<CODE_STUB>::Dispose(); |
| 188 NativesHolder<EXPERIMENTAL>::Dispose(); | 190 NativesHolder<EXPERIMENTAL>::Dispose(); |
| 189 NativesHolder<EXTRAS>::Dispose(); | 191 NativesHolder<EXTRAS>::Dispose(); |
| 190 } | 192 } |
| 191 | 193 |
| 192 | 194 |
| 193 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. | 195 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. |
| 194 // | 196 // |
| 195 // (The callers expect a purely static interface, since this is how the | 197 // (The callers expect a purely static interface, since this is how the |
| 196 // natives are usually compiled in. Since we implement them based on | 198 // natives are usually compiled in. Since we implement them based on |
| 197 // runtime content, we have to implement this indirection to offer | 199 // runtime content, we have to implement this indirection to offer |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 | 225 |
| 224 template <NativeType type> | 226 template <NativeType type> |
| 225 Vector<const char> NativesCollection<type>::GetScriptsSource() { | 227 Vector<const char> NativesCollection<type>::GetScriptsSource() { |
| 226 return NativesHolder<type>::get()->GetScriptsSource(); | 228 return NativesHolder<type>::get()->GetScriptsSource(); |
| 227 } | 229 } |
| 228 | 230 |
| 229 | 231 |
| 230 // The compiler can't 'see' all uses of the static methods and hence | 232 // The compiler can't 'see' all uses of the static methods and hence |
| 231 // my choice to elide them. This we'll explicitly instantiate these. | 233 // my choice to elide them. This we'll explicitly instantiate these. |
| 232 template class NativesCollection<CORE>; | 234 template class NativesCollection<CORE>; |
| 235 template class NativesCollection<CODE_STUB>; |
| 233 template class NativesCollection<EXPERIMENTAL>; | 236 template class NativesCollection<EXPERIMENTAL>; |
| 234 template class NativesCollection<EXTRAS>; | 237 template class NativesCollection<EXTRAS>; |
| 235 } // namespace internal | 238 } // namespace internal |
| 236 } // namespace v8 | 239 } // namespace v8 |
| OLD | NEW |