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 RUNTIME_VM_SNAPSHOT_H_ | 5 #ifndef RUNTIME_VM_SNAPSHOT_H_ |
6 #define RUNTIME_VM_SNAPSHOT_H_ | 6 #define RUNTIME_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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 // Make room for recording snapshot buffer size. | 653 // Make room for recording snapshot buffer size. |
654 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 654 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
655 } | 655 } |
656 | 656 |
657 void FillHeader(Snapshot::Kind kind) { | 657 void FillHeader(Snapshot::Kind kind) { |
658 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); | 658 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
659 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 659 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
660 data[Snapshot::kSnapshotFlagIndex] = kind; | 660 data[Snapshot::kSnapshotFlagIndex] = kind; |
661 } | 661 } |
662 | 662 |
663 void FreeBuffer() { dealloc_(stream_.buffer()); } | 663 void FreeBuffer() { |
| 664 dealloc_(stream_.buffer()); |
| 665 stream_.set_buffer(NULL); |
| 666 } |
664 | 667 |
665 private: | 668 private: |
666 WriteStream stream_; | 669 WriteStream stream_; |
667 DeAlloc dealloc_; | 670 DeAlloc dealloc_; |
668 | 671 |
669 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 672 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
670 }; | 673 }; |
671 | 674 |
672 | 675 |
673 class ForwardList { | 676 class ForwardList { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 // Writes a partial snapshot of the script. | 972 // Writes a partial snapshot of the script. |
970 void WriteScriptSnapshot(const Library& lib); | 973 void WriteScriptSnapshot(const Library& lib); |
971 | 974 |
972 private: | 975 private: |
973 ForwardList forward_list_; | 976 ForwardList forward_list_; |
974 | 977 |
975 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 978 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
976 }; | 979 }; |
977 | 980 |
978 | 981 |
| 982 class SerializedObjectBuffer : public StackResource { |
| 983 public: |
| 984 SerializedObjectBuffer() |
| 985 : StackResource(Thread::Current()), |
| 986 object_data_(NULL), |
| 987 object_length_(0) {} |
| 988 |
| 989 virtual ~SerializedObjectBuffer() { free(object_data_); } |
| 990 |
| 991 void StealBuffer(uint8_t** out_data, intptr_t* out_length) { |
| 992 *out_data = object_data_; |
| 993 *out_length = object_length_; |
| 994 |
| 995 object_data_ = NULL; |
| 996 object_length_ = 0; |
| 997 } |
| 998 |
| 999 uint8_t** data_buffer() { return &object_data_; } |
| 1000 intptr_t* data_length() { return &object_length_; } |
| 1001 |
| 1002 private: |
| 1003 uint8_t* object_data_; |
| 1004 intptr_t object_length_; |
| 1005 }; |
| 1006 |
| 1007 |
979 class MessageWriter : public SnapshotWriter { | 1008 class MessageWriter : public SnapshotWriter { |
980 public: | 1009 public: |
981 static const intptr_t kInitialSize = 512; | 1010 static const intptr_t kInitialSize = 512; |
982 MessageWriter(uint8_t** buffer, | 1011 MessageWriter(uint8_t** buffer, |
983 ReAlloc alloc, | 1012 ReAlloc alloc, |
984 DeAlloc dealloc, | 1013 DeAlloc dealloc, |
985 bool can_send_any_object); | 1014 bool can_send_any_object, |
| 1015 intptr_t* buffer_len = NULL); |
986 ~MessageWriter() {} | 1016 ~MessageWriter() {} |
987 | 1017 |
988 void WriteMessage(const Object& obj); | 1018 void WriteMessage(const Object& obj); |
989 | 1019 |
990 private: | 1020 private: |
991 ForwardList forward_list_; | 1021 ForwardList forward_list_; |
| 1022 intptr_t* buffer_len_; |
992 | 1023 |
993 DISALLOW_COPY_AND_ASSIGN(MessageWriter); | 1024 DISALLOW_COPY_AND_ASSIGN(MessageWriter); |
994 }; | 1025 }; |
995 | 1026 |
996 | 1027 |
997 // An object pointer visitor implementation which writes out | 1028 // An object pointer visitor implementation which writes out |
998 // objects to a snap shot. | 1029 // objects to a snap shot. |
999 class SnapshotWriterVisitor : public ObjectPointerVisitor { | 1030 class SnapshotWriterVisitor : public ObjectPointerVisitor { |
1000 public: | 1031 public: |
1001 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references) | 1032 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references) |
1002 : ObjectPointerVisitor(Isolate::Current()), | 1033 : ObjectPointerVisitor(Isolate::Current()), |
1003 writer_(writer), | 1034 writer_(writer), |
1004 as_references_(as_references) {} | 1035 as_references_(as_references) {} |
1005 | 1036 |
1006 virtual void VisitPointers(RawObject** first, RawObject** last); | 1037 virtual void VisitPointers(RawObject** first, RawObject** last); |
1007 | 1038 |
1008 private: | 1039 private: |
1009 SnapshotWriter* writer_; | 1040 SnapshotWriter* writer_; |
1010 bool as_references_; | 1041 bool as_references_; |
1011 | 1042 |
1012 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1043 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1013 }; | 1044 }; |
1014 | 1045 |
1015 } // namespace dart | 1046 } // namespace dart |
1016 | 1047 |
1017 #endif // RUNTIME_VM_SNAPSHOT_H_ | 1048 #endif // RUNTIME_VM_SNAPSHOT_H_ |
OLD | NEW |