Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: src/serialize.h

Issue 293993021: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "hashmap.h" 8 #include "v8.h"
Benedikt Meurer 2014/05/27 04:09:59 Nit: Please don't introduce new v8.h includes, but
vogelheim 2014/05/27 15:20:23 Done.
9 #include "snapshot-source-sink.h"
9 10
10 namespace v8 { 11 namespace v8 {
11 namespace internal { 12 namespace internal {
12 13
13 // A TypeCode is used to distinguish different kinds of external reference. 14 // A TypeCode is used to distinguish different kinds of external reference.
14 // It is a single bit to make testing for types easy. 15 // It is a single bit to make testing for types easy.
15 enum TypeCode { 16 enum TypeCode {
16 UNCLASSIFIED, // One-of-a-kind references. 17 UNCLASSIFIED, // One-of-a-kind references.
17 BUILTIN, 18 BUILTIN,
18 RUNTIME_FUNCTION, 19 RUNTIME_FUNCTION,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 void Put(uint32_t key, Address value) { 131 void Put(uint32_t key, Address value) {
131 *Lookup(key) = value; 132 *Lookup(key) = value;
132 } 133 }
133 134
134 Isolate* isolate_; 135 Isolate* isolate_;
135 }; 136 };
136 137
137 138
138 class SnapshotByteSource {
139 public:
140 SnapshotByteSource(const byte* array, int length)
141 : data_(array), length_(length), position_(0) { }
142
143 bool HasMore() { return position_ < length_; }
144
145 int Get() {
146 ASSERT(position_ < length_);
147 return data_[position_++];
148 }
149
150 int32_t GetUnalignedInt() {
151 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN
152 int32_t answer;
153 ASSERT(position_ + sizeof(answer) <= length_ + 0u);
154 answer = *reinterpret_cast<const int32_t*>(data_ + position_);
155 #else
156 int32_t answer = data_[position_];
157 answer |= data_[position_ + 1] << 8;
158 answer |= data_[position_ + 2] << 16;
159 answer |= data_[position_ + 3] << 24;
160 #endif
161 return answer;
162 }
163
164 void Advance(int by) { position_ += by; }
165
166 inline void CopyRaw(byte* to, int number_of_bytes);
167
168 inline int GetInt();
169
170 bool AtEOF();
171
172 int position() { return position_; }
173
174 private:
175 const byte* data_;
176 int length_;
177 int position_;
178 };
179
180
181 // The Serializer/Deserializer class is a common superclass for Serializer and 139 // The Serializer/Deserializer class is a common superclass for Serializer and
182 // Deserializer which is used to store common constants and methods used by 140 // Deserializer which is used to store common constants and methods used by
183 // both. 141 // both.
184 class SerializerDeserializer: public ObjectVisitor { 142 class SerializerDeserializer: public ObjectVisitor {
185 public: 143 public:
186 static void Iterate(Isolate* isolate, ObjectVisitor* visitor); 144 static void Iterate(Isolate* isolate, ObjectVisitor* visitor);
187 145
188 static int nop() { return kNop; } 146 static int nop() { return kNop; }
189 147
190 protected: 148 protected:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 222 }
265 223
266 static const int kNumberOfSpaces = LO_SPACE; 224 static const int kNumberOfSpaces = LO_SPACE;
267 static const int kAnyOldSpace = -1; 225 static const int kAnyOldSpace = -1;
268 226
269 // A bitmask for getting the space out of an instruction. 227 // A bitmask for getting the space out of an instruction.
270 static const int kSpaceMask = 7; 228 static const int kSpaceMask = 7;
271 }; 229 };
272 230
273 231
274 int SnapshotByteSource::GetInt() {
275 // This way of variable-length encoding integers does not suffer from branch
276 // mispredictions.
277 uint32_t answer = GetUnalignedInt();
278 int bytes = answer & 3;
279 Advance(bytes);
280 uint32_t mask = 0xffffffffu;
281 mask >>= 32 - (bytes << 3);
282 answer &= mask;
283 answer >>= 2;
284 return answer;
285 }
286
287
288 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
289 OS::MemCopy(to, data_ + position_, number_of_bytes);
290 position_ += number_of_bytes;
291 }
292
293
294 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. 232 // A Deserializer reads a snapshot and reconstructs the Object graph it defines.
295 class Deserializer: public SerializerDeserializer { 233 class Deserializer: public SerializerDeserializer {
296 public: 234 public:
297 // Create a deserializer from a snapshot byte source. 235 // Create a deserializer from a snapshot byte source.
298 explicit Deserializer(SnapshotByteSource* source); 236 explicit Deserializer(SnapshotByteSource* source);
299 237
300 virtual ~Deserializer(); 238 virtual ~Deserializer();
301 239
302 // Deserialize the snapshot into an empty heap. 240 // Deserialize the snapshot into an empty heap.
303 void Deserialize(Isolate* isolate); 241 void Deserialize(Isolate* isolate);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 302
365 int reservations_[LAST_SPACE + 1]; 303 int reservations_[LAST_SPACE + 1];
366 static const intptr_t kUninitializedReservation = -1; 304 static const intptr_t kUninitializedReservation = -1;
367 305
368 ExternalReferenceDecoder* external_reference_decoder_; 306 ExternalReferenceDecoder* external_reference_decoder_;
369 307
370 DISALLOW_COPY_AND_ASSIGN(Deserializer); 308 DISALLOW_COPY_AND_ASSIGN(Deserializer);
371 }; 309 };
372 310
373 311
374 class SnapshotByteSink {
375 public:
376 virtual ~SnapshotByteSink() { }
377 virtual void Put(int byte, const char* description) = 0;
378 virtual void PutSection(int byte, const char* description) {
379 Put(byte, description);
380 }
381 void PutInt(uintptr_t integer, const char* description);
382 virtual int Position() = 0;
383 };
384
385
386 // Mapping objects to their location after deserialization. 312 // Mapping objects to their location after deserialization.
387 // This is used during building, but not at runtime by V8. 313 // This is used during building, but not at runtime by V8.
388 class SerializationAddressMapper { 314 class SerializationAddressMapper {
389 public: 315 public:
390 SerializationAddressMapper() 316 SerializationAddressMapper()
391 : no_allocation_(), 317 : no_allocation_(),
392 serialization_map_(new HashMap(HashMap::PointersMatch)) { } 318 serialization_map_(new HashMap(HashMap::PointersMatch)) { }
393 319
394 ~SerializationAddressMapper() { 320 ~SerializationAddressMapper() {
395 delete serialization_map_; 321 delete serialization_map_;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 private: 569 private:
644 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 570 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
645 return false; 571 return false;
646 } 572 }
647 }; 573 };
648 574
649 575
650 } } // namespace v8::internal 576 } } // namespace v8::internal
651 577
652 #endif // V8_SERIALIZE_H_ 578 #endif // V8_SERIALIZE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698