Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: runtime/vm/snapshot.h

Issue 2654443003: Revert "VM: Fix memory leaks during isolate spawning" (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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() { 663 void FreeBuffer() { dealloc_(stream_.buffer()); }
664 dealloc_(stream_.buffer());
665 stream_.set_buffer(NULL);
666 }
667 664
668 private: 665 private:
669 WriteStream stream_; 666 WriteStream stream_;
670 DeAlloc dealloc_; 667 DeAlloc dealloc_;
671 668
672 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); 669 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter);
673 }; 670 };
674 671
675 672
676 class ForwardList { 673 class ForwardList {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 // Writes a partial snapshot of the script. 969 // Writes a partial snapshot of the script.
973 void WriteScriptSnapshot(const Library& lib); 970 void WriteScriptSnapshot(const Library& lib);
974 971
975 private: 972 private:
976 ForwardList forward_list_; 973 ForwardList forward_list_;
977 974
978 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); 975 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter);
979 }; 976 };
980 977
981 978
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
1008 class MessageWriter : public SnapshotWriter { 979 class MessageWriter : public SnapshotWriter {
1009 public: 980 public:
1010 static const intptr_t kInitialSize = 512; 981 static const intptr_t kInitialSize = 512;
1011 MessageWriter(uint8_t** buffer, 982 MessageWriter(uint8_t** buffer,
1012 ReAlloc alloc, 983 ReAlloc alloc,
1013 DeAlloc dealloc, 984 DeAlloc dealloc,
1014 bool can_send_any_object, 985 bool can_send_any_object);
1015 intptr_t* buffer_len = NULL);
1016 ~MessageWriter() {} 986 ~MessageWriter() {}
1017 987
1018 void WriteMessage(const Object& obj); 988 void WriteMessage(const Object& obj);
1019 989
1020 private: 990 private:
1021 ForwardList forward_list_; 991 ForwardList forward_list_;
1022 intptr_t* buffer_len_;
1023 992
1024 DISALLOW_COPY_AND_ASSIGN(MessageWriter); 993 DISALLOW_COPY_AND_ASSIGN(MessageWriter);
1025 }; 994 };
1026 995
1027 996
1028 // An object pointer visitor implementation which writes out 997 // An object pointer visitor implementation which writes out
1029 // objects to a snap shot. 998 // objects to a snap shot.
1030 class SnapshotWriterVisitor : public ObjectPointerVisitor { 999 class SnapshotWriterVisitor : public ObjectPointerVisitor {
1031 public: 1000 public:
1032 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references) 1001 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references)
1033 : ObjectPointerVisitor(Isolate::Current()), 1002 : ObjectPointerVisitor(Isolate::Current()),
1034 writer_(writer), 1003 writer_(writer),
1035 as_references_(as_references) {} 1004 as_references_(as_references) {}
1036 1005
1037 virtual void VisitPointers(RawObject** first, RawObject** last); 1006 virtual void VisitPointers(RawObject** first, RawObject** last);
1038 1007
1039 private: 1008 private:
1040 SnapshotWriter* writer_; 1009 SnapshotWriter* writer_;
1041 bool as_references_; 1010 bool as_references_;
1042 1011
1043 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 1012 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
1044 }; 1013 };
1045 1014
1046 } // namespace dart 1015 } // namespace dart
1047 1016
1048 #endif // RUNTIME_VM_SNAPSHOT_H_ 1017 #endif // RUNTIME_VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698