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" | |
9 #include "src/hashmap.h" | 8 #include "src/hashmap.h" |
10 #include "src/heap-profiler.h" | 9 #include "src/heap-profiler.h" |
11 #include "src/isolate.h" | 10 #include "src/isolate.h" |
12 #include "src/snapshot-source-sink.h" | 11 #include "src/snapshot-source-sink.h" |
13 | 12 |
14 namespace v8 { | 13 namespace v8 { |
15 namespace internal { | 14 namespace internal { |
16 | 15 |
| 16 class ScriptData; |
| 17 |
17 // A TypeCode is used to distinguish different kinds of external reference. | 18 // A TypeCode is used to distinguish different kinds of external reference. |
18 // It is a single bit to make testing for types easy. | 19 // It is a single bit to make testing for types easy. |
19 enum TypeCode { | 20 enum TypeCode { |
20 UNCLASSIFIED, // One-of-a-kind references. | 21 UNCLASSIFIED, // One-of-a-kind references. |
21 C_BUILTIN, | 22 C_BUILTIN, |
22 BUILTIN, | 23 BUILTIN, |
23 RUNTIME_FUNCTION, | 24 RUNTIME_FUNCTION, |
24 IC_UTILITY, | 25 IC_UTILITY, |
25 STATS_COUNTER, | 26 STATS_COUNTER, |
26 TOP_ADDRESS, | 27 TOP_ADDRESS, |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size; | 925 static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size; |
925 static const int kHeaderSize = kPayloadLengthOffset + kInt32Size; | 926 static const int kHeaderSize = kPayloadLengthOffset + kInt32Size; |
926 }; | 927 }; |
927 | 928 |
928 | 929 |
929 // Wrapper around ScriptData to provide code-serializer-specific functionality. | 930 // Wrapper around ScriptData to provide code-serializer-specific functionality. |
930 class SerializedCodeData : public SerializedData { | 931 class SerializedCodeData : public SerializedData { |
931 public: | 932 public: |
932 // Used when consuming. | 933 // Used when consuming. |
933 static SerializedCodeData* FromCachedData(ScriptData* cached_data, | 934 static SerializedCodeData* FromCachedData(ScriptData* cached_data, |
934 String* source) { | 935 String* source); |
935 DisallowHeapAllocation no_gc; | |
936 SerializedCodeData* scd = new SerializedCodeData(cached_data); | |
937 if (scd->IsSane(source)) return scd; | |
938 cached_data->Reject(); | |
939 delete scd; | |
940 return NULL; | |
941 } | |
942 | 936 |
943 // Used when producing. | 937 // Used when producing. |
944 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); | 938 SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); |
945 | 939 |
946 // Return ScriptData object and relinquish ownership over it to the caller. | 940 // Return ScriptData object and relinquish ownership over it to the caller. |
947 ScriptData* GetScriptData(); | 941 ScriptData* GetScriptData(); |
948 | 942 |
949 Vector<const Reservation> Reservations() const; | 943 Vector<const Reservation> Reservations() const; |
950 Vector<const byte> Payload() const; | 944 Vector<const byte> Payload() const; |
951 | 945 |
952 int NumInternalizedStrings() const; | 946 int NumInternalizedStrings() const; |
953 Vector<const uint32_t> CodeStubKeys() const; | 947 Vector<const uint32_t> CodeStubKeys() const; |
954 | 948 |
955 private: | 949 private: |
956 explicit SerializedCodeData(ScriptData* data) | 950 explicit SerializedCodeData(ScriptData* data); |
957 : SerializedData(const_cast<byte*>(data->data()), data->length()) {} | |
958 | 951 |
959 bool IsSane(String* source) const; | 952 bool IsSane(String* source) const; |
960 | 953 |
961 uint32_t SourceHash(String* source) const { return source->length(); } | 954 uint32_t SourceHash(String* source) const { return source->length(); } |
962 | 955 |
963 // The data header consists of uint32_t-sized entries: | 956 // The data header consists of uint32_t-sized entries: |
964 // [0] version hash | 957 // [0] version hash |
965 // [1] source hash | 958 // [1] source hash |
966 // [2] cpu features | 959 // [2] cpu features |
967 // [3] flag hash | 960 // [3] flag hash |
(...skipping 15 matching lines...) Expand all Loading... |
983 kNumInternalizedStringsOffset + kInt32Size; | 976 kNumInternalizedStringsOffset + kInt32Size; |
984 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 977 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
985 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 978 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
986 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 979 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
987 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 980 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
988 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 981 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
989 }; | 982 }; |
990 } } // namespace v8::internal | 983 } } // namespace v8::internal |
991 | 984 |
992 #endif // V8_SERIALIZE_H_ | 985 #endif // V8_SERIALIZE_H_ |
OLD | NEW |