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

Side by Side Diff: src/serialize.h

Issue 328693003: Revert "Support external startup data in V8." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix brace. 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/isolate.h"
10 #include "src/snapshot-source-sink.h"
11 #include "src/heap-profiler.h"
12 9
13 namespace v8 { 10 namespace v8 {
14 namespace internal { 11 namespace internal {
15 12
16 // A TypeCode is used to distinguish different kinds of external reference. 13 // A TypeCode is used to distinguish different kinds of external reference.
17 // It is a single bit to make testing for types easy. 14 // It is a single bit to make testing for types easy.
18 enum TypeCode { 15 enum TypeCode {
19 UNCLASSIFIED, // One-of-a-kind references. 16 UNCLASSIFIED, // One-of-a-kind references.
20 BUILTIN, 17 BUILTIN,
21 RUNTIME_FUNCTION, 18 RUNTIME_FUNCTION,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 125 }
129 126
130 void Put(uint32_t key, Address value) { 127 void Put(uint32_t key, Address value) {
131 *Lookup(key) = value; 128 *Lookup(key) = value;
132 } 129 }
133 130
134 Isolate* isolate_; 131 Isolate* isolate_;
135 }; 132 };
136 133
137 134
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
138 // The Serializer/Deserializer class is a common superclass for Serializer and 178 // The Serializer/Deserializer class is a common superclass for Serializer and
139 // Deserializer which is used to store common constants and methods used by 179 // Deserializer which is used to store common constants and methods used by
140 // both. 180 // both.
141 class SerializerDeserializer: public ObjectVisitor { 181 class SerializerDeserializer: public ObjectVisitor {
142 public: 182 public:
143 static void Iterate(Isolate* isolate, ObjectVisitor* visitor); 183 static void Iterate(Isolate* isolate, ObjectVisitor* visitor);
144 184
145 static int nop() { return kNop; } 185 static int nop() { return kNop; }
146 186
147 protected: 187 protected:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 261 }
222 262
223 static const int kNumberOfSpaces = LO_SPACE; 263 static const int kNumberOfSpaces = LO_SPACE;
224 static const int kAnyOldSpace = -1; 264 static const int kAnyOldSpace = -1;
225 265
226 // A bitmask for getting the space out of an instruction. 266 // A bitmask for getting the space out of an instruction.
227 static const int kSpaceMask = 7; 267 static const int kSpaceMask = 7;
228 }; 268 };
229 269
230 270
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
231 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. 291 // A Deserializer reads a snapshot and reconstructs the Object graph it defines.
232 class Deserializer: public SerializerDeserializer { 292 class Deserializer: public SerializerDeserializer {
233 public: 293 public:
234 // Create a deserializer from a snapshot byte source. 294 // Create a deserializer from a snapshot byte source.
235 explicit Deserializer(SnapshotByteSource* source); 295 explicit Deserializer(SnapshotByteSource* source);
236 296
237 virtual ~Deserializer(); 297 virtual ~Deserializer();
238 298
239 // Deserialize the snapshot into an empty heap. 299 // Deserialize the snapshot into an empty heap.
240 void Deserialize(Isolate* isolate); 300 void Deserialize(Isolate* isolate);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 361
302 int reservations_[LAST_SPACE + 1]; 362 int reservations_[LAST_SPACE + 1];
303 static const intptr_t kUninitializedReservation = -1; 363 static const intptr_t kUninitializedReservation = -1;
304 364
305 ExternalReferenceDecoder* external_reference_decoder_; 365 ExternalReferenceDecoder* external_reference_decoder_;
306 366
307 DISALLOW_COPY_AND_ASSIGN(Deserializer); 367 DISALLOW_COPY_AND_ASSIGN(Deserializer);
308 }; 368 };
309 369
310 370
371 class SnapshotByteSink {
372 public:
373 virtual ~SnapshotByteSink() { }
374 virtual void Put(int byte, const char* description) = 0;
375 virtual void PutSection(int byte, const char* description) {
376 Put(byte, description);
377 }
378 void PutInt(uintptr_t integer, const char* description);
379 virtual int Position() = 0;
380 };
381
382
311 // Mapping objects to their location after deserialization. 383 // Mapping objects to their location after deserialization.
312 // This is used during building, but not at runtime by V8. 384 // This is used during building, but not at runtime by V8.
313 class SerializationAddressMapper { 385 class SerializationAddressMapper {
314 public: 386 public:
315 SerializationAddressMapper() 387 SerializationAddressMapper()
316 : no_allocation_(), 388 : no_allocation_(),
317 serialization_map_(new HashMap(HashMap::PointersMatch)) { } 389 serialization_map_(new HashMap(HashMap::PointersMatch)) { }
318 390
319 ~SerializationAddressMapper() { 391 ~SerializationAddressMapper() {
320 delete serialization_map_; 392 delete serialization_map_;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 private: 629 private:
558 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 630 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
559 return false; 631 return false;
560 } 632 }
561 }; 633 };
562 634
563 635
564 } } // namespace v8::internal 636 } } // namespace v8::internal
565 637
566 #endif // V8_SERIALIZE_H_ 638 #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