OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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_CODE_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_CODE_SERIALIZER_H_ |
6 #define V8_SNAPSHOT_CODE_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_CODE_SERIALIZER_H_ |
7 | 7 |
8 #include "src/parsing/preparse-data.h" | 8 #include "src/parsing/preparse-data.h" |
9 #include "src/snapshot/serializer.h" | 9 #include "src/snapshot/serializer.h" |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 CHECK_SUCCESS = 0, | 89 CHECK_SUCCESS = 0, |
90 MAGIC_NUMBER_MISMATCH = 1, | 90 MAGIC_NUMBER_MISMATCH = 1, |
91 VERSION_MISMATCH = 2, | 91 VERSION_MISMATCH = 2, |
92 SOURCE_MISMATCH = 3, | 92 SOURCE_MISMATCH = 3, |
93 CPU_FEATURES_MISMATCH = 4, | 93 CPU_FEATURES_MISMATCH = 4, |
94 FLAGS_MISMATCH = 5, | 94 FLAGS_MISMATCH = 5, |
95 CHECKSUM_MISMATCH = 6, | 95 CHECKSUM_MISMATCH = 6, |
96 INVALID_HEADER = 7 | 96 INVALID_HEADER = 7 |
97 }; | 97 }; |
98 | 98 |
| 99 // The data header consists of uint32_t-sized entries: |
| 100 // [0] magic number and external reference count |
| 101 // [1] version hash |
| 102 // [2] source hash |
| 103 // [3] cpu features |
| 104 // [4] flag hash |
| 105 // [5] number of code stub keys |
| 106 // [6] number of reservation size entries |
| 107 // [7] payload length |
| 108 // [8] payload checksum part 1 |
| 109 // [9] payload checksum part 2 |
| 110 // ... reservations |
| 111 // ... code stub keys |
| 112 // ... serialized payload |
| 113 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; |
| 114 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; |
| 115 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; |
| 116 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; |
| 117 static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size; |
| 118 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
| 119 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
| 120 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
| 121 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
| 122 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
| 123 |
99 // Used when consuming. | 124 // Used when consuming. |
100 static const SerializedCodeData FromCachedData( | 125 static const SerializedCodeData FromCachedData( |
101 Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash, | 126 Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash, |
102 SanityCheckResult* rejection_result); | 127 SanityCheckResult* rejection_result); |
103 | 128 |
104 // Used when producing. | 129 // Used when producing. |
105 SerializedCodeData(const List<byte>* payload, const CodeSerializer* cs); | 130 SerializedCodeData(const List<byte>* payload, const CodeSerializer* cs); |
106 | 131 |
107 // Return ScriptData object and relinquish ownership over it to the caller. | 132 // Return ScriptData object and relinquish ownership over it to the caller. |
108 ScriptData* GetScriptData(); | 133 ScriptData* GetScriptData(); |
109 | 134 |
110 Vector<const Reservation> Reservations() const; | 135 Vector<const Reservation> Reservations() const; |
111 Vector<const byte> Payload() const; | 136 Vector<const byte> Payload() const; |
112 | 137 |
113 Vector<const uint32_t> CodeStubKeys() const; | 138 Vector<const uint32_t> CodeStubKeys() const; |
114 | 139 |
115 static uint32_t SourceHash(Handle<String> source); | 140 static uint32_t SourceHash(Handle<String> source); |
116 | 141 |
117 private: | 142 private: |
118 explicit SerializedCodeData(ScriptData* data); | 143 explicit SerializedCodeData(ScriptData* data); |
119 SerializedCodeData(const byte* data, int size) | 144 SerializedCodeData(const byte* data, int size) |
120 : SerializedData(const_cast<byte*>(data), size) {} | 145 : SerializedData(const_cast<byte*>(data), size) {} |
121 | 146 |
122 Vector<const byte> DataWithoutHeader() const { | 147 Vector<const byte> DataWithoutHeader() const { |
123 return Vector<const byte>(data_ + kHeaderSize, size_ - kHeaderSize); | 148 return Vector<const byte>(data_ + kHeaderSize, size_ - kHeaderSize); |
124 } | 149 } |
125 | 150 |
126 SanityCheckResult SanityCheck(Isolate* isolate, | 151 SanityCheckResult SanityCheck(Isolate* isolate, |
127 uint32_t expected_source_hash) const; | 152 uint32_t expected_source_hash) const; |
128 // The data header consists of uint32_t-sized entries: | |
129 // [0] magic number and external reference count | |
130 // [1] version hash | |
131 // [2] source hash | |
132 // [3] cpu features | |
133 // [4] flag hash | |
134 // [5] number of code stub keys | |
135 // [6] number of reservation size entries | |
136 // [7] payload length | |
137 // [8] payload checksum part 1 | |
138 // [9] payload checksum part 2 | |
139 // ... reservations | |
140 // ... code stub keys | |
141 // ... serialized payload | |
142 static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size; | |
143 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size; | |
144 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size; | |
145 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size; | |
146 static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size; | |
147 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | |
148 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | |
149 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | |
150 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | |
151 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | |
152 }; | 153 }; |
153 | 154 |
154 } // namespace internal | 155 } // namespace internal |
155 } // namespace v8 | 156 } // namespace v8 |
156 | 157 |
157 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_ | 158 #endif // V8_SNAPSHOT_CODE_SERIALIZER_H_ |
OLD | NEW |