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

Side by Side Diff: src/serialize.h

Issue 334913004: Support external startup data in V8. (retry) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + style fix 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
« no previous file with comments | « src/natives-external.cc ('k') | src/serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/hashmap.h" 8 #include "src/hashmap.h"
9 #include "src/heap-profiler.h"
10 #include "src/isolate.h"
11 #include "src/snapshot-source-sink.h"
9 12
10 namespace v8 { 13 namespace v8 {
11 namespace internal { 14 namespace internal {
12 15
13 // A TypeCode is used to distinguish different kinds of external reference. 16 // A TypeCode is used to distinguish different kinds of external reference.
14 // It is a single bit to make testing for types easy. 17 // It is a single bit to make testing for types easy.
15 enum TypeCode { 18 enum TypeCode {
16 UNCLASSIFIED, // One-of-a-kind references. 19 UNCLASSIFIED, // One-of-a-kind references.
17 BUILTIN, 20 BUILTIN,
18 RUNTIME_FUNCTION, 21 RUNTIME_FUNCTION,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 128 }
126 129
127 void Put(uint32_t key, Address value) { 130 void Put(uint32_t key, Address value) {
128 *Lookup(key) = value; 131 *Lookup(key) = value;
129 } 132 }
130 133
131 Isolate* isolate_; 134 Isolate* isolate_;
132 }; 135 };
133 136
134 137
135 class SnapshotByteSource {
136 public:
137 SnapshotByteSource(const byte* array, int length)
138 : data_(array), length_(length), position_(0) { }
139
140 bool HasMore() { return position_ < length_; }
141
142 int Get() {
143 ASSERT(position_ < length_);
144 return data_[position_++];
145 }
146
147 int32_t GetUnalignedInt() {
148 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN
149 int32_t answer;
150 ASSERT(position_ + sizeof(answer) <= length_ + 0u);
151 answer = *reinterpret_cast<const int32_t*>(data_ + position_);
152 #else
153 int32_t answer = data_[position_];
154 answer |= data_[position_ + 1] << 8;
155 answer |= data_[position_ + 2] << 16;
156 answer |= data_[position_ + 3] << 24;
157 #endif
158 return answer;
159 }
160
161 void Advance(int by) { position_ += by; }
162
163 inline void CopyRaw(byte* to, int number_of_bytes);
164
165 inline int GetInt();
166
167 bool AtEOF();
168
169 int position() { return position_; }
170
171 private:
172 const byte* data_;
173 int length_;
174 int position_;
175 };
176
177
178 // The Serializer/Deserializer class is a common superclass for Serializer and 138 // The Serializer/Deserializer class is a common superclass for Serializer and
179 // Deserializer which is used to store common constants and methods used by 139 // Deserializer which is used to store common constants and methods used by
180 // both. 140 // both.
181 class SerializerDeserializer: public ObjectVisitor { 141 class SerializerDeserializer: public ObjectVisitor {
182 public: 142 public:
183 static void Iterate(Isolate* isolate, ObjectVisitor* visitor); 143 static void Iterate(Isolate* isolate, ObjectVisitor* visitor);
184 144
185 static int nop() { return kNop; } 145 static int nop() { return kNop; }
186 146
187 protected: 147 protected:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 221 }
262 222
263 static const int kNumberOfSpaces = LO_SPACE; 223 static const int kNumberOfSpaces = LO_SPACE;
264 static const int kAnyOldSpace = -1; 224 static const int kAnyOldSpace = -1;
265 225
266 // A bitmask for getting the space out of an instruction. 226 // A bitmask for getting the space out of an instruction.
267 static const int kSpaceMask = 7; 227 static const int kSpaceMask = 7;
268 }; 228 };
269 229
270 230
271 int SnapshotByteSource::GetInt() {
272 // This way of variable-length encoding integers does not suffer from branch
273 // mispredictions.
274 uint32_t answer = GetUnalignedInt();
275 int bytes = answer & 3;
276 Advance(bytes);
277 uint32_t mask = 0xffffffffu;
278 mask >>= 32 - (bytes << 3);
279 answer &= mask;
280 answer >>= 2;
281 return answer;
282 }
283
284
285 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
286 MemCopy(to, data_ + position_, number_of_bytes);
287 position_ += number_of_bytes;
288 }
289
290
291 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. 231 // A Deserializer reads a snapshot and reconstructs the Object graph it defines.
292 class Deserializer: public SerializerDeserializer { 232 class Deserializer: public SerializerDeserializer {
293 public: 233 public:
294 // Create a deserializer from a snapshot byte source. 234 // Create a deserializer from a snapshot byte source.
295 explicit Deserializer(SnapshotByteSource* source); 235 explicit Deserializer(SnapshotByteSource* source);
296 236
297 virtual ~Deserializer(); 237 virtual ~Deserializer();
298 238
299 // Deserialize the snapshot into an empty heap. 239 // Deserialize the snapshot into an empty heap.
300 void Deserialize(Isolate* isolate); 240 void Deserialize(Isolate* isolate);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 297
358 int reservations_[LAST_SPACE + 1]; 298 int reservations_[LAST_SPACE + 1];
359 static const intptr_t kUninitializedReservation = -1; 299 static const intptr_t kUninitializedReservation = -1;
360 300
361 ExternalReferenceDecoder* external_reference_decoder_; 301 ExternalReferenceDecoder* external_reference_decoder_;
362 302
363 DISALLOW_COPY_AND_ASSIGN(Deserializer); 303 DISALLOW_COPY_AND_ASSIGN(Deserializer);
364 }; 304 };
365 305
366 306
367 class SnapshotByteSink {
368 public:
369 virtual ~SnapshotByteSink() { }
370 virtual void Put(int byte, const char* description) = 0;
371 virtual void PutSection(int byte, const char* description) {
372 Put(byte, description);
373 }
374 void PutInt(uintptr_t integer, const char* description);
375 virtual int Position() = 0;
376 };
377
378
379 // Mapping objects to their location after deserialization. 307 // Mapping objects to their location after deserialization.
380 // This is used during building, but not at runtime by V8. 308 // This is used during building, but not at runtime by V8.
381 class SerializationAddressMapper { 309 class SerializationAddressMapper {
382 public: 310 public:
383 SerializationAddressMapper() 311 SerializationAddressMapper()
384 : no_allocation_(), 312 : no_allocation_(),
385 serialization_map_(new HashMap(HashMap::PointersMatch)) { } 313 serialization_map_(new HashMap(HashMap::PointersMatch)) { }
386 314
387 ~SerializationAddressMapper() { 315 ~SerializationAddressMapper() {
388 delete serialization_map_; 316 delete serialization_map_;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 SerializeStrongReferences(); 547 SerializeStrongReferences();
620 SerializeWeakReferences(); 548 SerializeWeakReferences();
621 Pad(); 549 Pad();
622 } 550 }
623 }; 551 };
624 552
625 553
626 } } // namespace v8::internal 554 } } // namespace v8::internal
627 555
628 #endif // V8_SERIALIZE_H_ 556 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « src/natives-external.cc ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698