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

Side by Side Diff: vm/raw_object.h

Issue 8879063: Changes to set up the object tag bits (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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_RAW_OBJECT_H_ 5 #ifndef VM_RAW_OBJECT_H_
6 #define VM_RAW_OBJECT_H_ 6 #define VM_RAW_OBJECT_H_
7 7
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/snapshot.h" 10 #include "vm/snapshot.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 }; 94 };
95 95
96 enum { 96 enum {
97 kSmiTag = 0, 97 kSmiTag = 0,
98 kHeapObjectTag = 1, 98 kHeapObjectTag = 1,
99 kSmiTagSize = 1, 99 kSmiTagSize = 1,
100 kSmiTagMask = 1, 100 kSmiTagMask = 1,
101 kSmiTagShift = 1, 101 kSmiTagShift = 1,
102 }; 102 };
103 103
104
105 /*
106 * The tags field which is a part of the object header uses the following
107 * bit fields for storing tags.
108 *
109 * bit 0 - SmiTag
110 * bit 1 - Mark bit.
111 * bit 2 - Canonical object.
112 * bit 3 - Created from a full snapshot.
113 */
114 class CanonicalObjectTag : public BitField<bool, 2, 1> {
115 };
116
117
118 class CreatedFromSnapshotTag : public BitField<bool, 3, 1> {
119 };
120
121
104 #define SNAPSHOT_WRITER_SUPPORT() \ 122 #define SNAPSHOT_WRITER_SUPPORT() \
105 void WriteTo( \ 123 void WriteTo( \
106 SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind); \ 124 SnapshotWriter* writer, intptr_t object_id, Snapshot::Kind kind); \
107 friend class SnapshotWriter; \ 125 friend class SnapshotWriter; \
108 126
109 #define VISITOR_SUPPORT(object) \ 127 #define VISITOR_SUPPORT(object) \
110 static intptr_t Visit##object##Pointers(Raw##object* raw_obj, \ 128 static intptr_t Visit##object##Pointers(Raw##object* raw_obj, \
111 ObjectPointerVisitor* visitor); 129 ObjectPointerVisitor* visitor);
112 130
113 #define RAW_OBJECT_IMPLEMENTATION(object) \ 131 #define RAW_OBJECT_IMPLEMENTATION(object) \
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ASSERT(!IsMarked()); 177 ASSERT(!IsMarked());
160 uword header_bits = reinterpret_cast<uword>(ptr()->class_); 178 uword header_bits = reinterpret_cast<uword>(ptr()->class_);
161 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits | kMarked); 179 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits | kMarked);
162 } 180 }
163 void ClearMarkBit() { 181 void ClearMarkBit() {
164 ASSERT(IsMarked()); 182 ASSERT(IsMarked());
165 uword header_bits = reinterpret_cast<uword>(ptr()->class_); 183 uword header_bits = reinterpret_cast<uword>(ptr()->class_);
166 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits ^ kMarked); 184 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits ^ kMarked);
167 } 185 }
168 186
187 // Support for object tags.
188 bool IsCanonical() const {
189 return CanonicalObjectTag::decode(ptr()->tags_);
190 }
191 void SetCanonical() {
192 intptr_t tags = ptr()->tags_;
193 ptr()->tags_ = CanonicalObjectTag::update(true, tags);
194 }
195 bool IsCreatedFromSnapshot() {
196 return CreatedFromSnapshotTag::decode(ptr()->tags_);
197 }
198 void SetCreatedFromSnapshot() {
199 intptr_t tags = ptr()->tags_;
200 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags);
201 }
202
169 void Validate() const; 203 void Validate() const;
170 intptr_t Size() const; 204 intptr_t Size() const;
171 intptr_t VisitPointers(ObjectPointerVisitor* visitor); 205 intptr_t VisitPointers(ObjectPointerVisitor* visitor);
172 206
173 static RawObject* FromAddr(uword addr) { 207 static RawObject* FromAddr(uword addr) {
174 // We expect the untagged address here. 208 // We expect the untagged address here.
175 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); 209 ASSERT((addr & kSmiTagMask) != kHeapObjectTag);
176 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); 210 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag);
177 } 211 }
178 212
179 static uword ToAddr(RawObject* raw_obj) { 213 static uword ToAddr(RawObject* raw_obj) {
180 return reinterpret_cast<uword>(raw_obj->ptr()); 214 return reinterpret_cast<uword>(raw_obj->ptr());
181 } 215 }
182 216
217 static bool IsCreatedFromSnapshot(intptr_t value) {
218 return CreatedFromSnapshotTag::decode(value);
219 }
220
221 static bool IsCanonical(intptr_t value) {
222 return CanonicalObjectTag::decode(value);
223 }
224
183 protected: 225 protected:
184 RawClass* class_; 226 RawClass* class_;
227 intptr_t tags_; // Various object tags (bits).
185 228
186 private: 229 private:
187 enum { 230 enum {
188 kMarkingMask = 3, 231 kMarkingMask = 3,
189 kNotMarked = 1, // Tagged pointer. 232 kNotMarked = 1, // Tagged pointer.
190 kMarked = 3, // Tagged pointer and forwarding bit set. 233 kMarked = 3, // Tagged pointer and forwarding bit set.
191 }; 234 };
192 235
193 RawObject* ptr() const { 236 RawObject* ptr() const {
194 ASSERT(IsHeapObject()); 237 ASSERT(IsHeapObject());
195 return reinterpret_cast<RawObject*>( 238 return reinterpret_cast<RawObject*>(
196 reinterpret_cast<uword>(this) - kHeapObjectTag); 239 reinterpret_cast<uword>(this) - kHeapObjectTag);
197 } 240 }
198 241
199 intptr_t tags_; // Various object tags (bits).
200
201 friend class Object; 242 friend class Object;
202 friend class Array; 243 friend class Array;
203 friend class SnapshotWriter; 244 friend class SnapshotWriter;
204 friend class SnapshotReader; 245 friend class SnapshotReader;
205 friend class MarkingVisitor; 246 friend class MarkingVisitor;
206 247
207 DISALLOW_ALLOCATION(); 248 DISALLOW_ALLOCATION();
208 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); 249 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject);
209 }; 250 };
210 251
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 }; 377 };
337 378
338 379
339 class RawTypeArguments : public RawAbstractTypeArguments { 380 class RawTypeArguments : public RawAbstractTypeArguments {
340 private: 381 private:
341 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments); 382 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments);
342 383
343 RawObject** from() { 384 RawObject** from() {
344 return reinterpret_cast<RawObject**>(&ptr()->length_); 385 return reinterpret_cast<RawObject**>(&ptr()->length_);
345 } 386 }
346 bool is_canonical_;
347 RawSmi* length_; 387 RawSmi* length_;
348 388
349 // Variable length data follows here. 389 // Variable length data follows here.
350 RawAbstractType* types_[0]; 390 RawAbstractType* types_[0];
351 RawObject** to(intptr_t length) { 391 RawObject** to(intptr_t length) {
352 return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]); 392 return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]);
353 } 393 }
354 }; 394 };
355 395
356 396
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 intptr_t type_; // Uninitialized, simple or complex. 902 intptr_t type_; // Uninitialized, simple or complex.
863 intptr_t flags_; // Represents global/local, case insensitive, multiline. 903 intptr_t flags_; // Represents global/local, case insensitive, multiline.
864 904
865 // Variable length data follows here. 905 // Variable length data follows here.
866 uint8_t data_[0]; 906 uint8_t data_[0];
867 }; 907 };
868 908
869 } // namespace dart 909 } // namespace dart
870 910
871 #endif // VM_RAW_OBJECT_H_ 911 #endif // VM_RAW_OBJECT_H_
OLDNEW
« vm/object.cc ('K') | « vm/object.cc ('k') | vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698