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* data, Handle<String> source); | 709 Isolate* isolate, ScriptData* cached_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 explicit SerializedCodeData(ScriptData* data, String* source) | 760 static SerializedCodeData* FromCachedData(ScriptData* cached_data, |
761 : script_data_(data), owns_script_data_(false) { | 761 String* source) { |
762 DisallowHeapAllocation no_gc; | 762 DisallowHeapAllocation no_gc; |
763 CHECK(IsSane(source)); | 763 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
| 764 if (scd->IsSane(source)) return scd; |
| 765 cached_data->Reject(); |
| 766 delete scd; |
| 767 return NULL; |
764 } | 768 } |
765 | 769 |
766 // Used when producing. | 770 // Used when producing. |
767 SerializedCodeData(const List<byte>& payload, CodeSerializer* cs); | 771 SerializedCodeData(const List<byte>& payload, CodeSerializer* cs); |
768 | 772 |
769 ~SerializedCodeData() { | 773 ~SerializedCodeData() { |
770 if (owns_script_data_) delete script_data_; | 774 if (owns_script_data_) delete script_data_; |
771 } | 775 } |
772 | 776 |
773 // Return ScriptData object and relinquish ownership over it to the caller. | 777 // Return ScriptData object and relinquish ownership over it to the caller. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 819 } |
816 | 820 |
817 int PayloadLength() const { | 821 int PayloadLength() const { |
818 int payload_length = GetHeaderValue(kPayloadLengthOffset); | 822 int payload_length = GetHeaderValue(kPayloadLengthOffset); |
819 DCHECK_EQ(script_data_->data() + script_data_->length(), | 823 DCHECK_EQ(script_data_->data() + script_data_->length(), |
820 Payload() + payload_length); | 824 Payload() + payload_length); |
821 return payload_length; | 825 return payload_length; |
822 } | 826 } |
823 | 827 |
824 private: | 828 private: |
| 829 explicit SerializedCodeData(ScriptData* data) |
| 830 : script_data_(data), owns_script_data_(false) {} |
| 831 |
825 void SetHeaderValue(int offset, int value) { | 832 void SetHeaderValue(int offset, int value) { |
826 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = | 833 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = |
827 value; | 834 value; |
828 } | 835 } |
829 | 836 |
830 int GetHeaderValue(int offset) const { | 837 int GetHeaderValue(int offset) const { |
831 return reinterpret_cast<const int*>(script_data_->data())[offset]; | 838 return reinterpret_cast<const int*>(script_data_->data())[offset]; |
832 } | 839 } |
833 | 840 |
834 bool IsSane(String* source); | 841 bool IsSane(String* source); |
(...skipping 19 matching lines...) Expand all Loading... |
854 // Following the header, we store, in sequential order | 861 // Following the header, we store, in sequential order |
855 // - code stub keys | 862 // - code stub keys |
856 // - serialization payload | 863 // - serialization payload |
857 | 864 |
858 ScriptData* script_data_; | 865 ScriptData* script_data_; |
859 bool owns_script_data_; | 866 bool owns_script_data_; |
860 }; | 867 }; |
861 } } // namespace v8::internal | 868 } } // namespace v8::internal |
862 | 869 |
863 #endif // V8_SERIALIZE_H_ | 870 #endif // V8_SERIALIZE_H_ |
OLD | NEW |