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 #ifndef V8_SERIALIZE_H_ | 5 #ifndef V8_SERIALIZE_H_ |
6 #define V8_SERIALIZE_H_ | 6 #define V8_SERIALIZE_H_ |
7 | 7 |
8 #include "src/hashmap.h" | 8 #include "src/hashmap.h" |
9 #include "src/heap-profiler.h" | 9 #include "src/heap-profiler.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ~Serializer(); | 610 ~Serializer(); |
611 void VisitPointers(Object** start, Object** end) OVERRIDE; | 611 void VisitPointers(Object** start, Object** end) OVERRIDE; |
612 | 612 |
613 void EncodeReservations(List<SerializedData::Reservation>* out) const; | 613 void EncodeReservations(List<SerializedData::Reservation>* out) const; |
614 | 614 |
615 Isolate* isolate() const { return isolate_; } | 615 Isolate* isolate() const { return isolate_; } |
616 | 616 |
617 BackReferenceMap* back_reference_map() { return &back_reference_map_; } | 617 BackReferenceMap* back_reference_map() { return &back_reference_map_; } |
618 RootIndexMap* root_index_map() { return &root_index_map_; } | 618 RootIndexMap* root_index_map() { return &root_index_map_; } |
619 | 619 |
| 620 #ifdef OBJECT_PRINT |
| 621 void CountInstanceType(HeapObject* obj); |
| 622 #endif // OBJECT_PRINT |
| 623 |
620 protected: | 624 protected: |
621 class ObjectSerializer : public ObjectVisitor { | 625 class ObjectSerializer : public ObjectVisitor { |
622 public: | 626 public: |
623 ObjectSerializer(Serializer* serializer, Object* o, SnapshotByteSink* sink, | 627 ObjectSerializer(Serializer* serializer, Object* o, SnapshotByteSink* sink, |
624 HowToCode how_to_code, WhereToPoint where_to_point) | 628 HowToCode how_to_code, WhereToPoint where_to_point) |
625 : serializer_(serializer), | 629 : serializer_(serializer), |
626 object_(HeapObject::cast(o)), | 630 object_(HeapObject::cast(o)), |
627 sink_(sink), | 631 sink_(sink), |
628 reference_representation_(how_to_code + where_to_point), | 632 reference_representation_(how_to_code + where_to_point), |
629 bytes_processed_so_far_(0), | 633 bytes_processed_so_far_(0), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 Code* CopyCode(Code* code); | 715 Code* CopyCode(Code* code); |
712 | 716 |
713 inline uint32_t max_chunk_size(int space) const { | 717 inline uint32_t max_chunk_size(int space) const { |
714 DCHECK_LE(0, space); | 718 DCHECK_LE(0, space); |
715 DCHECK_LT(space, kNumberOfSpaces); | 719 DCHECK_LT(space, kNumberOfSpaces); |
716 return max_chunk_size_[space]; | 720 return max_chunk_size_[space]; |
717 } | 721 } |
718 | 722 |
719 SnapshotByteSink* sink() const { return sink_; } | 723 SnapshotByteSink* sink() const { return sink_; } |
720 | 724 |
| 725 void OutputStatistics(const char* name); |
| 726 |
721 Isolate* isolate_; | 727 Isolate* isolate_; |
722 | 728 |
723 SnapshotByteSink* sink_; | 729 SnapshotByteSink* sink_; |
724 ExternalReferenceEncoder external_reference_encoder_; | 730 ExternalReferenceEncoder external_reference_encoder_; |
725 | 731 |
726 BackReferenceMap back_reference_map_; | 732 BackReferenceMap back_reference_map_; |
727 RootIndexMap root_index_map_; | 733 RootIndexMap root_index_map_; |
728 | 734 |
729 friend class Deserializer; | 735 friend class Deserializer; |
730 friend class ObjectSerializer; | 736 friend class ObjectSerializer; |
731 friend class SnapshotData; | 737 friend class SnapshotData; |
732 | 738 |
733 private: | 739 private: |
734 CodeAddressMap* code_address_map_; | 740 CodeAddressMap* code_address_map_; |
735 // Objects from the same space are put into chunks for bulk-allocation | 741 // Objects from the same space are put into chunks for bulk-allocation |
736 // when deserializing. We have to make sure that each chunk fits into a | 742 // when deserializing. We have to make sure that each chunk fits into a |
737 // page. So we track the chunk size in pending_chunk_ of a space, but | 743 // page. So we track the chunk size in pending_chunk_ of a space, but |
738 // when it exceeds a page, we complete the current chunk and start a new one. | 744 // when it exceeds a page, we complete the current chunk and start a new one. |
739 uint32_t pending_chunk_[kNumberOfPreallocatedSpaces]; | 745 uint32_t pending_chunk_[kNumberOfPreallocatedSpaces]; |
740 List<uint32_t> completed_chunks_[kNumberOfPreallocatedSpaces]; | 746 List<uint32_t> completed_chunks_[kNumberOfPreallocatedSpaces]; |
741 uint32_t max_chunk_size_[kNumberOfPreallocatedSpaces]; | 747 uint32_t max_chunk_size_[kNumberOfPreallocatedSpaces]; |
742 | 748 |
743 // We map serialized large objects to indexes for back-referencing. | 749 // We map serialized large objects to indexes for back-referencing. |
744 uint32_t large_objects_total_size_; | 750 uint32_t large_objects_total_size_; |
745 uint32_t seen_large_objects_index_; | 751 uint32_t seen_large_objects_index_; |
746 | 752 |
747 List<byte> code_buffer_; | 753 List<byte> code_buffer_; |
748 | 754 |
| 755 #ifdef OBJECT_PRINT |
| 756 static const int kInstanceTypes = 256; |
| 757 int* instance_type_count_; |
| 758 size_t* instance_type_size_; |
| 759 #endif // OBJECT_PRINT |
| 760 |
749 DISALLOW_COPY_AND_ASSIGN(Serializer); | 761 DISALLOW_COPY_AND_ASSIGN(Serializer); |
750 }; | 762 }; |
751 | 763 |
752 | 764 |
753 class PartialSerializer : public Serializer { | 765 class PartialSerializer : public Serializer { |
754 public: | 766 public: |
755 PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer, | 767 PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer, |
756 SnapshotByteSink* sink) | 768 SnapshotByteSink* sink) |
757 : Serializer(isolate, sink), | 769 : Serializer(isolate, sink), |
758 startup_serializer_(startup_snapshot_serializer), | 770 startup_serializer_(startup_snapshot_serializer), |
759 outdated_contexts_(0), | 771 outdated_contexts_(0), |
760 global_object_(NULL) { | 772 global_object_(NULL) { |
761 InitializeCodeAddressMap(); | 773 InitializeCodeAddressMap(); |
762 } | 774 } |
763 | 775 |
| 776 ~PartialSerializer() { OutputStatistics("PartialSerializer"); } |
| 777 |
764 // Serialize the objects reachable from a single object pointer. | 778 // Serialize the objects reachable from a single object pointer. |
765 void Serialize(Object** o); | 779 void Serialize(Object** o); |
766 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 780 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
767 WhereToPoint where_to_point, int skip) OVERRIDE; | 781 WhereToPoint where_to_point, int skip) OVERRIDE; |
768 | 782 |
769 private: | 783 private: |
770 int PartialSnapshotCacheIndex(HeapObject* o); | 784 int PartialSnapshotCacheIndex(HeapObject* o); |
771 bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 785 bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
772 // Scripts should be referred only through shared function infos. We can't | 786 // Scripts should be referred only through shared function infos. We can't |
773 // allow them to be part of the partial snapshot because they contain a | 787 // allow them to be part of the partial snapshot because they contain a |
(...skipping 22 matching lines...) Expand all Loading... |
796 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) | 810 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) |
797 : Serializer(isolate, sink), root_index_wave_front_(0) { | 811 : Serializer(isolate, sink), root_index_wave_front_(0) { |
798 // Clear the cache of objects used by the partial snapshot. After the | 812 // Clear the cache of objects used by the partial snapshot. After the |
799 // strong roots have been serialized we can create a partial snapshot | 813 // strong roots have been serialized we can create a partial snapshot |
800 // which will repopulate the cache with objects needed by that partial | 814 // which will repopulate the cache with objects needed by that partial |
801 // snapshot. | 815 // snapshot. |
802 isolate->partial_snapshot_cache()->Clear(); | 816 isolate->partial_snapshot_cache()->Clear(); |
803 InitializeCodeAddressMap(); | 817 InitializeCodeAddressMap(); |
804 } | 818 } |
805 | 819 |
| 820 ~StartupSerializer() { OutputStatistics("StartupSerializer"); } |
| 821 |
806 // The StartupSerializer has to serialize the root array, which is slightly | 822 // The StartupSerializer has to serialize the root array, which is slightly |
807 // different. | 823 // different. |
808 void VisitPointers(Object** start, Object** end) OVERRIDE; | 824 void VisitPointers(Object** start, Object** end) OVERRIDE; |
809 | 825 |
810 // Serialize the current state of the heap. The order is: | 826 // Serialize the current state of the heap. The order is: |
811 // 1) Strong references. | 827 // 1) Strong references. |
812 // 2) Partial snapshot cache. | 828 // 2) Partial snapshot cache. |
813 // 3) Weak references (e.g. the string table). | 829 // 3) Weak references (e.g. the string table). |
814 virtual void SerializeStrongReferences(); | 830 virtual void SerializeStrongReferences(); |
815 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 831 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 private: | 868 private: |
853 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, | 869 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, |
854 Code* main_code) | 870 Code* main_code) |
855 : Serializer(isolate, sink), | 871 : Serializer(isolate, sink), |
856 source_(source), | 872 source_(source), |
857 main_code_(main_code), | 873 main_code_(main_code), |
858 num_internalized_strings_(0) { | 874 num_internalized_strings_(0) { |
859 back_reference_map_.AddSourceString(source); | 875 back_reference_map_.AddSourceString(source); |
860 } | 876 } |
861 | 877 |
| 878 ~CodeSerializer() { OutputStatistics("CodeSerializer"); } |
| 879 |
862 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 880 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
863 WhereToPoint where_to_point, int skip) OVERRIDE; | 881 WhereToPoint where_to_point, int skip) OVERRIDE; |
864 | 882 |
865 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 883 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, |
866 WhereToPoint where_to_point); | 884 WhereToPoint where_to_point); |
867 void SerializeIC(Code* ic, HowToCode how_to_code, | 885 void SerializeIC(Code* ic, HowToCode how_to_code, |
868 WhereToPoint where_to_point); | 886 WhereToPoint where_to_point); |
869 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 887 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, |
870 WhereToPoint where_to_point); | 888 WhereToPoint where_to_point); |
871 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, | 889 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 kNumInternalizedStringsOffset + kInt32Size; | 996 kNumInternalizedStringsOffset + kInt32Size; |
979 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 997 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
980 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 998 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
981 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 999 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
982 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 1000 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
983 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 1001 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
984 }; | 1002 }; |
985 } } // namespace v8::internal | 1003 } } // namespace v8::internal |
986 | 1004 |
987 #endif // V8_SERIALIZE_H_ | 1005 #endif // V8_SERIALIZE_H_ |
OLD | NEW |