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

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, 3 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_; } 148 const uint8_t* content() const { OPEN_ARRAY_START(uint8_t, uint8_t); }
149 intptr_t length() const { 149 intptr_t length() const {
150 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_)); 150 return static_cast<intptr_t>(ReadUnaligned(&unaligned_length_));
151 } 151 }
152 Kind kind() const { 152 Kind kind() const {
153 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_)); 153 return static_cast<Kind>(ReadUnaligned(&unaligned_kind_));
154 } 154 }
155 155
156 bool IsMessageSnapshot() const { return kind() == kMessage; } 156 bool IsMessageSnapshot() const { return kind() == kMessage; }
157 bool IsScriptSnapshot() const { return kind() == kScript; } 157 bool IsScriptSnapshot() const { return kind() == kScript; }
158 bool IsFullSnapshot() const { return kind() == kFull; } 158 bool IsFullSnapshot() const { return kind() == kFull; }
159 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } 159 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); }
160 160
161 static intptr_t length_offset() { 161 static intptr_t length_offset() {
162 return OFFSET_OF(Snapshot, unaligned_length_); 162 return OFFSET_OF(Snapshot, unaligned_length_);
163 } 163 }
164 static intptr_t kind_offset() { 164 static intptr_t kind_offset() {
165 return OFFSET_OF(Snapshot, unaligned_kind_); 165 return OFFSET_OF(Snapshot, unaligned_kind_);
166 } 166 }
167 167
168 private: 168 private:
169 // Prevent Snapshot from ever being allocated directly. 169 // Prevent Snapshot from ever being allocated directly.
170 Snapshot(); 170 Snapshot();
171 171
172 // The following fields are potentially unaligned. 172 // The following fields are potentially unaligned.
173 int64_t unaligned_length_; // Stream length. 173 int64_t unaligned_length_; // Stream length.
174 int64_t unaligned_kind_; // Kind of snapshot. 174 int64_t unaligned_kind_; // Kind of snapshot.
175 uint8_t content_[]; // Stream content. 175
176 // Variable length data follows here.
176 177
177 DISALLOW_COPY_AND_ASSIGN(Snapshot); 178 DISALLOW_COPY_AND_ASSIGN(Snapshot);
178 }; 179 };
179 180
180 181
181 class BaseReader { 182 class BaseReader {
182 public: 183 public:
183 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} 184 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {}
184 // Reads raw data (for basic types). 185 // Reads raw data (for basic types).
185 // sizeof(T) must be in {1,2,4,8}. 186 // sizeof(T) must be in {1,2,4,8}.
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 private: 727 private:
727 SnapshotWriter* writer_; 728 SnapshotWriter* writer_;
728 bool as_references_; 729 bool as_references_;
729 730
730 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 731 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
731 }; 732 };
732 733
733 } // namespace dart 734 } // namespace dart
734 735
735 #endif // VM_SNAPSHOT_H_ 736 #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