| 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { | 338 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { |
| 339 i::Isolate* internal_isolate = new i::Isolate(true); | 339 i::Isolate* internal_isolate = new i::Isolate(true); |
| 340 ArrayBufferAllocator allocator; | 340 ArrayBufferAllocator allocator; |
| 341 internal_isolate->set_array_buffer_allocator(&allocator); | 341 internal_isolate->set_array_buffer_allocator(&allocator); |
| 342 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | 342 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
| 343 StartupData result = {NULL, 0}; | 343 StartupData result = {NULL, 0}; |
| 344 { | 344 { |
| 345 base::ElapsedTimer timer; | 345 base::ElapsedTimer timer; |
| 346 timer.Start(); | 346 timer.Start(); |
| 347 Isolate::Scope isolate_scope(isolate); | 347 Isolate::Scope isolate_scope(isolate); |
| 348 internal_isolate->set_creating_default_snapshot(true); |
| 348 internal_isolate->Init(NULL); | 349 internal_isolate->Init(NULL); |
| 349 Persistent<Context> context; | 350 Persistent<Context> context; |
| 350 i::Snapshot::Metadata metadata; | 351 i::Snapshot::Metadata metadata; |
| 351 { | 352 { |
| 352 HandleScope handle_scope(isolate); | 353 HandleScope handle_scope(isolate); |
| 353 Handle<Context> new_context = Context::New(isolate); | 354 Handle<Context> new_context = Context::New(isolate); |
| 355 internal_isolate->set_creating_default_snapshot(false); |
| 354 context.Reset(isolate, new_context); | 356 context.Reset(isolate, new_context); |
| 355 if (custom_source != NULL) { | 357 if (custom_source != NULL) { |
| 356 metadata.set_embeds_script(true); | 358 metadata.set_embeds_script(true); |
| 357 Context::Scope context_scope(new_context); | 359 Context::Scope context_scope(new_context); |
| 358 if (!RunExtraCode(isolate, custom_source)) context.Reset(); | 360 if (!RunExtraCode(isolate, custom_source)) context.Reset(); |
| 359 } | 361 } |
| 360 } | 362 } |
| 361 if (!context.IsEmpty()) { | 363 if (!context.IsEmpty()) { |
| 362 // Make sure all builtin scripts are cached. | 364 // Make sure all builtin scripts are cached. |
| 363 { | 365 { |
| 364 HandleScope scope(isolate); | 366 HandleScope scope(isolate); |
| 365 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | 367 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { |
| 366 internal_isolate->bootstrapper()->SourceLookup<i::Natives>(i); | 368 internal_isolate->bootstrapper()->SourceLookup<i::Natives>(i); |
| 367 } | 369 } |
| 368 } | 370 } |
| 369 // If we don't do this then we end up with a stray root pointing at the | 371 // If we don't do this then we end up with a stray root pointing at the |
| 370 // context even after we have disposed of the context. | 372 // context even after we have disposed of the context. |
| 371 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); | 373 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); |
| 372 i::Object* raw_context = *v8::Utils::OpenPersistent(context); | 374 i::Object* raw_context = *v8::Utils::OpenPersistent(context); |
| 373 context.Reset(); | 375 context.Reset(); |
| 374 | 376 |
| 375 i::SnapshotByteSink snapshot_sink; | 377 i::SnapshotByteSink snapshot_sink; |
| 376 i::StartupSerializer ser(internal_isolate, &snapshot_sink); | 378 i::StartupSerializer ser(internal_isolate, &snapshot_sink); |
| 377 ser.SerializeStrongReferences(); | 379 ser.SerializeStrongReferences(); |
| 378 | 380 |
| 379 i::SnapshotByteSink context_sink; | 381 i::SnapshotByteSink context_sink; |
| 380 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); | 382 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); |
| 381 context_ser.Serialize(&raw_context); | 383 context_ser.Serialize(&raw_context); |
| 382 ser.SerializeWeakReferences(); | 384 ser.SerializeWeakReferencesAndDeferred(); |
| 383 | 385 |
| 384 result = i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata); | 386 result = i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata); |
| 385 } | 387 } |
| 386 if (i::FLAG_profile_deserialization) { | 388 if (i::FLAG_profile_deserialization) { |
| 387 i::PrintF("Creating snapshot took %0.3f ms\n", | 389 i::PrintF("Creating snapshot took %0.3f ms\n", |
| 388 timer.Elapsed().InMillisecondsF()); | 390 timer.Elapsed().InMillisecondsF()); |
| 389 } | 391 } |
| 390 timer.Stop(); | 392 timer.Stop(); |
| 391 } | 393 } |
| 392 isolate->Dispose(); | 394 isolate->Dispose(); |
| (...skipping 7639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8032 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8034 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8033 Address callback_address = | 8035 Address callback_address = |
| 8034 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8036 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8035 VMState<EXTERNAL> state(isolate); | 8037 VMState<EXTERNAL> state(isolate); |
| 8036 ExternalCallbackScope call_scope(isolate, callback_address); | 8038 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8037 callback(info); | 8039 callback(info); |
| 8038 } | 8040 } |
| 8039 | 8041 |
| 8040 | 8042 |
| 8041 } } // namespace v8::internal | 8043 } } // namespace v8::internal |
| OLD | NEW |