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_SNAPSHOT_SERIALIZE_H_ | 5 #ifndef V8_SNAPSHOT_SERIALIZE_H_ |
6 #define V8_SNAPSHOT_SERIALIZE_H_ | 6 #define V8_SNAPSHOT_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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 void DecodeReservation(Vector<const SerializedData::Reservation> res); | 561 void DecodeReservation(Vector<const SerializedData::Reservation> res); |
562 | 562 |
563 bool ReserveSpace(); | 563 bool ReserveSpace(); |
564 | 564 |
565 void UnalignedCopy(Object** dest, Object** src) { | 565 void UnalignedCopy(Object** dest, Object** src) { |
566 memcpy(dest, src, sizeof(*src)); | 566 memcpy(dest, src, sizeof(*src)); |
567 } | 567 } |
568 | 568 |
569 void DeserializeDeferredObjects(); | 569 void DeserializeDeferredObjects(); |
570 | 570 |
| 571 void CommitNewInternalizedStrings(Isolate* isolate); |
| 572 |
571 // Fills in some heap data in an area from start to end (non-inclusive). The | 573 // Fills in some heap data in an area from start to end (non-inclusive). The |
572 // space id is used for the write barrier. The object_address is the address | 574 // space id is used for the write barrier. The object_address is the address |
573 // of the object we are writing into, or NULL if we are not writing into an | 575 // of the object we are writing into, or NULL if we are not writing into an |
574 // object, i.e. if we are writing a series of tagged values that are not on | 576 // object, i.e. if we are writing a series of tagged values that are not on |
575 // the heap. Return false if the object content has been deferred. | 577 // the heap. Return false if the object content has been deferred. |
576 bool ReadData(Object** start, Object** end, int space, | 578 bool ReadData(Object** start, Object** end, int space, |
577 Address object_address); | 579 Address object_address); |
578 void ReadObject(int space_number, Object** write_back); | 580 void ReadObject(int space_number, Object** write_back); |
579 Address Allocate(int space_index, int size); | 581 Address Allocate(int space_index, int size); |
580 | 582 |
(...skipping 18 matching lines...) Expand all Loading... |
599 // fitting into a page. Deserialized objects are allocated into the | 601 // fitting into a page. Deserialized objects are allocated into the |
600 // current chunk of the target space by bumping up high water mark. | 602 // current chunk of the target space by bumping up high water mark. |
601 Heap::Reservation reservations_[kNumberOfSpaces]; | 603 Heap::Reservation reservations_[kNumberOfSpaces]; |
602 uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; | 604 uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; |
603 Address high_water_[kNumberOfPreallocatedSpaces]; | 605 Address high_water_[kNumberOfPreallocatedSpaces]; |
604 | 606 |
605 ExternalReferenceTable* external_reference_table_; | 607 ExternalReferenceTable* external_reference_table_; |
606 | 608 |
607 List<HeapObject*> deserialized_large_objects_; | 609 List<HeapObject*> deserialized_large_objects_; |
608 List<Code*> new_code_objects_; | 610 List<Code*> new_code_objects_; |
| 611 List<Handle<String> > new_internalized_strings_; |
609 | 612 |
610 bool deserializing_user_code_; | 613 bool deserializing_user_code_; |
611 | 614 |
612 AllocationAlignment next_alignment_; | 615 AllocationAlignment next_alignment_; |
613 | 616 |
614 DISALLOW_COPY_AND_ASSIGN(Deserializer); | 617 DISALLOW_COPY_AND_ASSIGN(Deserializer); |
615 }; | 618 }; |
616 | 619 |
617 | 620 |
618 class CodeAddressMap; | 621 class CodeAddressMap; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 STATIC_ASSERT(kSourceObjectReference == kSourceObjectIndex); | 905 STATIC_ASSERT(kSourceObjectReference == kSourceObjectIndex); |
903 | 906 |
904 static const int kCodeStubsBaseIndex = 1; | 907 static const int kCodeStubsBaseIndex = 1; |
905 | 908 |
906 String* source() const { | 909 String* source() const { |
907 DCHECK(!AllowHeapAllocation::IsAllowed()); | 910 DCHECK(!AllowHeapAllocation::IsAllowed()); |
908 return source_; | 911 return source_; |
909 } | 912 } |
910 | 913 |
911 const List<uint32_t>* stub_keys() const { return &stub_keys_; } | 914 const List<uint32_t>* stub_keys() const { return &stub_keys_; } |
912 int num_internalized_strings() const { return num_internalized_strings_; } | |
913 | 915 |
914 private: | 916 private: |
915 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, | 917 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, |
916 Code* main_code) | 918 Code* main_code) |
917 : Serializer(isolate, sink), | 919 : Serializer(isolate, sink), source_(source), main_code_(main_code) { |
918 source_(source), | |
919 main_code_(main_code), | |
920 num_internalized_strings_(0) { | |
921 back_reference_map_.AddSourceString(source); | 920 back_reference_map_.AddSourceString(source); |
922 } | 921 } |
923 | 922 |
924 ~CodeSerializer() { OutputStatistics("CodeSerializer"); } | 923 ~CodeSerializer() { OutputStatistics("CodeSerializer"); } |
925 | 924 |
926 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 925 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
927 WhereToPoint where_to_point, int skip) override; | 926 WhereToPoint where_to_point, int skip) override; |
928 | 927 |
929 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 928 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, |
930 WhereToPoint where_to_point); | 929 WhereToPoint where_to_point); |
931 void SerializeIC(Code* ic, HowToCode how_to_code, | 930 void SerializeIC(Code* ic, HowToCode how_to_code, |
932 WhereToPoint where_to_point); | 931 WhereToPoint where_to_point); |
933 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 932 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, |
934 WhereToPoint where_to_point); | 933 WhereToPoint where_to_point); |
935 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, | 934 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, |
936 WhereToPoint where_to_point); | 935 WhereToPoint where_to_point); |
937 int AddCodeStubKey(uint32_t stub_key); | 936 int AddCodeStubKey(uint32_t stub_key); |
938 | 937 |
939 DisallowHeapAllocation no_gc_; | 938 DisallowHeapAllocation no_gc_; |
940 String* source_; | 939 String* source_; |
941 Code* main_code_; | 940 Code* main_code_; |
942 int num_internalized_strings_; | |
943 List<uint32_t> stub_keys_; | 941 List<uint32_t> stub_keys_; |
944 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); | 942 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); |
945 }; | 943 }; |
946 | 944 |
947 | 945 |
948 // Wrapper around reservation sizes and the serialization payload. | 946 // Wrapper around reservation sizes and the serialization payload. |
949 class SnapshotData : public SerializedData { | 947 class SnapshotData : public SerializedData { |
950 public: | 948 public: |
951 // Used when producing. | 949 // Used when producing. |
952 explicit SnapshotData(const Serializer& ser); | 950 explicit SnapshotData(const Serializer& ser); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 | 989 |
992 // Used when producing. | 990 // Used when producing. |
993 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); | 991 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); |
994 | 992 |
995 // Return ScriptData object and relinquish ownership over it to the caller. | 993 // Return ScriptData object and relinquish ownership over it to the caller. |
996 ScriptData* GetScriptData(); | 994 ScriptData* GetScriptData(); |
997 | 995 |
998 Vector<const Reservation> Reservations() const; | 996 Vector<const Reservation> Reservations() const; |
999 Vector<const byte> Payload() const; | 997 Vector<const byte> Payload() const; |
1000 | 998 |
1001 int NumInternalizedStrings() const; | |
1002 Vector<const uint32_t> CodeStubKeys() const; | 999 Vector<const uint32_t> CodeStubKeys() const; |
1003 | 1000 |
1004 private: | 1001 private: |
1005 explicit SerializedCodeData(ScriptData* data); | 1002 explicit SerializedCodeData(ScriptData* data); |
1006 | 1003 |
1007 enum SanityCheckResult { | 1004 enum SanityCheckResult { |
1008 CHECK_SUCCESS = 0, | 1005 CHECK_SUCCESS = 0, |
1009 MAGIC_NUMBER_MISMATCH = 1, | 1006 MAGIC_NUMBER_MISMATCH = 1, |
1010 VERSION_MISMATCH = 2, | 1007 VERSION_MISMATCH = 2, |
1011 SOURCE_MISMATCH = 3, | 1008 SOURCE_MISMATCH = 3, |
1012 CPU_FEATURES_MISMATCH = 4, | 1009 CPU_FEATURES_MISMATCH = 4, |
1013 FLAGS_MISMATCH = 5, | 1010 FLAGS_MISMATCH = 5, |
1014 CHECKSUM_MISMATCH = 6 | 1011 CHECKSUM_MISMATCH = 6 |
1015 }; | 1012 }; |
1016 | 1013 |
1017 SanityCheckResult SanityCheck(Isolate* isolate, String* source) const; | 1014 SanityCheckResult SanityCheck(Isolate* isolate, String* source) const; |
1018 | 1015 |
1019 uint32_t SourceHash(String* source) const { return source->length(); } | 1016 uint32_t SourceHash(String* source) const { return source->length(); } |
1020 | 1017 |
1021 // The data header consists of uint32_t-sized entries: | 1018 // The data header consists of uint32_t-sized entries: |
1022 // [ 0] magic number and external reference count | 1019 // [0] magic number and external reference count |
1023 // [ 1] version hash | 1020 // [1] version hash |
1024 // [ 2] source hash | 1021 // [2] source hash |
1025 // [ 3] cpu features | 1022 // [3] cpu features |
1026 // [ 4] flag hash | 1023 // [4] flag hash |
1027 // [ 5] number of internalized strings | 1024 // [5] number of code stub keys |
1028 // [ 6] number of code stub keys | 1025 // [6] number of reservation size entries |
1029 // [ 7] number of reservation size entries | 1026 // [7] payload length |
1030 // [ 8] payload length | 1027 // [8] payload checksum part 1 |
1031 // [ 9] payload checksum part 1 | 1028 // [9] payload checksum part 2 |
1032 // [10] payload checksum part 2 | |
1033 // ... reservations | 1029 // ... reservations |
1034 // ... code stub keys | 1030 // ... code stub keys |
1035 // ... serialized payload | 1031 // ... serialized payload |
1036 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; | 1032 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; |
1037 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; | 1033 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; |
1038 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; | 1034 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; |
1039 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; | 1035 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; |
1040 static const int kNumInternalizedStringsOffset = kFlagHashOffset + kInt32Size; | 1036 static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size; |
1041 static const int kNumReservationsOffset = | |
1042 kNumInternalizedStringsOffset + kInt32Size; | |
1043 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 1037 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
1044 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 1038 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
1045 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 1039 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
1046 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 1040 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
1047 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 1041 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
1048 }; | 1042 }; |
1049 } } // namespace v8::internal | 1043 } } // namespace v8::internal |
1050 | 1044 |
1051 #endif // V8_SNAPSHOT_SERIALIZE_H_ | 1045 #endif // V8_SNAPSHOT_SERIALIZE_H_ |
OLD | NEW |