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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 449 } |
450 | 450 |
451 DisallowHeapAllocation no_allocation_; | 451 DisallowHeapAllocation no_allocation_; |
452 HashMap* serialization_map_; | 452 HashMap* serialization_map_; |
453 DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); | 453 DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); |
454 }; | 454 }; |
455 | 455 |
456 | 456 |
457 class CodeAddressMap; | 457 class CodeAddressMap; |
458 | 458 |
| 459 enum SerializationState { |
| 460 SERIALIZER_STATE_DISABLED = 0, |
| 461 SERIALIZER_STATE_ENABLED = 1, |
| 462 SERIALIZER_STATE_PERMANENTLY_DISABLED = 2 |
| 463 }; |
| 464 |
459 // There can be only one serializer per V8 process. | 465 // There can be only one serializer per V8 process. |
460 class Serializer : public SerializerDeserializer { | 466 class Serializer : public SerializerDeserializer { |
461 public: | 467 public: |
462 Serializer(Isolate* isolate, SnapshotByteSink* sink); | 468 Serializer(Isolate* isolate, SnapshotByteSink* sink); |
463 ~Serializer(); | 469 ~Serializer(); |
464 void VisitPointers(Object** start, Object** end); | 470 void VisitPointers(Object** start, Object** end); |
465 // You can call this after serialization to find out how much space was used | 471 // You can call this after serialization to find out how much space was used |
466 // in each space. | 472 // in each space. |
467 int CurrentAllocationAddress(int space) { | 473 int CurrentAllocationAddress(int space) { |
468 ASSERT(space < kNumberOfSpaces); | 474 ASSERT(space < kNumberOfSpaces); |
469 return fullness_[space]; | 475 return fullness_[space]; |
470 } | 476 } |
471 | 477 |
472 Isolate* isolate() const { return isolate_; } | 478 Isolate* isolate() const { return isolate_; } |
473 static void Enable(Isolate* isolate); | 479 static void Enable(Isolate* isolate); |
474 static void Disable(); | 480 static void Disable(); |
475 | 481 |
476 // Call this when you have made use of the fact that there is no serialization | 482 // Call this when you have made use of the fact that there is no serialization |
477 // going on. | 483 // going on. Returns true if serialization was disabled, and now it's |
478 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } | 484 // permanetely disabled. |
479 static bool enabled() { return serialization_enabled_; } | 485 static bool TrySetPermanentlyDisabled() { |
| 486 LockGuard<Mutex> lock_guard(&serialization_mutex_); |
| 487 // Changes are only made under the lock. |
| 488 if (serialization_state_ == SERIALIZER_STATE_DISABLED) { |
| 489 serialization_state_ = SERIALIZER_STATE_PERMANENTLY_DISABLED; |
| 490 return true; |
| 491 } |
| 492 return false; |
| 493 } |
| 494 static bool IsPermanentlyDisabled() { |
| 495 LockGuard<Mutex> lock_guard(&serialization_mutex_); |
| 496 return serialization_state_ == |
| 497 SERIALIZER_STATE_PERMANENTLY_DISABLED; |
| 498 } |
| 499 static bool enabled() { |
| 500 LockGuard<Mutex> lock_guard(&serialization_mutex_); |
| 501 return serialization_state_ == SERIALIZER_STATE_ENABLED; |
| 502 } |
480 SerializationAddressMapper* address_mapper() { return &address_mapper_; } | 503 SerializationAddressMapper* address_mapper() { return &address_mapper_; } |
481 void PutRoot(int index, | 504 void PutRoot(int index, |
482 HeapObject* object, | 505 HeapObject* object, |
483 HowToCode how, | 506 HowToCode how, |
484 WhereToPoint where, | 507 WhereToPoint where, |
485 int skip); | 508 int skip); |
486 | 509 |
487 protected: | 510 protected: |
488 static const int kInvalidRootIndex = -1; | 511 static const int kInvalidRootIndex = -1; |
489 | 512 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 // Some roots should not be serialized, because their actual value depends on | 590 // Some roots should not be serialized, because their actual value depends on |
568 // absolute addresses and they are reset after deserialization, anyway. | 591 // absolute addresses and they are reset after deserialization, anyway. |
569 bool ShouldBeSkipped(Object** current); | 592 bool ShouldBeSkipped(Object** current); |
570 | 593 |
571 Isolate* isolate_; | 594 Isolate* isolate_; |
572 // Keep track of the fullness of each space in order to generate | 595 // Keep track of the fullness of each space in order to generate |
573 // relative addresses for back references. | 596 // relative addresses for back references. |
574 int fullness_[LAST_SPACE + 1]; | 597 int fullness_[LAST_SPACE + 1]; |
575 SnapshotByteSink* sink_; | 598 SnapshotByteSink* sink_; |
576 ExternalReferenceEncoder* external_reference_encoder_; | 599 ExternalReferenceEncoder* external_reference_encoder_; |
577 static bool serialization_enabled_; | 600 |
578 // Did we already make use of the fact that serialization was not enabled? | 601 static Mutex serialization_mutex_; |
579 static bool too_late_to_enable_now_; | 602 static SerializationState serialization_state_; |
| 603 |
580 SerializationAddressMapper address_mapper_; | 604 SerializationAddressMapper address_mapper_; |
581 intptr_t root_index_wave_front_; | 605 intptr_t root_index_wave_front_; |
582 void Pad(); | 606 void Pad(); |
583 | 607 |
584 friend class ObjectSerializer; | 608 friend class ObjectSerializer; |
585 friend class Deserializer; | 609 friend class Deserializer; |
586 | 610 |
587 private: | 611 private: |
588 static CodeAddressMap* code_address_map_; | 612 static CodeAddressMap* code_address_map_; |
589 DISALLOW_COPY_AND_ASSIGN(Serializer); | 613 DISALLOW_COPY_AND_ASSIGN(Serializer); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 private: | 681 private: |
658 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 682 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
659 return false; | 683 return false; |
660 } | 684 } |
661 }; | 685 }; |
662 | 686 |
663 | 687 |
664 } } // namespace v8::internal | 688 } } // namespace v8::internal |
665 | 689 |
666 #endif // V8_SERIALIZE_H_ | 690 #endif // V8_SERIALIZE_H_ |
OLD | NEW |