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 "platform/utils.h" |
9 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
10 #include "vm/bitfield.h" | 11 #include "vm/bitfield.h" |
11 #include "vm/datastream.h" | 12 #include "vm/datastream.h" |
12 #include "vm/exceptions.h" | 13 #include "vm/exceptions.h" |
13 #include "vm/globals.h" | 14 #include "vm/globals.h" |
14 #include "vm/growable_array.h" | 15 #include "vm/growable_array.h" |
15 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
16 #include "vm/visitor.h" | 17 #include "vm/visitor.h" |
17 | 18 |
18 namespace dart { | 19 namespace dart { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 }; | 136 }; |
136 | 137 |
137 static const int kHeaderSize = 2 * sizeof(int64_t); | 138 static const int kHeaderSize = 2 * sizeof(int64_t); |
138 static const int kLengthIndex = 0; | 139 static const int kLengthIndex = 0; |
139 static const int kSnapshotFlagIndex = 1; | 140 static const int kSnapshotFlagIndex = 1; |
140 | 141 |
141 static const Snapshot* SetupFromBuffer(const void* raw_memory); | 142 static const Snapshot* SetupFromBuffer(const void* raw_memory); |
142 | 143 |
143 // Getters. | 144 // Getters. |
144 const uint8_t* content() const { return content_; } | 145 const uint8_t* content() const { return content_; } |
145 intptr_t length() const { return static_cast<intptr_t>(length_); } | 146 intptr_t length() const { |
146 Kind kind() const { return static_cast<Kind>(kind_); } | 147 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_)); |
| 148 } |
| 149 Kind kind() const { |
| 150 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); |
| 151 } |
147 | 152 |
148 bool IsMessageSnapshot() const { return kind_ == kMessage; } | 153 bool IsMessageSnapshot() const { return kind() == kMessage; } |
149 bool IsScriptSnapshot() const { return kind_ == kScript; } | 154 bool IsScriptSnapshot() const { return kind() == kScript; } |
150 bool IsFullSnapshot() const { return kind_ == kFull; } | 155 bool IsFullSnapshot() const { return kind() == kFull; } |
151 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } | 156 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } |
152 | 157 |
153 static intptr_t length_offset() { return OFFSET_OF(Snapshot, length_); } | 158 static intptr_t length_offset() { |
| 159 return OFFSET_OF(Snapshot, unaligned_length_); |
| 160 } |
154 static intptr_t kind_offset() { | 161 static intptr_t kind_offset() { |
155 return OFFSET_OF(Snapshot, kind_); | 162 return OFFSET_OF(Snapshot, unaligned_kind_); |
156 } | 163 } |
157 | 164 |
158 private: | 165 private: |
159 Snapshot() : length_(0), kind_(kFull) {} | 166 // Prevent Snapshot from ever being allocated directly. |
| 167 Snapshot(); |
160 | 168 |
161 int64_t length_; // Stream length. | 169 // The following fields are potentially unaligned. |
162 int64_t kind_; // Kind of snapshot. | 170 int64_t unaligned_length_; // Stream length. |
| 171 int64_t unaligned_kind_; // Kind of snapshot. |
163 uint8_t content_[]; // Stream content. | 172 uint8_t content_[]; // Stream content. |
164 | 173 |
165 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 174 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
166 }; | 175 }; |
167 | 176 |
168 | 177 |
169 class BaseReader { | 178 class BaseReader { |
170 public: | 179 public: |
171 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} | 180 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} |
172 // Reads raw data (for basic types). | 181 // Reads raw data (for basic types). |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 private: | 714 private: |
706 SnapshotWriter* writer_; | 715 SnapshotWriter* writer_; |
707 bool as_references_; | 716 bool as_references_; |
708 | 717 |
709 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 718 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
710 }; | 719 }; |
711 | 720 |
712 } // namespace dart | 721 } // namespace dart |
713 | 722 |
714 #endif // VM_SNAPSHOT_H_ | 723 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |