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/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
10 #include "src/heap-profiler.h" | 10 #include "src/heap-profiler.h" |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 }; | 699 }; |
700 | 700 |
701 | 701 |
702 class CodeSerializer : public Serializer { | 702 class CodeSerializer : public Serializer { |
703 public: | 703 public: |
704 static ScriptData* Serialize(Isolate* isolate, | 704 static ScriptData* Serialize(Isolate* isolate, |
705 Handle<SharedFunctionInfo> info, | 705 Handle<SharedFunctionInfo> info, |
706 Handle<String> source); | 706 Handle<String> source); |
707 | 707 |
708 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( | 708 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( |
709 Isolate* isolate, ScriptData* cached_data, Handle<String> source); | 709 Isolate* isolate, ScriptData* data, Handle<String> source); |
710 | 710 |
711 static const int kSourceObjectIndex = 0; | 711 static const int kSourceObjectIndex = 0; |
712 static const int kCodeStubsBaseIndex = 1; | 712 static const int kCodeStubsBaseIndex = 1; |
713 | 713 |
714 String* source() const { | 714 String* source() const { |
715 DCHECK(!AllowHeapAllocation::IsAllowed()); | 715 DCHECK(!AllowHeapAllocation::IsAllowed()); |
716 return source_; | 716 return source_; |
717 } | 717 } |
718 | 718 |
719 List<uint32_t>* stub_keys() { return &stub_keys_; } | 719 List<uint32_t>* stub_keys() { return &stub_keys_; } |
(...skipping 30 matching lines...) Expand all Loading... |
750 int num_internalized_strings_; | 750 int num_internalized_strings_; |
751 List<uint32_t> stub_keys_; | 751 List<uint32_t> stub_keys_; |
752 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); | 752 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); |
753 }; | 753 }; |
754 | 754 |
755 | 755 |
756 // Wrapper around ScriptData to provide code-serializer-specific functionality. | 756 // Wrapper around ScriptData to provide code-serializer-specific functionality. |
757 class SerializedCodeData { | 757 class SerializedCodeData { |
758 public: | 758 public: |
759 // Used by when consuming. | 759 // Used by when consuming. |
760 static SerializedCodeData* FromCachedData(ScriptData* cached_data, | 760 explicit SerializedCodeData(ScriptData* data, String* source) |
761 String* source) { | 761 : script_data_(data), owns_script_data_(false) { |
762 DisallowHeapAllocation no_gc; | 762 DisallowHeapAllocation no_gc; |
763 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 763 CHECK(IsSane(source)); |
764 if (scd->IsSane(source)) return scd; | |
765 cached_data->Reject(); | |
766 delete scd; | |
767 return NULL; | |
768 } | 764 } |
769 | 765 |
770 // Used when producing. | 766 // Used when producing. |
771 SerializedCodeData(const List<byte>& payload, CodeSerializer* cs); | 767 SerializedCodeData(const List<byte>& payload, CodeSerializer* cs); |
772 | 768 |
773 ~SerializedCodeData() { | 769 ~SerializedCodeData() { |
774 if (owns_script_data_) delete script_data_; | 770 if (owns_script_data_) delete script_data_; |
775 } | 771 } |
776 | 772 |
777 // Return ScriptData object and relinquish ownership over it to the caller. | 773 // Return ScriptData object and relinquish ownership over it to the caller. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 } | 815 } |
820 | 816 |
821 int PayloadLength() const { | 817 int PayloadLength() const { |
822 int payload_length = GetHeaderValue(kPayloadLengthOffset); | 818 int payload_length = GetHeaderValue(kPayloadLengthOffset); |
823 DCHECK_EQ(script_data_->data() + script_data_->length(), | 819 DCHECK_EQ(script_data_->data() + script_data_->length(), |
824 Payload() + payload_length); | 820 Payload() + payload_length); |
825 return payload_length; | 821 return payload_length; |
826 } | 822 } |
827 | 823 |
828 private: | 824 private: |
829 explicit SerializedCodeData(ScriptData* data) | |
830 : script_data_(data), owns_script_data_(false) {} | |
831 | |
832 void SetHeaderValue(int offset, int value) { | 825 void SetHeaderValue(int offset, int value) { |
833 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = | 826 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = |
834 value; | 827 value; |
835 } | 828 } |
836 | 829 |
837 int GetHeaderValue(int offset) const { | 830 int GetHeaderValue(int offset) const { |
838 return reinterpret_cast<const int*>(script_data_->data())[offset]; | 831 return reinterpret_cast<const int*>(script_data_->data())[offset]; |
839 } | 832 } |
840 | 833 |
841 bool IsSane(String* source); | 834 bool IsSane(String* source); |
(...skipping 19 matching lines...) Expand all Loading... |
861 // Following the header, we store, in sequential order | 854 // Following the header, we store, in sequential order |
862 // - code stub keys | 855 // - code stub keys |
863 // - serialization payload | 856 // - serialization payload |
864 | 857 |
865 ScriptData* script_data_; | 858 ScriptData* script_data_; |
866 bool owns_script_data_; | 859 bool owns_script_data_; |
867 }; | 860 }; |
868 } } // namespace v8::internal | 861 } } // namespace v8::internal |
869 | 862 |
870 #endif // V8_SERIALIZE_H_ | 863 #endif // V8_SERIALIZE_H_ |
OLD | NEW |