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/snapshot/serialize.h" | 5 #include "src/snapshot/serialize.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 deserializing_user_code_ = true; | 626 deserializing_user_code_ = true; |
627 HandleScope scope(isolate); | 627 HandleScope scope(isolate); |
628 Handle<SharedFunctionInfo> result; | 628 Handle<SharedFunctionInfo> result; |
629 { | 629 { |
630 DisallowHeapAllocation no_gc; | 630 DisallowHeapAllocation no_gc; |
631 Object* root; | 631 Object* root; |
632 VisitPointer(&root); | 632 VisitPointer(&root); |
633 DeserializeDeferredObjects(); | 633 DeserializeDeferredObjects(); |
634 result = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root)); | 634 result = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root)); |
635 } | 635 } |
636 CommitNewInternalizedStrings(isolate); | 636 CommitPostProcessedObjects(isolate); |
637 return scope.CloseAndEscape(result); | 637 return scope.CloseAndEscape(result); |
638 } | 638 } |
639 } | 639 } |
640 | 640 |
641 | 641 |
642 Deserializer::~Deserializer() { | 642 Deserializer::~Deserializer() { |
643 // TODO(svenpanne) Re-enable this assertion when v8 initialization is fixed. | 643 // TODO(svenpanne) Re-enable this assertion when v8 initialization is fixed. |
644 // DCHECK(source_.AtEOF()); | 644 // DCHECK(source_.AtEOF()); |
645 attached_objects_.Dispose(); | 645 attached_objects_.Dispose(); |
646 } | 646 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 String* canonical = StringTable::LookupKeyIfExists(isolate_, &key); | 719 String* canonical = StringTable::LookupKeyIfExists(isolate_, &key); |
720 if (canonical == NULL) { | 720 if (canonical == NULL) { |
721 new_internalized_strings_.Add(handle(string)); | 721 new_internalized_strings_.Add(handle(string)); |
722 return string; | 722 return string; |
723 } else { | 723 } else { |
724 string->SetForwardedInternalizedString(canonical); | 724 string->SetForwardedInternalizedString(canonical); |
725 return canonical; | 725 return canonical; |
726 } | 726 } |
727 } | 727 } |
728 } else if (obj->IsScript()) { | 728 } else if (obj->IsScript()) { |
729 // Assign a new script id to avoid collision. | 729 new_scripts_.Add(handle(Script::cast(obj))); |
730 Script::cast(obj)->set_id(isolate_->heap()->NextScriptId()); | |
731 } else { | 730 } else { |
732 DCHECK(CanBeDeferred(obj)); | 731 DCHECK(CanBeDeferred(obj)); |
733 } | 732 } |
734 } | 733 } |
735 if (obj->IsAllocationSite()) { | 734 if (obj->IsAllocationSite()) { |
736 DCHECK(obj->IsAllocationSite()); | 735 DCHECK(obj->IsAllocationSite()); |
737 // Allocation sites are present in the snapshot, and must be linked into | 736 // Allocation sites are present in the snapshot, and must be linked into |
738 // a list at deserialization time. | 737 // a list at deserialization time. |
739 AllocationSite* site = AllocationSite::cast(obj); | 738 AllocationSite* site = AllocationSite::cast(obj); |
740 // TODO(mvstanton): consider treating the heap()->allocation_sites_list() | 739 // TODO(mvstanton): consider treating the heap()->allocation_sites_list() |
(...skipping 12 matching lines...) Expand all Loading... |
753 if (deserializing_user_code() || space == LO_SPACE) { | 752 if (deserializing_user_code() || space == LO_SPACE) { |
754 new_code_objects_.Add(Code::cast(obj)); | 753 new_code_objects_.Add(Code::cast(obj)); |
755 } | 754 } |
756 } | 755 } |
757 // Check alignment. | 756 // Check alignment. |
758 DCHECK_EQ(0, Heap::GetFillToAlign(obj->address(), obj->RequiredAlignment())); | 757 DCHECK_EQ(0, Heap::GetFillToAlign(obj->address(), obj->RequiredAlignment())); |
759 return obj; | 758 return obj; |
760 } | 759 } |
761 | 760 |
762 | 761 |
763 void Deserializer::CommitNewInternalizedStrings(Isolate* isolate) { | 762 void Deserializer::CommitPostProcessedObjects(Isolate* isolate) { |
764 StringTable::EnsureCapacityForDeserialization( | 763 StringTable::EnsureCapacityForDeserialization( |
765 isolate, new_internalized_strings_.length()); | 764 isolate, new_internalized_strings_.length()); |
766 for (Handle<String> string : new_internalized_strings_) { | 765 for (Handle<String> string : new_internalized_strings_) { |
767 StringTableInsertionKey key(*string); | 766 StringTableInsertionKey key(*string); |
768 DCHECK_NULL(StringTable::LookupKeyIfExists(isolate, &key)); | 767 DCHECK_NULL(StringTable::LookupKeyIfExists(isolate, &key)); |
769 StringTable::LookupKey(isolate, &key); | 768 StringTable::LookupKey(isolate, &key); |
770 } | 769 } |
| 770 |
| 771 Heap* heap = isolate->heap(); |
| 772 Factory* factory = isolate->factory(); |
| 773 for (Handle<Script> script : new_scripts_) { |
| 774 // Assign a new script id to avoid collision. |
| 775 script->set_id(isolate_->heap()->NextScriptId()); |
| 776 // Add script to list. |
| 777 heap->set_script_list(*WeakFixedArray::Add(factory->script_list(), script)); |
| 778 } |
771 } | 779 } |
772 | 780 |
773 | 781 |
774 HeapObject* Deserializer::GetBackReferencedObject(int space) { | 782 HeapObject* Deserializer::GetBackReferencedObject(int space) { |
775 HeapObject* obj; | 783 HeapObject* obj; |
776 BackReference back_reference(source_.GetInt()); | 784 BackReference back_reference(source_.GetInt()); |
777 if (space == LO_SPACE) { | 785 if (space == LO_SPACE) { |
778 CHECK(back_reference.chunk_index() == 0); | 786 CHECK(back_reference.chunk_index() == 0); |
779 uint32_t index = back_reference.large_object_index(); | 787 uint32_t index = back_reference.large_object_index(); |
780 obj = deserialized_large_objects_[index]; | 788 obj = deserialized_large_objects_[index]; |
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2781 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2774 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2782 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2775 if (r == CHECK_SUCCESS) return scd; | 2783 if (r == CHECK_SUCCESS) return scd; |
2776 cached_data->Reject(); | 2784 cached_data->Reject(); |
2777 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2785 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2778 delete scd; | 2786 delete scd; |
2779 return NULL; | 2787 return NULL; |
2780 } | 2788 } |
2781 } // namespace internal | 2789 } // namespace internal |
2782 } // namespace v8 | 2790 } // namespace v8 |
OLD | NEW |