| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_SNAPSHOT_H_ | 5 #ifndef VM_SNAPSHOT_H_ |
| 6 #define VM_SNAPSHOT_H_ | 6 #define VM_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 friend class TypeParameter; | 421 friend class TypeParameter; |
| 422 friend class TypeRef; | 422 friend class TypeRef; |
| 423 friend class UnresolvedClass; | 423 friend class UnresolvedClass; |
| 424 friend class UnhandledException; | 424 friend class UnhandledException; |
| 425 friend class WeakProperty; | 425 friend class WeakProperty; |
| 426 friend class MirrorReference; | 426 friend class MirrorReference; |
| 427 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 427 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| 428 }; | 428 }; |
| 429 | 429 |
| 430 | 430 |
| 431 class BaseWriter { | 431 class BaseWriter : public StackResource { |
| 432 public: | 432 public: |
| 433 // Size of the snapshot. | 433 // Size of the snapshot. |
| 434 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 434 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| 435 | 435 |
| 436 // Writes raw data to the stream (basic type). | 436 // Writes raw data to the stream (basic type). |
| 437 // sizeof(T) must be in {1,2,4,8}. | 437 // sizeof(T) must be in {1,2,4,8}. |
| 438 template <typename T> | 438 template <typename T> |
| 439 void Write(T value) { | 439 void Write(T value) { |
| 440 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 440 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| 441 } | 441 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 stream_.WriteBytes(addr, len); | 489 stream_.WriteBytes(addr, len); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void WriteDouble(double value) { | 492 void WriteDouble(double value) { |
| 493 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value)); | 493 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value)); |
| 494 } | 494 } |
| 495 | 495 |
| 496 protected: | 496 protected: |
| 497 BaseWriter(uint8_t** buffer, | 497 BaseWriter(uint8_t** buffer, |
| 498 ReAlloc alloc, | 498 ReAlloc alloc, |
| 499 intptr_t initial_size) : stream_(buffer, alloc, initial_size) { | 499 intptr_t initial_size) |
| 500 : StackResource(Isolate::Current()), |
| 501 stream_(buffer, alloc, initial_size) { |
| 500 ASSERT(buffer != NULL); | 502 ASSERT(buffer != NULL); |
| 501 ASSERT(alloc != NULL); | 503 ASSERT(alloc != NULL); |
| 502 } | 504 } |
| 503 ~BaseWriter() { } | 505 ~BaseWriter() { } |
| 504 | 506 |
| 505 void ReserveHeader() { | 507 void ReserveHeader() { |
| 506 // Make room for recording snapshot buffer size. | 508 // Make room for recording snapshot buffer size. |
| 507 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 509 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
| 508 } | 510 } |
| 509 | 511 |
| 510 void FillHeader(Snapshot::Kind kind) { | 512 void FillHeader(Snapshot::Kind kind) { |
| 511 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); | 513 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
| 512 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 514 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
| 513 data[Snapshot::kSnapshotFlagIndex] = kind; | 515 data[Snapshot::kSnapshotFlagIndex] = kind; |
| 514 } | 516 } |
| 515 | 517 |
| 516 private: | 518 private: |
| 517 WriteStream stream_; | 519 WriteStream stream_; |
| 518 | 520 |
| 519 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 521 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
| 520 }; | 522 }; |
| 521 | 523 |
| 522 | 524 |
| 523 class ForwardList { | 525 class ForwardList { |
| 524 public: | 526 public: |
| 525 explicit ForwardList(intptr_t first_object_id) | 527 explicit ForwardList(intptr_t first_object_id); |
| 526 : first_object_id_(first_object_id), | 528 ~ForwardList(); |
| 527 nodes_(), | |
| 528 first_unprocessed_object_id_(first_object_id) {} | |
| 529 | 529 |
| 530 class Node : public ZoneAllocated { | 530 class Node : public ZoneAllocated { |
| 531 public: | 531 public: |
| 532 Node(RawObject* raw, uword tags, SerializeState state) | 532 Node(RawObject* raw, uword tags, SerializeState state) |
| 533 : raw_(raw), tags_(tags), state_(state) {} | 533 : raw_(raw), tags_(tags), state_(state) {} |
| 534 RawObject* raw() const { return raw_; } | 534 RawObject* raw() const { return raw_; } |
| 535 uword tags() const { return tags_; } | 535 uword tags() const { return tags_; } |
| 536 bool is_serialized() const { return state_ == kIsSerialized; } | 536 bool is_serialized() const { return state_ == kIsSerialized; } |
| 537 | 537 |
| 538 private: | 538 private: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 RawTypeArguments* type_arguments, | 624 RawTypeArguments* type_arguments, |
| 625 RawObject* data[]); | 625 RawObject* data[]); |
| 626 void CheckIfSerializable(RawClass* cls); | 626 void CheckIfSerializable(RawClass* cls); |
| 627 void SetWriteException(Exceptions::ExceptionType type, const char* msg); | 627 void SetWriteException(Exceptions::ExceptionType type, const char* msg); |
| 628 void WriteInstance(intptr_t object_id, | 628 void WriteInstance(intptr_t object_id, |
| 629 RawObject* raw, | 629 RawObject* raw, |
| 630 RawClass* cls, | 630 RawClass* cls, |
| 631 intptr_t tags); | 631 intptr_t tags); |
| 632 void WriteInstanceRef(RawObject* raw, RawClass* cls); | 632 void WriteInstanceRef(RawObject* raw, RawClass* cls); |
| 633 | 633 |
| 634 Isolate* isolate() const { return isolate_; } |
| 634 ObjectStore* object_store() const { return object_store_; } | 635 ObjectStore* object_store() const { return object_store_; } |
| 635 | 636 |
| 636 private: | 637 private: |
| 637 Snapshot::Kind kind_; | 638 Snapshot::Kind kind_; |
| 639 Isolate* isolate_; |
| 638 ObjectStore* object_store_; // Object store for common classes. | 640 ObjectStore* object_store_; // Object store for common classes. |
| 639 ClassTable* class_table_; // Class table for the class index to class lookup. | 641 ClassTable* class_table_; // Class table for the class index to class lookup. |
| 640 ForwardList forward_list_; | 642 ForwardList forward_list_; |
| 641 Exceptions::ExceptionType exception_type_; // Exception type. | 643 Exceptions::ExceptionType exception_type_; // Exception type. |
| 642 const char* exception_msg_; // Message associated with exception. | 644 const char* exception_msg_; // Message associated with exception. |
| 643 | 645 |
| 644 friend class RawArray; | 646 friend class RawArray; |
| 645 friend class RawClass; | 647 friend class RawClass; |
| 646 friend class RawClosureData; | 648 friend class RawClosureData; |
| 647 friend class RawGrowableObjectArray; | 649 friend class RawGrowableObjectArray; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 private: | 737 private: |
| 736 SnapshotWriter* writer_; | 738 SnapshotWriter* writer_; |
| 737 bool as_references_; | 739 bool as_references_; |
| 738 | 740 |
| 739 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 741 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 740 }; | 742 }; |
| 741 | 743 |
| 742 } // namespace dart | 744 } // namespace dart |
| 743 | 745 |
| 744 #endif // VM_SNAPSHOT_H_ | 746 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |