| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 544 } |
| 545 | 545 |
| 546 StartupData SnapshotCreator::CreateBlob( | 546 StartupData SnapshotCreator::CreateBlob( |
| 547 SnapshotCreator::FunctionCodeHandling function_code_handling, | 547 SnapshotCreator::FunctionCodeHandling function_code_handling, |
| 548 SerializeInternalFieldsCallback callback) { | 548 SerializeInternalFieldsCallback callback) { |
| 549 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); | 549 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); |
| 550 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_); | 550 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_); |
| 551 DCHECK(!data->created_); | 551 DCHECK(!data->created_); |
| 552 DCHECK(!data->default_context_.IsEmpty()); | 552 DCHECK(!data->default_context_.IsEmpty()); |
| 553 | 553 |
| 554 int num_additional_contexts = static_cast<int>(data->contexts_.Size()); |
| 555 |
| 554 { | 556 { |
| 555 int num_templates = static_cast<int>(data->templates_.Size()); | 557 int num_templates = static_cast<int>(data->templates_.Size()); |
| 556 i::HandleScope scope(isolate); | 558 i::HandleScope scope(isolate); |
| 557 i::Handle<i::FixedArray> templates = | 559 i::Handle<i::FixedArray> templates = |
| 558 isolate->factory()->NewFixedArray(num_templates, i::TENURED); | 560 isolate->factory()->NewFixedArray(num_templates, i::TENURED); |
| 559 for (int i = 0; i < num_templates; i++) { | 561 for (int i = 0; i < num_templates; i++) { |
| 560 templates->set(i, *v8::Utils::OpenHandle(*data->templates_.Get(i))); | 562 templates->set(i, *v8::Utils::OpenHandle(*data->templates_.Get(i))); |
| 561 } | 563 } |
| 562 isolate->heap()->SetSerializedTemplates(*templates); | 564 isolate->heap()->SetSerializedTemplates(*templates); |
| 563 data->templates_.Clear(); | 565 data->templates_.Clear(); |
| 566 |
| 567 // We need to store the global proxy size upfront in case we need the |
| 568 // bootstrapper to create a global proxy before we deserialize the context. |
| 569 i::Handle<i::FixedArray> global_proxy_sizes = |
| 570 isolate->factory()->NewFixedArray(num_additional_contexts, i::TENURED); |
| 571 for (int i = 0; i < num_additional_contexts; i++) { |
| 572 i::Handle<i::Context> context = |
| 573 v8::Utils::OpenHandle(*data->contexts_.Get(i)); |
| 574 global_proxy_sizes->set(i, |
| 575 i::Smi::FromInt(context->global_proxy()->Size())); |
| 576 } |
| 577 isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes); |
| 564 } | 578 } |
| 565 | 579 |
| 566 // If we don't do this then we end up with a stray root pointing at the | 580 // If we don't do this then we end up with a stray root pointing at the |
| 567 // context even after we have disposed of the context. | 581 // context even after we have disposed of the context. |
| 568 isolate->heap()->CollectAllAvailableGarbage( | 582 isolate->heap()->CollectAllAvailableGarbage( |
| 569 i::GarbageCollectionReason::kSnapshotCreator); | 583 i::GarbageCollectionReason::kSnapshotCreator); |
| 570 isolate->heap()->CompactWeakFixedArrays(); | 584 isolate->heap()->CompactWeakFixedArrays(); |
| 571 | 585 |
| 572 i::DisallowHeapAllocation no_gc_from_here_on; | 586 i::DisallowHeapAllocation no_gc_from_here_on; |
| 573 | 587 |
| 574 int num_additional_contexts = static_cast<int>(data->contexts_.Size()); | |
| 575 i::List<i::Object*> contexts(num_additional_contexts); | 588 i::List<i::Object*> contexts(num_additional_contexts); |
| 576 i::Object* default_context; | 589 i::Object* default_context; |
| 577 { | 590 { |
| 578 i::HandleScope scope(isolate); | 591 i::HandleScope scope(isolate); |
| 579 default_context = | 592 default_context = |
| 580 *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_)); | 593 *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_)); |
| 581 data->default_context_.Reset(); | 594 data->default_context_.Reset(); |
| 582 for (int i = 0; i < num_additional_contexts; i++) { | 595 for (int i = 0; i < num_additional_contexts; i++) { |
| 583 i::Handle<i::Context> context = | 596 i::Handle<i::Context> context = |
| 584 v8::Utils::OpenHandle(*data->contexts_.Get(i)); | 597 v8::Utils::OpenHandle(*data->contexts_.Get(i)); |
| (...skipping 9311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9896 Address callback_address = | 9909 Address callback_address = |
| 9897 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9910 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9898 VMState<EXTERNAL> state(isolate); | 9911 VMState<EXTERNAL> state(isolate); |
| 9899 ExternalCallbackScope call_scope(isolate, callback_address); | 9912 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9900 callback(info); | 9913 callback(info); |
| 9901 } | 9914 } |
| 9902 | 9915 |
| 9903 | 9916 |
| 9904 } // namespace internal | 9917 } // namespace internal |
| 9905 } // namespace v8 | 9918 } // namespace v8 |
| OLD | NEW |