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

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

Issue 604553003: Don't use the size-zero array hack to access variable data in Snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | 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 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 kMessage, // A partial snapshot used only for isolate messaging. 138 kMessage, // A partial snapshot used only for isolate messaging.
139 }; 139 };
140 140
141 static const int kHeaderSize = 2 * sizeof(int64_t); 141 static const int kHeaderSize = 2 * sizeof(int64_t);
142 static const int kLengthIndex = 0; 142 static const int kLengthIndex = 0;
143 static const int kSnapshotFlagIndex = 1; 143 static const int kSnapshotFlagIndex = 1;
144 144
145 static const Snapshot* SetupFromBuffer(const void* raw_memory); 145 static const Snapshot* SetupFromBuffer(const void* raw_memory);
146 146
147 // Getters. 147 // Getters.
148 const uint8_t* content() const { return content_; }
149 intptr_t length() const { 148 intptr_t length() const {
150 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_)); 149 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_));
151 } 150 }
152 Kind kind() const { 151 Kind kind() const {
153 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); 152 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_));
154 } 153 }
155 154
156 bool IsMessageSnapshot() const { return kind() == kMessage; } 155 bool IsMessageSnapshot() const { return kind() == kMessage; }
157 bool IsScriptSnapshot() const { return kind() == kScript; } 156 bool IsScriptSnapshot() const { return kind() == kScript; }
158 bool IsFullSnapshot() const { return kind() == kFull; } 157 bool IsFullSnapshot() const { return kind() == kFull; }
159 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } 158 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); }
160 159
161 static intptr_t length_offset() { 160 static intptr_t length_offset() {
162 return OFFSET_OF(Snapshot, unaligned_length_); 161 return OFFSET_OF(Snapshot, unaligned_length_);
163 } 162 }
164 static intptr_t kind_offset() { 163 static intptr_t kind_offset() {
165 return OFFSET_OF(Snapshot, unaligned_kind_); 164 return OFFSET_OF(Snapshot, unaligned_kind_);
166 } 165 }
167 166
168 private: 167 private:
169 // Prevent Snapshot from ever being allocated directly. 168 // Prevent Snapshot from ever being allocated directly.
170 Snapshot(); 169 Snapshot();
171 170
172 // The following fields are potentially unaligned. 171 // The following fields are potentially unaligned.
173 int64_t unaligned_length_; // Stream length. 172 int64_t unaligned_length_; // Stream length.
174 int64_t unaligned_kind_; // Kind of snapshot. 173 int64_t unaligned_kind_; // Kind of snapshot.
175 uint8_t content_[]; // Stream content.
176 174
175 public:
176 // Variable length data follows here.
177 const uint8_t* content() const { OPEN_ARRAY_START(uint8_t, uint8_t); }
siva 2014/09/24 22:02:53 Why not move this block to the top above the 'priv
rmacnak 2014/09/24 22:38:08 The intention was for content() to appear in the p
178
179 private:
177 DISALLOW_COPY_AND_ASSIGN(Snapshot); 180 DISALLOW_COPY_AND_ASSIGN(Snapshot);
178 }; 181 };
179 182
180 183
181 class BaseReader { 184 class BaseReader {
182 public: 185 public:
183 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} 186 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {}
184 // Reads raw data (for basic types). 187 // Reads raw data (for basic types).
185 // sizeof(T) must be in {1,2,4,8}. 188 // sizeof(T) must be in {1,2,4,8}.
186 template <typename T> 189 template <typename T>
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 private: 729 private:
727 SnapshotWriter* writer_; 730 SnapshotWriter* writer_;
728 bool as_references_; 731 bool as_references_;
729 732
730 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 733 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
731 }; 734 };
732 735
733 } // namespace dart 736 } // namespace dart
734 737
735 #endif // VM_SNAPSHOT_H_ 738 #endif // VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698