OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 void V8::SetNativesDataBlob(StartupData* natives_blob) { | 199 void V8::SetNativesDataBlob(StartupData* natives_blob) { |
200 i::V8::SetNativesBlob(natives_blob); | 200 i::V8::SetNativesBlob(natives_blob); |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { | 204 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { |
205 i::V8::SetSnapshotBlob(snapshot_blob); | 205 i::V8::SetSnapshotBlob(snapshot_blob); |
206 } | 206 } |
207 | 207 |
208 | 208 |
| 209 StartupData V8::CreateSnapshotDataBlob() { |
| 210 Isolate::CreateParams params; |
| 211 params.enable_serializer = true; |
| 212 Isolate* isolate = v8::Isolate::New(params); |
| 213 StartupData result = {NULL, 0}; |
| 214 { |
| 215 Isolate::Scope isolate_scope(isolate); |
| 216 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 217 Persistent<Context> context; |
| 218 { |
| 219 HandleScope handle_scope(isolate); |
| 220 context.Reset(isolate, Context::New(isolate)); |
| 221 } |
| 222 if (!context.IsEmpty()) { |
| 223 // Make sure all builtin scripts are cached. |
| 224 { |
| 225 HandleScope scope(isolate); |
| 226 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { |
| 227 internal_isolate->bootstrapper()->NativesSourceLookup(i); |
| 228 } |
| 229 } |
| 230 // If we don't do this then we end up with a stray root pointing at the |
| 231 // context even after we have disposed of the context. |
| 232 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); |
| 233 i::Object* raw_context = *v8::Utils::OpenPersistent(context); |
| 234 context.Reset(); |
| 235 |
| 236 i::SnapshotByteSink snapshot_sink; |
| 237 i::StartupSerializer ser(internal_isolate, &snapshot_sink); |
| 238 ser.SerializeStrongReferences(); |
| 239 |
| 240 i::SnapshotByteSink context_sink; |
| 241 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); |
| 242 context_ser.Serialize(&raw_context); |
| 243 ser.SerializeWeakReferences(); |
| 244 |
| 245 i::SnapshotData sd(snapshot_sink, ser); |
| 246 i::SnapshotData csd(context_sink, context_ser); |
| 247 |
| 248 result = i::Snapshot::CreateSnapshotBlob(sd.RawData(), csd.RawData()); |
| 249 } |
| 250 } |
| 251 isolate->Dispose(); |
| 252 return result; |
| 253 } |
| 254 |
| 255 |
209 void V8::SetFlagsFromString(const char* str, int length) { | 256 void V8::SetFlagsFromString(const char* str, int length) { |
210 i::FlagList::SetFlagsFromString(str, length); | 257 i::FlagList::SetFlagsFromString(str, length); |
211 } | 258 } |
212 | 259 |
213 | 260 |
214 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { | 261 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
215 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); | 262 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
216 } | 263 } |
217 | 264 |
218 | 265 |
(...skipping 7476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7695 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7742 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7696 Address callback_address = | 7743 Address callback_address = |
7697 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7744 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7698 VMState<EXTERNAL> state(isolate); | 7745 VMState<EXTERNAL> state(isolate); |
7699 ExternalCallbackScope call_scope(isolate, callback_address); | 7746 ExternalCallbackScope call_scope(isolate, callback_address); |
7700 callback(info); | 7747 callback(info); |
7701 } | 7748 } |
7702 | 7749 |
7703 | 7750 |
7704 } } // namespace v8::internal | 7751 } } // namespace v8::internal |
OLD | NEW |