| OLD | NEW |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ASSERT(IsHeapObject()); \ | 125 ASSERT(IsHeapObject()); \ |
| 126 return reinterpret_cast<Raw##object*>( \ | 126 return reinterpret_cast<Raw##object*>( \ |
| 127 reinterpret_cast<uword>(this) - kHeapObjectTag); \ | 127 reinterpret_cast<uword>(this) - kHeapObjectTag); \ |
| 128 } \ | 128 } \ |
| 129 SNAPSHOT_WRITER_SUPPORT() \ | 129 SNAPSHOT_WRITER_SUPPORT() \ |
| 130 | 130 |
| 131 | 131 |
| 132 // RawObject is the base class of all raw objects, even though it carries the | 132 // RawObject is the base class of all raw objects, even though it carries the |
| 133 // class_ field not all raw objects are allocated in the heap and thus cannot | 133 // class_ field not all raw objects are allocated in the heap and thus cannot |
| 134 // be dereferenced (e.g. RawSmi). | 134 // be dereferenced (e.g. RawSmi). |
| 135 // |
| 136 // The tags field which is a part of the object header uses the following |
| 137 // bit fields for storing tags. |
| 138 // |
| 139 // bit 0 - SmiTag |
| 140 // bit 1 - Mark bit. |
| 141 // bit 2 - Canonical object. |
| 142 // bit 3 - Created from a full snapshot. |
| 143 // |
| 135 class RawObject { | 144 class RawObject { |
| 136 public: | 145 public: |
| 137 bool IsHeapObject() const { | 146 bool IsHeapObject() const { |
| 138 uword value = reinterpret_cast<uword>(this); | 147 uword value = reinterpret_cast<uword>(this); |
| 139 return (value & kSmiTagMask) == kHeapObjectTag; | 148 return (value & kSmiTagMask) == kHeapObjectTag; |
| 140 } | 149 } |
| 141 | 150 |
| 142 bool IsNewObject() const { | 151 bool IsNewObject() const { |
| 143 uword addr = reinterpret_cast<uword>(this); | 152 uword addr = reinterpret_cast<uword>(this); |
| 144 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; | 153 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 159 ASSERT(!IsMarked()); | 168 ASSERT(!IsMarked()); |
| 160 uword header_bits = reinterpret_cast<uword>(ptr()->class_); | 169 uword header_bits = reinterpret_cast<uword>(ptr()->class_); |
| 161 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits | kMarked); | 170 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits | kMarked); |
| 162 } | 171 } |
| 163 void ClearMarkBit() { | 172 void ClearMarkBit() { |
| 164 ASSERT(IsMarked()); | 173 ASSERT(IsMarked()); |
| 165 uword header_bits = reinterpret_cast<uword>(ptr()->class_); | 174 uword header_bits = reinterpret_cast<uword>(ptr()->class_); |
| 166 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits ^ kMarked); | 175 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits ^ kMarked); |
| 167 } | 176 } |
| 168 | 177 |
| 178 // Support for object tags. |
| 179 bool IsCanonical() const { |
| 180 return CanonicalObjectTag::decode(ptr()->tags_); |
| 181 } |
| 182 void SetCanonical() { |
| 183 intptr_t tags = ptr()->tags_; |
| 184 ptr()->tags_ = CanonicalObjectTag::update(true, tags); |
| 185 } |
| 186 bool IsCreatedFromSnapshot() { |
| 187 return CreatedFromSnapshotTag::decode(ptr()->tags_); |
| 188 } |
| 189 void SetCreatedFromSnapshot() { |
| 190 intptr_t tags = ptr()->tags_; |
| 191 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags); |
| 192 } |
| 193 |
| 169 void Validate() const; | 194 void Validate() const; |
| 170 intptr_t Size() const; | 195 intptr_t Size() const; |
| 171 intptr_t VisitPointers(ObjectPointerVisitor* visitor); | 196 intptr_t VisitPointers(ObjectPointerVisitor* visitor); |
| 172 | 197 |
| 173 static RawObject* FromAddr(uword addr) { | 198 static RawObject* FromAddr(uword addr) { |
| 174 // We expect the untagged address here. | 199 // We expect the untagged address here. |
| 175 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); | 200 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); |
| 176 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); | 201 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); |
| 177 } | 202 } |
| 178 | 203 |
| 179 static uword ToAddr(RawObject* raw_obj) { | 204 static uword ToAddr(RawObject* raw_obj) { |
| 180 return reinterpret_cast<uword>(raw_obj->ptr()); | 205 return reinterpret_cast<uword>(raw_obj->ptr()); |
| 181 } | 206 } |
| 182 | 207 |
| 208 static bool IsCreatedFromSnapshot(intptr_t value) { |
| 209 return CreatedFromSnapshotTag::decode(value); |
| 210 } |
| 211 |
| 212 static bool IsCanonical(intptr_t value) { |
| 213 return CanonicalObjectTag::decode(value); |
| 214 } |
| 215 |
| 183 protected: | 216 protected: |
| 184 RawClass* class_; | 217 RawClass* class_; |
| 218 intptr_t tags_; // Various object tags (bits). |
| 185 | 219 |
| 186 private: | 220 private: |
| 187 enum { | 221 enum { |
| 188 kMarkingMask = 3, | 222 kMarkingMask = 3, |
| 189 kNotMarked = 1, // Tagged pointer. | 223 kNotMarked = 1, // Tagged pointer. |
| 190 kMarked = 3, // Tagged pointer and forwarding bit set. | 224 kMarked = 3, // Tagged pointer and forwarding bit set. |
| 191 }; | 225 }; |
| 192 | 226 |
| 227 class CanonicalObjectTag : public BitField<bool, 2, 1> { |
| 228 }; |
| 229 |
| 230 class CreatedFromSnapshotTag : public BitField<bool, 3, 1> { |
| 231 }; |
| 232 |
| 193 RawObject* ptr() const { | 233 RawObject* ptr() const { |
| 194 ASSERT(IsHeapObject()); | 234 ASSERT(IsHeapObject()); |
| 195 return reinterpret_cast<RawObject*>( | 235 return reinterpret_cast<RawObject*>( |
| 196 reinterpret_cast<uword>(this) - kHeapObjectTag); | 236 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 197 } | 237 } |
| 198 | 238 |
| 199 intptr_t tags_; // Various object tags (bits). | |
| 200 | |
| 201 friend class Object; | 239 friend class Object; |
| 202 friend class Array; | 240 friend class Array; |
| 203 friend class SnapshotWriter; | 241 friend class SnapshotWriter; |
| 204 friend class SnapshotReader; | 242 friend class SnapshotReader; |
| 205 friend class MarkingVisitor; | 243 friend class MarkingVisitor; |
| 206 | 244 |
| 207 DISALLOW_ALLOCATION(); | 245 DISALLOW_ALLOCATION(); |
| 208 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 246 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
| 209 }; | 247 }; |
| 210 | 248 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 }; | 374 }; |
| 337 | 375 |
| 338 | 376 |
| 339 class RawTypeArguments : public RawAbstractTypeArguments { | 377 class RawTypeArguments : public RawAbstractTypeArguments { |
| 340 private: | 378 private: |
| 341 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments); | 379 RAW_HEAP_OBJECT_IMPLEMENTATION(TypeArguments); |
| 342 | 380 |
| 343 RawObject** from() { | 381 RawObject** from() { |
| 344 return reinterpret_cast<RawObject**>(&ptr()->length_); | 382 return reinterpret_cast<RawObject**>(&ptr()->length_); |
| 345 } | 383 } |
| 346 bool is_canonical_; | |
| 347 RawSmi* length_; | 384 RawSmi* length_; |
| 348 | 385 |
| 349 // Variable length data follows here. | 386 // Variable length data follows here. |
| 350 RawAbstractType* types_[0]; | 387 RawAbstractType* types_[0]; |
| 351 RawObject** to(intptr_t length) { | 388 RawObject** to(intptr_t length) { |
| 352 return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]); | 389 return reinterpret_cast<RawObject**>(&ptr()->types_[length - 1]); |
| 353 } | 390 } |
| 354 }; | 391 }; |
| 355 | 392 |
| 356 | 393 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 intptr_t type_; // Uninitialized, simple or complex. | 899 intptr_t type_; // Uninitialized, simple or complex. |
| 863 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 900 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
| 864 | 901 |
| 865 // Variable length data follows here. | 902 // Variable length data follows here. |
| 866 uint8_t data_[0]; | 903 uint8_t data_[0]; |
| 867 }; | 904 }; |
| 868 | 905 |
| 869 } // namespace dart | 906 } // namespace dart |
| 870 | 907 |
| 871 #endif // VM_RAW_OBJECT_H_ | 908 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |