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_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_SERIALIZER_H_ |
6 #define V8_SNAPSHOT_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_SERIALIZER_H_ |
7 | 7 |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/log.h" | 9 #include "src/log.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 public: | 121 public: |
122 Serializer(Isolate* isolate, SnapshotByteSink* sink); | 122 Serializer(Isolate* isolate, SnapshotByteSink* sink); |
123 ~Serializer() override; | 123 ~Serializer() override; |
124 | 124 |
125 void EncodeReservations(List<SerializedData::Reservation>* out) const; | 125 void EncodeReservations(List<SerializedData::Reservation>* out) const; |
126 | 126 |
127 void SerializeDeferredObjects(); | 127 void SerializeDeferredObjects(); |
128 | 128 |
129 Isolate* isolate() const { return isolate_; } | 129 Isolate* isolate() const { return isolate_; } |
130 | 130 |
131 BackReferenceMap* back_reference_map() { return &back_reference_map_; } | 131 SerializerReferenceMap* reference_map() { return &reference_map_; } |
132 RootIndexMap* root_index_map() { return &root_index_map_; } | 132 RootIndexMap* root_index_map() { return &root_index_map_; } |
133 | 133 |
134 #ifdef OBJECT_PRINT | 134 #ifdef OBJECT_PRINT |
135 void CountInstanceType(Map* map, int size); | 135 void CountInstanceType(Map* map, int size); |
136 #endif // OBJECT_PRINT | 136 #endif // OBJECT_PRINT |
137 | 137 |
138 protected: | 138 protected: |
139 class ObjectSerializer; | 139 class ObjectSerializer; |
140 class RecursionScope { | 140 class RecursionScope { |
141 public: | 141 public: |
(...skipping 13 matching lines...) Expand all Loading... |
155 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 155 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
156 WhereToPoint where_to_point, int skip) = 0; | 156 WhereToPoint where_to_point, int skip) = 0; |
157 | 157 |
158 void VisitPointers(Object** start, Object** end) override; | 158 void VisitPointers(Object** start, Object** end) override; |
159 | 159 |
160 void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, | 160 void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, |
161 int skip); | 161 int skip); |
162 | 162 |
163 void PutSmi(Smi* smi); | 163 void PutSmi(Smi* smi); |
164 | 164 |
165 void PutBackReference(HeapObject* object, BackReference reference); | 165 void PutBackReference(HeapObject* object, SerializerReference reference); |
| 166 |
| 167 void PutAttachedReference(SerializerReference reference, |
| 168 HowToCode how_to_code, WhereToPoint where_to_point); |
166 | 169 |
167 // Emit alignment prefix if necessary, return required padding space in bytes. | 170 // Emit alignment prefix if necessary, return required padding space in bytes. |
168 int PutAlignmentPrefix(HeapObject* object); | 171 int PutAlignmentPrefix(HeapObject* object); |
169 | 172 |
170 // Returns true if the object was successfully serialized. | 173 // Returns true if the object was successfully serialized. |
171 bool SerializeKnownObject(HeapObject* obj, HowToCode how_to_code, | 174 bool SerializeKnownObject(HeapObject* obj, HowToCode how_to_code, |
172 WhereToPoint where_to_point, int skip); | 175 WhereToPoint where_to_point, int skip); |
173 | 176 |
174 inline void FlushSkip(int skip) { | 177 inline void FlushSkip(int skip) { |
175 if (skip != 0) { | 178 if (skip != 0) { |
176 sink_->Put(kSkip, "SkipFromSerializeObject"); | 179 sink_->Put(kSkip, "SkipFromSerializeObject"); |
177 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); | 180 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
178 } | 181 } |
179 } | 182 } |
180 | 183 |
181 bool BackReferenceIsAlreadyAllocated(BackReference back_reference); | 184 bool BackReferenceIsAlreadyAllocated(SerializerReference back_reference); |
182 | 185 |
183 // This will return the space for an object. | 186 // This will return the space for an object. |
184 BackReference AllocateLargeObject(int size); | 187 SerializerReference AllocateLargeObject(int size); |
185 BackReference Allocate(AllocationSpace space, int size); | 188 SerializerReference Allocate(AllocationSpace space, int size); |
186 int EncodeExternalReference(Address addr) { | 189 int EncodeExternalReference(Address addr) { |
187 return external_reference_encoder_.Encode(addr); | 190 return external_reference_encoder_.Encode(addr); |
188 } | 191 } |
189 | 192 |
190 bool HasNotExceededFirstPageOfEachSpace(); | 193 bool HasNotExceededFirstPageOfEachSpace(); |
191 | 194 |
192 // GetInt reads 4 bytes at once, requiring padding at the end. | 195 // GetInt reads 4 bytes at once, requiring padding at the end. |
193 void Pad(); | 196 void Pad(); |
194 | 197 |
195 // We may not need the code address map for logging for every instance | 198 // We may not need the code address map for logging for every instance |
196 // of the serializer. Initialize it on demand. | 199 // of the serializer. Initialize it on demand. |
197 void InitializeCodeAddressMap(); | 200 void InitializeCodeAddressMap(); |
198 | 201 |
199 Code* CopyCode(Code* code); | 202 Code* CopyCode(Code* code); |
200 | 203 |
201 inline uint32_t max_chunk_size(int space) const { | 204 inline uint32_t max_chunk_size(int space) const { |
202 DCHECK_LE(0, space); | 205 DCHECK_LE(0, space); |
203 DCHECK_LT(space, kNumberOfSpaces); | 206 DCHECK_LT(space, kNumberOfSpaces); |
204 return max_chunk_size_[space]; | 207 return max_chunk_size_[space]; |
205 } | 208 } |
206 | 209 |
207 SnapshotByteSink* sink() const { return sink_; } | 210 SnapshotByteSink* sink() const { return sink_; } |
208 | 211 |
209 void QueueDeferredObject(HeapObject* obj) { | 212 void QueueDeferredObject(HeapObject* obj) { |
210 DCHECK(back_reference_map_.Lookup(obj).is_valid()); | 213 DCHECK(reference_map_.Lookup(obj).is_back_reference()); |
211 deferred_objects_.Add(obj); | 214 deferred_objects_.Add(obj); |
212 } | 215 } |
213 | 216 |
214 void OutputStatistics(const char* name); | 217 void OutputStatistics(const char* name); |
215 | 218 |
216 Isolate* isolate_; | 219 Isolate* isolate_; |
217 | 220 |
218 SnapshotByteSink* sink_; | 221 SnapshotByteSink* sink_; |
219 ExternalReferenceEncoder external_reference_encoder_; | 222 ExternalReferenceEncoder external_reference_encoder_; |
220 | 223 |
221 BackReferenceMap back_reference_map_; | 224 SerializerReferenceMap reference_map_; |
222 RootIndexMap root_index_map_; | 225 RootIndexMap root_index_map_; |
223 | 226 |
224 int recursion_depth_; | 227 int recursion_depth_; |
225 | 228 |
226 friend class Deserializer; | 229 friend class Deserializer; |
227 friend class ObjectSerializer; | 230 friend class ObjectSerializer; |
228 friend class RecursionScope; | 231 friend class RecursionScope; |
229 friend class SnapshotData; | 232 friend class SnapshotData; |
230 | 233 |
231 private: | 234 private: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 SnapshotByteSink* sink_; | 315 SnapshotByteSink* sink_; |
313 int reference_representation_; | 316 int reference_representation_; |
314 int bytes_processed_so_far_; | 317 int bytes_processed_so_far_; |
315 bool code_has_been_output_; | 318 bool code_has_been_output_; |
316 }; | 319 }; |
317 | 320 |
318 } // namespace internal | 321 } // namespace internal |
319 } // namespace v8 | 322 } // namespace v8 |
320 | 323 |
321 #endif // V8_SNAPSHOT_SERIALIZER_H_ | 324 #endif // V8_SNAPSHOT_SERIALIZER_H_ |
OLD | NEW |