| OLD | NEW |
| 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 "hashmap.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 Address address(int i) { return refs_[i].address; } | 53 Address address(int i) { return refs_[i].address; } |
| 54 | 54 |
| 55 uint32_t code(int i) { return refs_[i].code; } | 55 uint32_t code(int i) { return refs_[i].code; } |
| 56 | 56 |
| 57 const char* name(int i) { return refs_[i].name; } | 57 const char* name(int i) { return refs_[i].name; } |
| 58 | 58 |
| 59 int max_id(int code) { return max_id_[code]; } | 59 int max_id(int code) { return max_id_[code]; } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) { | 62 explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) { |
| 63 PopulateTable(isolate); | 63 PopulateTable(isolate); |
| 64 } | 64 } |
| 65 | 65 |
| 66 struct ExternalReferenceEntry { | 66 struct ExternalReferenceEntry { |
| 67 Address address; | 67 Address address; |
| 68 uint32_t code; | 68 uint32_t code; |
| 69 const char* name; | 69 const char* name; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 void PopulateTable(Isolate* isolate); | 72 void PopulateTable(Isolate* isolate); |
| 73 | 73 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 ~Serializer(); | 440 ~Serializer(); |
| 441 void VisitPointers(Object** start, Object** end); | 441 void VisitPointers(Object** start, Object** end); |
| 442 // You can call this after serialization to find out how much space was used | 442 // You can call this after serialization to find out how much space was used |
| 443 // in each space. | 443 // in each space. |
| 444 int CurrentAllocationAddress(int space) const { | 444 int CurrentAllocationAddress(int space) const { |
| 445 ASSERT(space < kNumberOfSpaces); | 445 ASSERT(space < kNumberOfSpaces); |
| 446 return fullness_[space]; | 446 return fullness_[space]; |
| 447 } | 447 } |
| 448 | 448 |
| 449 Isolate* isolate() const { return isolate_; } | 449 Isolate* isolate() const { return isolate_; } |
| 450 static void RequestEnable(Isolate* isolate); | |
| 451 static void InitializeOncePerProcess(); | |
| 452 static void TearDown(); | |
| 453 | 450 |
| 454 static bool enabled(Isolate* isolate) { | |
| 455 SerializationState state = static_cast<SerializationState>( | |
| 456 NoBarrier_Load(&serialization_state_)); | |
| 457 ASSERT(state != SERIALIZER_STATE_UNINITIALIZED); | |
| 458 return state == SERIALIZER_STATE_ENABLED; | |
| 459 } | |
| 460 SerializationAddressMapper* address_mapper() { return &address_mapper_; } | 451 SerializationAddressMapper* address_mapper() { return &address_mapper_; } |
| 461 void PutRoot(int index, | 452 void PutRoot(int index, |
| 462 HeapObject* object, | 453 HeapObject* object, |
| 463 HowToCode how, | 454 HowToCode how, |
| 464 WhereToPoint where, | 455 WhereToPoint where, |
| 465 int skip); | 456 int skip); |
| 466 | 457 |
| 467 protected: | 458 protected: |
| 468 static const int kInvalidRootIndex = -1; | 459 static const int kInvalidRootIndex = -1; |
| 469 | 460 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // absolute addresses and they are reset after deserialization, anyway. | 539 // absolute addresses and they are reset after deserialization, anyway. |
| 549 bool ShouldBeSkipped(Object** current); | 540 bool ShouldBeSkipped(Object** current); |
| 550 | 541 |
| 551 Isolate* isolate_; | 542 Isolate* isolate_; |
| 552 // Keep track of the fullness of each space in order to generate | 543 // Keep track of the fullness of each space in order to generate |
| 553 // relative addresses for back references. | 544 // relative addresses for back references. |
| 554 int fullness_[LAST_SPACE + 1]; | 545 int fullness_[LAST_SPACE + 1]; |
| 555 SnapshotByteSink* sink_; | 546 SnapshotByteSink* sink_; |
| 556 ExternalReferenceEncoder* external_reference_encoder_; | 547 ExternalReferenceEncoder* external_reference_encoder_; |
| 557 | 548 |
| 558 enum SerializationState { | |
| 559 SERIALIZER_STATE_UNINITIALIZED = 0, | |
| 560 SERIALIZER_STATE_DISABLED = 1, | |
| 561 SERIALIZER_STATE_ENABLED = 2 | |
| 562 }; | |
| 563 | |
| 564 static AtomicWord serialization_state_; | |
| 565 | |
| 566 SerializationAddressMapper address_mapper_; | 549 SerializationAddressMapper address_mapper_; |
| 567 intptr_t root_index_wave_front_; | 550 intptr_t root_index_wave_front_; |
| 568 void Pad(); | 551 void Pad(); |
| 569 | 552 |
| 570 friend class ObjectSerializer; | 553 friend class ObjectSerializer; |
| 571 friend class Deserializer; | 554 friend class Deserializer; |
| 572 | 555 |
| 556 // We may not need the code address map for logging for every instance |
| 557 // of the serializer. Initialize it on demand. |
| 558 void InitializeCodeAddressMap(); |
| 559 |
| 573 private: | 560 private: |
| 574 static CodeAddressMap* code_address_map_; | 561 CodeAddressMap* code_address_map_; |
| 575 DISALLOW_COPY_AND_ASSIGN(Serializer); | 562 DISALLOW_COPY_AND_ASSIGN(Serializer); |
| 576 }; | 563 }; |
| 577 | 564 |
| 578 | 565 |
| 579 class PartialSerializer : public Serializer { | 566 class PartialSerializer : public Serializer { |
| 580 public: | 567 public: |
| 581 PartialSerializer(Isolate* isolate, | 568 PartialSerializer(Isolate* isolate, |
| 582 Serializer* startup_snapshot_serializer, | 569 Serializer* startup_snapshot_serializer, |
| 583 SnapshotByteSink* sink) | 570 SnapshotByteSink* sink) |
| 584 : Serializer(isolate, sink), | 571 : Serializer(isolate, sink), |
| 585 startup_serializer_(startup_snapshot_serializer) { | 572 startup_serializer_(startup_snapshot_serializer) { |
| 586 set_root_index_wave_front(Heap::kStrongRootListLength); | 573 set_root_index_wave_front(Heap::kStrongRootListLength); |
| 574 InitializeCodeAddressMap(); |
| 587 } | 575 } |
| 588 | 576 |
| 589 // Serialize the objects reachable from a single object pointer. | 577 // Serialize the objects reachable from a single object pointer. |
| 590 virtual void Serialize(Object** o); | 578 virtual void Serialize(Object** o); |
| 591 virtual void SerializeObject(Object* o, | 579 virtual void SerializeObject(Object* o, |
| 592 HowToCode how_to_code, | 580 HowToCode how_to_code, |
| 593 WhereToPoint where_to_point, | 581 WhereToPoint where_to_point, |
| 594 int skip); | 582 int skip); |
| 595 | 583 |
| 596 protected: | 584 protected: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 616 | 604 |
| 617 class StartupSerializer : public Serializer { | 605 class StartupSerializer : public Serializer { |
| 618 public: | 606 public: |
| 619 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) | 607 StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) |
| 620 : Serializer(isolate, sink) { | 608 : Serializer(isolate, sink) { |
| 621 // Clear the cache of objects used by the partial snapshot. After the | 609 // Clear the cache of objects used by the partial snapshot. After the |
| 622 // strong roots have been serialized we can create a partial snapshot | 610 // strong roots have been serialized we can create a partial snapshot |
| 623 // which will repopulate the cache with objects needed by that partial | 611 // which will repopulate the cache with objects needed by that partial |
| 624 // snapshot. | 612 // snapshot. |
| 625 isolate->set_serialize_partial_snapshot_cache_length(0); | 613 isolate->set_serialize_partial_snapshot_cache_length(0); |
| 614 InitializeCodeAddressMap(); |
| 626 } | 615 } |
| 627 // Serialize the current state of the heap. The order is: | 616 // Serialize the current state of the heap. The order is: |
| 628 // 1) Strong references. | 617 // 1) Strong references. |
| 629 // 2) Partial snapshot cache. | 618 // 2) Partial snapshot cache. |
| 630 // 3) Weak references (e.g. the string table). | 619 // 3) Weak references (e.g. the string table). |
| 631 virtual void SerializeStrongReferences(); | 620 virtual void SerializeStrongReferences(); |
| 632 virtual void SerializeObject(Object* o, | 621 virtual void SerializeObject(Object* o, |
| 633 HowToCode how_to_code, | 622 HowToCode how_to_code, |
| 634 WhereToPoint where_to_point, | 623 WhereToPoint where_to_point, |
| 635 int skip); | 624 int skip); |
| 636 void SerializeWeakReferences(); | 625 void SerializeWeakReferences(); |
| 637 void Serialize() { | 626 void Serialize() { |
| 638 SerializeStrongReferences(); | 627 SerializeStrongReferences(); |
| 639 SerializeWeakReferences(); | 628 SerializeWeakReferences(); |
| 640 Pad(); | 629 Pad(); |
| 641 } | 630 } |
| 642 | 631 |
| 643 private: | 632 private: |
| 644 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 633 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
| 645 return false; | 634 return false; |
| 646 } | 635 } |
| 647 }; | 636 }; |
| 648 | 637 |
| 649 | 638 |
| 650 } } // namespace v8::internal | 639 } } // namespace v8::internal |
| 651 | 640 |
| 652 #endif // V8_SERIALIZE_H_ | 641 #endif // V8_SERIALIZE_H_ |
| OLD | NEW |