OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 // For other types of references, the caller will figure out the address. | 103 // For other types of references, the caller will figure out the address. |
104 void Add(Address address, TypeCode type, uint16_t id, const char* name); | 104 void Add(Address address, TypeCode type, uint16_t id, const char* name); |
105 | 105 |
106 List<ExternalReferenceEntry> refs_; | 106 List<ExternalReferenceEntry> refs_; |
107 int max_id_[kTypeCodeCount]; | 107 int max_id_[kTypeCodeCount]; |
108 }; | 108 }; |
109 | 109 |
110 | 110 |
111 class ExternalReferenceEncoder { | 111 class ExternalReferenceEncoder { |
112 public: | 112 public: |
113 ExternalReferenceEncoder(); | 113 explicit ExternalReferenceEncoder(Isolate* isolate); |
114 | 114 |
115 uint32_t Encode(Address key) const; | 115 uint32_t Encode(Address key) const; |
116 | 116 |
117 const char* NameOfAddress(Address key) const; | 117 const char* NameOfAddress(Address key) const; |
118 | 118 |
119 private: | 119 private: |
120 HashMap encodings_; | 120 HashMap encodings_; |
121 static uint32_t Hash(Address key) { | 121 static uint32_t Hash(Address key) { |
122 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2); | 122 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2); |
123 } | 123 } |
124 | 124 |
125 int IndexOf(Address key) const; | 125 int IndexOf(Address key) const; |
126 | 126 |
127 static bool Match(void* key1, void* key2) { return key1 == key2; } | 127 static bool Match(void* key1, void* key2) { return key1 == key2; } |
128 | 128 |
129 void Put(Address key, int index); | 129 void Put(Address key, int index); |
130 | 130 |
131 Isolate* isolate_; | 131 Isolate* isolate_; |
132 }; | 132 }; |
133 | 133 |
134 | 134 |
135 class ExternalReferenceDecoder { | 135 class ExternalReferenceDecoder { |
136 public: | 136 public: |
137 ExternalReferenceDecoder(); | 137 explicit ExternalReferenceDecoder(Isolate* isolate); |
138 ~ExternalReferenceDecoder(); | 138 ~ExternalReferenceDecoder(); |
139 | 139 |
140 Address Decode(uint32_t key) const { | 140 Address Decode(uint32_t key) const { |
141 if (key == 0) return NULL; | 141 if (key == 0) return NULL; |
142 return *Lookup(key); | 142 return *Lookup(key); |
143 } | 143 } |
144 | 144 |
145 private: | 145 private: |
146 Address** encodings_; | 146 Address** encodings_; |
147 | 147 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 int length_; | 201 int length_; |
202 int position_; | 202 int position_; |
203 }; | 203 }; |
204 | 204 |
205 | 205 |
206 // The Serializer/Deserializer class is a common superclass for Serializer and | 206 // The Serializer/Deserializer class is a common superclass for Serializer and |
207 // Deserializer which is used to store common constants and methods used by | 207 // Deserializer which is used to store common constants and methods used by |
208 // both. | 208 // both. |
209 class SerializerDeserializer: public ObjectVisitor { | 209 class SerializerDeserializer: public ObjectVisitor { |
210 public: | 210 public: |
211 static void Iterate(ObjectVisitor* visitor); | 211 static void Iterate(Isolate* isolate, ObjectVisitor* visitor); |
212 | 212 |
213 static int nop() { return kNop; } | 213 static int nop() { return kNop; } |
214 | 214 |
215 protected: | 215 protected: |
216 // Where the pointed-to object can be found: | 216 // Where the pointed-to object can be found: |
217 enum Where { | 217 enum Where { |
218 kNewObject = 0, // Object is next in snapshot. | 218 kNewObject = 0, // Object is next in snapshot. |
219 // 1-6 One per space. | 219 // 1-6 One per space. |
220 kRootArray = 0x9, // Object is found in root array. | 220 kRootArray = 0x9, // Object is found in root array. |
221 kPartialSnapshotCache = 0xa, // Object is in the cache. | 221 kPartialSnapshotCache = 0xa, // Object is in the cache. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 | 318 |
319 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. | 319 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. |
320 class Deserializer: public SerializerDeserializer { | 320 class Deserializer: public SerializerDeserializer { |
321 public: | 321 public: |
322 // Create a deserializer from a snapshot byte source. | 322 // Create a deserializer from a snapshot byte source. |
323 explicit Deserializer(SnapshotByteSource* source); | 323 explicit Deserializer(SnapshotByteSource* source); |
324 | 324 |
325 virtual ~Deserializer(); | 325 virtual ~Deserializer(); |
326 | 326 |
327 // Deserialize the snapshot into an empty heap. | 327 // Deserialize the snapshot into an empty heap. |
328 void Deserialize(); | 328 void Deserialize(Isolate* isolate); |
329 | 329 |
330 // Deserialize a single object and the objects reachable from it. | 330 // Deserialize a single object and the objects reachable from it. |
331 void DeserializePartial(Object** root); | 331 void DeserializePartial(Isolate* isolate, Object** root); |
332 | 332 |
333 void set_reservation(int space_number, int reservation) { | 333 void set_reservation(int space_number, int reservation) { |
334 ASSERT(space_number >= 0); | 334 ASSERT(space_number >= 0); |
335 ASSERT(space_number <= LAST_SPACE); | 335 ASSERT(space_number <= LAST_SPACE); |
336 reservations_[space_number] = reservation; | 336 reservations_[space_number] = reservation; |
337 } | 337 } |
338 | 338 |
339 private: | 339 private: |
340 virtual void VisitPointers(Object** start, Object** end); | 340 virtual void VisitPointers(Object** start, Object** end); |
341 | 341 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 HashMap* serialization_map_; | 457 HashMap* serialization_map_; |
458 DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); | 458 DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); |
459 }; | 459 }; |
460 | 460 |
461 | 461 |
462 class CodeAddressMap; | 462 class CodeAddressMap; |
463 | 463 |
464 // There can be only one serializer per V8 process. | 464 // There can be only one serializer per V8 process. |
465 class Serializer : public SerializerDeserializer { | 465 class Serializer : public SerializerDeserializer { |
466 public: | 466 public: |
467 explicit Serializer(SnapshotByteSink* sink); | 467 Serializer(Isolate* isolate, SnapshotByteSink* sink); |
468 ~Serializer(); | 468 ~Serializer(); |
469 void VisitPointers(Object** start, Object** end); | 469 void VisitPointers(Object** start, Object** end); |
470 // You can call this after serialization to find out how much space was used | 470 // You can call this after serialization to find out how much space was used |
471 // in each space. | 471 // in each space. |
472 int CurrentAllocationAddress(int space) { | 472 int CurrentAllocationAddress(int space) { |
473 ASSERT(space < kNumberOfSpaces); | 473 ASSERT(space < kNumberOfSpaces); |
474 return fullness_[space]; | 474 return fullness_[space]; |
475 } | 475 } |
476 | 476 |
477 static void Enable(); | 477 Isolate* isolate() { return isolate_; } |
Sven Panne
2013/09/03 11:38:56
const
| |
478 static void Enable(Isolate* isolate); | |
478 static void Disable(); | 479 static void Disable(); |
479 | 480 |
480 // Call this when you have made use of the fact that there is no serialization | 481 // Call this when you have made use of the fact that there is no serialization |
481 // going on. | 482 // going on. |
482 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } | 483 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } |
483 static bool enabled() { return serialization_enabled_; } | 484 static bool enabled() { return serialization_enabled_; } |
484 SerializationAddressMapper* address_mapper() { return &address_mapper_; } | 485 SerializationAddressMapper* address_mapper() { return &address_mapper_; } |
485 void PutRoot(int index, | 486 void PutRoot(int index, |
486 HeapObject* object, | 487 HeapObject* object, |
487 HowToCode how, | 488 HowToCode how, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 friend class Deserializer; | 587 friend class Deserializer; |
587 | 588 |
588 private: | 589 private: |
589 static CodeAddressMap* code_address_map_; | 590 static CodeAddressMap* code_address_map_; |
590 DISALLOW_COPY_AND_ASSIGN(Serializer); | 591 DISALLOW_COPY_AND_ASSIGN(Serializer); |
591 }; | 592 }; |
592 | 593 |
593 | 594 |
594 class PartialSerializer : public Serializer { | 595 class PartialSerializer : public Serializer { |
595 public: | 596 public: |
596 PartialSerializer(Serializer* startup_snapshot_serializer, | 597 PartialSerializer(Isolate* isolate, |
598 Serializer* startup_snapshot_serializer, | |
597 SnapshotByteSink* sink) | 599 SnapshotByteSink* sink) |
598 : Serializer(sink), | 600 : Serializer(isolate, sink), |
599 startup_serializer_(startup_snapshot_serializer) { | 601 startup_serializer_(startup_snapshot_serializer) { |
600 set_root_index_wave_front(Heap::kStrongRootListLength); | 602 set_root_index_wave_front(Heap::kStrongRootListLength); |
601 } | 603 } |
602 | 604 |
603 // Serialize the objects reachable from a single object pointer. | 605 // Serialize the objects reachable from a single object pointer. |
604 virtual void Serialize(Object** o); | 606 virtual void Serialize(Object** o); |
605 virtual void SerializeObject(Object* o, | 607 virtual void SerializeObject(Object* o, |
606 HowToCode how_to_code, | 608 HowToCode how_to_code, |
607 WhereToPoint where_to_point, | 609 WhereToPoint where_to_point, |
608 int skip); | 610 int skip); |
(...skipping 13 matching lines...) Expand all Loading... | |
622 } | 624 } |
623 | 625 |
624 private: | 626 private: |
625 Serializer* startup_serializer_; | 627 Serializer* startup_serializer_; |
626 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); | 628 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); |
627 }; | 629 }; |
628 | 630 |
629 | 631 |
630 class StartupSerializer : public Serializer { | 632 class StartupSerializer : public Serializer { |
631 public: | 633 public: |
632 explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { | 634 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) |
635 : Serializer(isolate, sink) { | |
633 // Clear the cache of objects used by the partial snapshot. After the | 636 // Clear the cache of objects used by the partial snapshot. After the |
634 // strong roots have been serialized we can create a partial snapshot | 637 // strong roots have been serialized we can create a partial snapshot |
635 // which will repopulate the cache with objects needed by that partial | 638 // which will repopulate the cache with objects needed by that partial |
636 // snapshot. | 639 // snapshot. |
637 Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); | 640 isolate->set_serialize_partial_snapshot_cache_length(0); |
638 } | 641 } |
639 // Serialize the current state of the heap. The order is: | 642 // Serialize the current state of the heap. The order is: |
640 // 1) Strong references. | 643 // 1) Strong references. |
641 // 2) Partial snapshot cache. | 644 // 2) Partial snapshot cache. |
642 // 3) Weak references (e.g. the string table). | 645 // 3) Weak references (e.g. the string table). |
643 virtual void SerializeStrongReferences(); | 646 virtual void SerializeStrongReferences(); |
644 virtual void SerializeObject(Object* o, | 647 virtual void SerializeObject(Object* o, |
645 HowToCode how_to_code, | 648 HowToCode how_to_code, |
646 WhereToPoint where_to_point, | 649 WhereToPoint where_to_point, |
647 int skip); | 650 int skip); |
648 void SerializeWeakReferences(); | 651 void SerializeWeakReferences(); |
649 void Serialize() { | 652 void Serialize() { |
650 SerializeStrongReferences(); | 653 SerializeStrongReferences(); |
651 SerializeWeakReferences(); | 654 SerializeWeakReferences(); |
652 Pad(); | 655 Pad(); |
653 } | 656 } |
654 | 657 |
655 private: | 658 private: |
656 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 659 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
657 return false; | 660 return false; |
658 } | 661 } |
659 }; | 662 }; |
660 | 663 |
661 | 664 |
662 } } // namespace v8::internal | 665 } } // namespace v8::internal |
663 | 666 |
664 #endif // V8_SERIALIZE_H_ | 667 #endif // V8_SERIALIZE_H_ |
OLD | NEW |