Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: src/snapshot/serialize.h

Issue 1086363002: Serializer: collect and output memory statistics. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void CountInstanceType(InstanceType instance_type) {
621 instance_type_count_[instance_type]++;
622 }
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
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 static const int kInstanceTypes = 256;
756 int* instance_type_count_;
757
749 DISALLOW_COPY_AND_ASSIGN(Serializer); 758 DISALLOW_COPY_AND_ASSIGN(Serializer);
750 }; 759 };
751 760
752 761
753 class PartialSerializer : public Serializer { 762 class PartialSerializer : public Serializer {
754 public: 763 public:
755 PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer, 764 PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer,
756 SnapshotByteSink* sink) 765 SnapshotByteSink* sink)
757 : Serializer(isolate, sink), 766 : Serializer(isolate, sink),
758 startup_serializer_(startup_snapshot_serializer), 767 startup_serializer_(startup_snapshot_serializer),
759 outdated_contexts_(0), 768 outdated_contexts_(0),
760 global_object_(NULL) { 769 global_object_(NULL) {
761 InitializeCodeAddressMap(); 770 InitializeCodeAddressMap();
762 } 771 }
763 772
773 ~PartialSerializer() { OutputStatistics("PartialSerializer"); }
774
764 // Serialize the objects reachable from a single object pointer. 775 // Serialize the objects reachable from a single object pointer.
765 void Serialize(Object** o); 776 void Serialize(Object** o);
766 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, 777 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code,
767 WhereToPoint where_to_point, int skip) OVERRIDE; 778 WhereToPoint where_to_point, int skip) OVERRIDE;
768 779
769 private: 780 private:
770 int PartialSnapshotCacheIndex(HeapObject* o); 781 int PartialSnapshotCacheIndex(HeapObject* o);
771 bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 782 bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
772 // Scripts should be referred only through shared function infos. We can't 783 // 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 784 // allow them to be part of the partial snapshot because they contain a
(...skipping 22 matching lines...) Expand all
796 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) 807 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink)
797 : Serializer(isolate, sink), root_index_wave_front_(0) { 808 : Serializer(isolate, sink), root_index_wave_front_(0) {
798 // Clear the cache of objects used by the partial snapshot. After the 809 // Clear the cache of objects used by the partial snapshot. After the
799 // strong roots have been serialized we can create a partial snapshot 810 // strong roots have been serialized we can create a partial snapshot
800 // which will repopulate the cache with objects needed by that partial 811 // which will repopulate the cache with objects needed by that partial
801 // snapshot. 812 // snapshot.
802 isolate->partial_snapshot_cache()->Clear(); 813 isolate->partial_snapshot_cache()->Clear();
803 InitializeCodeAddressMap(); 814 InitializeCodeAddressMap();
804 } 815 }
805 816
817 ~StartupSerializer() { OutputStatistics("StartupSerializer"); }
818
806 // The StartupSerializer has to serialize the root array, which is slightly 819 // The StartupSerializer has to serialize the root array, which is slightly
807 // different. 820 // different.
808 void VisitPointers(Object** start, Object** end) OVERRIDE; 821 void VisitPointers(Object** start, Object** end) OVERRIDE;
809 822
810 // Serialize the current state of the heap. The order is: 823 // Serialize the current state of the heap. The order is:
811 // 1) Strong references. 824 // 1) Strong references.
812 // 2) Partial snapshot cache. 825 // 2) Partial snapshot cache.
813 // 3) Weak references (e.g. the string table). 826 // 3) Weak references (e.g. the string table).
814 virtual void SerializeStrongReferences(); 827 virtual void SerializeStrongReferences();
815 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, 828 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 private: 865 private:
853 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, 866 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source,
854 Code* main_code) 867 Code* main_code)
855 : Serializer(isolate, sink), 868 : Serializer(isolate, sink),
856 source_(source), 869 source_(source),
857 main_code_(main_code), 870 main_code_(main_code),
858 num_internalized_strings_(0) { 871 num_internalized_strings_(0) {
859 back_reference_map_.AddSourceString(source); 872 back_reference_map_.AddSourceString(source);
860 } 873 }
861 874
875 ~CodeSerializer() { OutputStatistics("CodeSerializer"); }
876
862 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, 877 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code,
863 WhereToPoint where_to_point, int skip) OVERRIDE; 878 WhereToPoint where_to_point, int skip) OVERRIDE;
864 879
865 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, 880 void SerializeBuiltin(int builtin_index, HowToCode how_to_code,
866 WhereToPoint where_to_point); 881 WhereToPoint where_to_point);
867 void SerializeIC(Code* ic, HowToCode how_to_code, 882 void SerializeIC(Code* ic, HowToCode how_to_code,
868 WhereToPoint where_to_point); 883 WhereToPoint where_to_point);
869 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, 884 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code,
870 WhereToPoint where_to_point); 885 WhereToPoint where_to_point);
871 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, 886 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 kNumInternalizedStringsOffset + kInt32Size; 993 kNumInternalizedStringsOffset + kInt32Size;
979 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; 994 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
980 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; 995 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
981 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; 996 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
982 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; 997 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
983 static const int kHeaderSize = kChecksum2Offset + kInt32Size; 998 static const int kHeaderSize = kChecksum2Offset + kInt32Size;
984 }; 999 };
985 } } // namespace v8::internal 1000 } } // namespace v8::internal
986 1001
987 #endif // V8_SERIALIZE_H_ 1002 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/snapshot/serialize.cc » ('j') | src/snapshot/serialize.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698