| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 void FlushICacheForNewCodeObjects(); | 542 void FlushICacheForNewCodeObjects(); |
| 543 | 543 |
| 544 // Pass a vector of externally-provided objects referenced by the snapshot. | 544 // Pass a vector of externally-provided objects referenced by the snapshot. |
| 545 // The ownership to its backing store is handed over as well. | 545 // The ownership to its backing store is handed over as well. |
| 546 void SetAttachedObjects(Vector<Handle<Object> > attached_objects) { | 546 void SetAttachedObjects(Vector<Handle<Object> > attached_objects) { |
| 547 attached_objects_ = attached_objects; | 547 attached_objects_ = attached_objects; |
| 548 } | 548 } |
| 549 | 549 |
| 550 private: | 550 private: |
| 551 class NewInternalizedStrings : public Relocatable { |
| 552 public: |
| 553 explicit NewInternalizedStrings(Isolate* isolate) : Relocatable(isolate) {} |
| 554 |
| 555 virtual void IterateInstance(ObjectVisitor* v) { |
| 556 Object** start = reinterpret_cast<Object**>(&strings_[0]); |
| 557 v->VisitPointers(start, start + strings_.length()); |
| 558 } |
| 559 |
| 560 void Add(String* string) { strings_.Add(string); } |
| 561 |
| 562 void Commit(Isolate* isolate); |
| 563 |
| 564 private: |
| 565 List<String*> strings_; |
| 566 }; |
| 567 |
| 551 virtual void VisitPointers(Object** start, Object** end); | 568 virtual void VisitPointers(Object** start, Object** end); |
| 552 | 569 |
| 553 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { | 570 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |
| 554 UNREACHABLE(); | 571 UNREACHABLE(); |
| 555 } | 572 } |
| 556 | 573 |
| 557 void Initialize(Isolate* isolate); | 574 void Initialize(Isolate* isolate); |
| 558 | 575 |
| 559 bool deserializing_user_code() { return deserializing_user_code_; } | 576 bool deserializing_user_code() { return deserializing_user_code_; } |
| 560 | 577 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // fitting into a page. Deserialized objects are allocated into the | 616 // fitting into a page. Deserialized objects are allocated into the |
| 600 // current chunk of the target space by bumping up high water mark. | 617 // current chunk of the target space by bumping up high water mark. |
| 601 Heap::Reservation reservations_[kNumberOfSpaces]; | 618 Heap::Reservation reservations_[kNumberOfSpaces]; |
| 602 uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; | 619 uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; |
| 603 Address high_water_[kNumberOfPreallocatedSpaces]; | 620 Address high_water_[kNumberOfPreallocatedSpaces]; |
| 604 | 621 |
| 605 ExternalReferenceTable* external_reference_table_; | 622 ExternalReferenceTable* external_reference_table_; |
| 606 | 623 |
| 607 List<HeapObject*> deserialized_large_objects_; | 624 List<HeapObject*> deserialized_large_objects_; |
| 608 List<Code*> new_code_objects_; | 625 List<Code*> new_code_objects_; |
| 626 NewInternalizedStrings* new_internalized_strings_; |
| 609 | 627 |
| 610 bool deserializing_user_code_; | 628 bool deserializing_user_code_; |
| 611 | 629 |
| 612 AllocationAlignment next_alignment_; | 630 AllocationAlignment next_alignment_; |
| 613 | 631 |
| 614 DISALLOW_COPY_AND_ASSIGN(Deserializer); | 632 DISALLOW_COPY_AND_ASSIGN(Deserializer); |
| 615 }; | 633 }; |
| 616 | 634 |
| 617 | 635 |
| 618 class CodeAddressMap; | 636 class CodeAddressMap; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 STATIC_ASSERT(kSourceObjectReference == kSourceObjectIndex); | 920 STATIC_ASSERT(kSourceObjectReference == kSourceObjectIndex); |
| 903 | 921 |
| 904 static const int kCodeStubsBaseIndex = 1; | 922 static const int kCodeStubsBaseIndex = 1; |
| 905 | 923 |
| 906 String* source() const { | 924 String* source() const { |
| 907 DCHECK(!AllowHeapAllocation::IsAllowed()); | 925 DCHECK(!AllowHeapAllocation::IsAllowed()); |
| 908 return source_; | 926 return source_; |
| 909 } | 927 } |
| 910 | 928 |
| 911 const List<uint32_t>* stub_keys() const { return &stub_keys_; } | 929 const List<uint32_t>* stub_keys() const { return &stub_keys_; } |
| 912 int num_internalized_strings() const { return num_internalized_strings_; } | |
| 913 | 930 |
| 914 private: | 931 private: |
| 915 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, | 932 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, |
| 916 Code* main_code) | 933 Code* main_code) |
| 917 : Serializer(isolate, sink), | 934 : 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); | 935 back_reference_map_.AddSourceString(source); |
| 922 } | 936 } |
| 923 | 937 |
| 924 ~CodeSerializer() { OutputStatistics("CodeSerializer"); } | 938 ~CodeSerializer() { OutputStatistics("CodeSerializer"); } |
| 925 | 939 |
| 926 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 940 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
| 927 WhereToPoint where_to_point, int skip) override; | 941 WhereToPoint where_to_point, int skip) override; |
| 928 | 942 |
| 929 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 943 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, |
| 930 WhereToPoint where_to_point); | 944 WhereToPoint where_to_point); |
| 931 void SerializeIC(Code* ic, HowToCode how_to_code, | 945 void SerializeIC(Code* ic, HowToCode how_to_code, |
| 932 WhereToPoint where_to_point); | 946 WhereToPoint where_to_point); |
| 933 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 947 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, |
| 934 WhereToPoint where_to_point); | 948 WhereToPoint where_to_point); |
| 935 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, | 949 void SerializeGeneric(HeapObject* heap_object, HowToCode how_to_code, |
| 936 WhereToPoint where_to_point); | 950 WhereToPoint where_to_point); |
| 937 int AddCodeStubKey(uint32_t stub_key); | 951 int AddCodeStubKey(uint32_t stub_key); |
| 938 | 952 |
| 939 DisallowHeapAllocation no_gc_; | 953 DisallowHeapAllocation no_gc_; |
| 940 String* source_; | 954 String* source_; |
| 941 Code* main_code_; | 955 Code* main_code_; |
| 942 int num_internalized_strings_; | |
| 943 List<uint32_t> stub_keys_; | 956 List<uint32_t> stub_keys_; |
| 944 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); | 957 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); |
| 945 }; | 958 }; |
| 946 | 959 |
| 947 | 960 |
| 948 // Wrapper around reservation sizes and the serialization payload. | 961 // Wrapper around reservation sizes and the serialization payload. |
| 949 class SnapshotData : public SerializedData { | 962 class SnapshotData : public SerializedData { |
| 950 public: | 963 public: |
| 951 // Used when producing. | 964 // Used when producing. |
| 952 explicit SnapshotData(const Serializer& ser); | 965 explicit SnapshotData(const Serializer& ser); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 | 1004 |
| 992 // Used when producing. | 1005 // Used when producing. |
| 993 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); | 1006 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); |
| 994 | 1007 |
| 995 // Return ScriptData object and relinquish ownership over it to the caller. | 1008 // Return ScriptData object and relinquish ownership over it to the caller. |
| 996 ScriptData* GetScriptData(); | 1009 ScriptData* GetScriptData(); |
| 997 | 1010 |
| 998 Vector<const Reservation> Reservations() const; | 1011 Vector<const Reservation> Reservations() const; |
| 999 Vector<const byte> Payload() const; | 1012 Vector<const byte> Payload() const; |
| 1000 | 1013 |
| 1001 int NumInternalizedStrings() const; | |
| 1002 Vector<const uint32_t> CodeStubKeys() const; | 1014 Vector<const uint32_t> CodeStubKeys() const; |
| 1003 | 1015 |
| 1004 private: | 1016 private: |
| 1005 explicit SerializedCodeData(ScriptData* data); | 1017 explicit SerializedCodeData(ScriptData* data); |
| 1006 | 1018 |
| 1007 enum SanityCheckResult { | 1019 enum SanityCheckResult { |
| 1008 CHECK_SUCCESS = 0, | 1020 CHECK_SUCCESS = 0, |
| 1009 MAGIC_NUMBER_MISMATCH = 1, | 1021 MAGIC_NUMBER_MISMATCH = 1, |
| 1010 VERSION_MISMATCH = 2, | 1022 VERSION_MISMATCH = 2, |
| 1011 SOURCE_MISMATCH = 3, | 1023 SOURCE_MISMATCH = 3, |
| 1012 CPU_FEATURES_MISMATCH = 4, | 1024 CPU_FEATURES_MISMATCH = 4, |
| 1013 FLAGS_MISMATCH = 5, | 1025 FLAGS_MISMATCH = 5, |
| 1014 CHECKSUM_MISMATCH = 6 | 1026 CHECKSUM_MISMATCH = 6 |
| 1015 }; | 1027 }; |
| 1016 | 1028 |
| 1017 SanityCheckResult SanityCheck(Isolate* isolate, String* source) const; | 1029 SanityCheckResult SanityCheck(Isolate* isolate, String* source) const; |
| 1018 | 1030 |
| 1019 uint32_t SourceHash(String* source) const { return source->length(); } | 1031 uint32_t SourceHash(String* source) const { return source->length(); } |
| 1020 | 1032 |
| 1021 // The data header consists of uint32_t-sized entries: | 1033 // The data header consists of uint32_t-sized entries: |
| 1022 // [ 0] magic number and external reference count | 1034 // [0] magic number and external reference count |
| 1023 // [ 1] version hash | 1035 // [1] version hash |
| 1024 // [ 2] source hash | 1036 // [2] source hash |
| 1025 // [ 3] cpu features | 1037 // [3] cpu features |
| 1026 // [ 4] flag hash | 1038 // [4] flag hash |
| 1027 // [ 5] number of internalized strings | 1039 // [5] number of code stub keys |
| 1028 // [ 6] number of code stub keys | 1040 // [6] number of reservation size entries |
| 1029 // [ 7] number of reservation size entries | 1041 // [7] payload length |
| 1030 // [ 8] payload length | 1042 // [8] payload checksum part 1 |
| 1031 // [ 9] payload checksum part 1 | 1043 // [9] payload checksum part 2 |
| 1032 // [10] payload checksum part 2 | |
| 1033 // ... reservations | 1044 // ... reservations |
| 1034 // ... code stub keys | 1045 // ... code stub keys |
| 1035 // ... serialized payload | 1046 // ... serialized payload |
| 1036 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; | 1047 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; |
| 1037 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; | 1048 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; |
| 1038 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; | 1049 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; |
| 1039 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; | 1050 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; |
| 1040 static const int kNumInternalizedStringsOffset = kFlagHashOffset + kInt32Size; | 1051 static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size; |
| 1041 static const int kNumReservationsOffset = | |
| 1042 kNumInternalizedStringsOffset + kInt32Size; | |
| 1043 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 1052 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
| 1044 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 1053 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
| 1045 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 1054 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
| 1046 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 1055 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
| 1047 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 1056 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
| 1048 }; | 1057 }; |
| 1049 } } // namespace v8::internal | 1058 } } // namespace v8::internal |
| 1050 | 1059 |
| 1051 #endif // V8_SNAPSHOT_SERIALIZE_H_ | 1060 #endif // V8_SNAPSHOT_SERIALIZE_H_ |
| OLD | NEW |