Chromium Code Reviews| 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_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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/token.h" | 10 #include "vm/token.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 kReservedBit10K = 4, | 182 kReservedBit10K = 4, |
| 183 kReservedBit100K = 5, | 183 kReservedBit100K = 5, |
| 184 kReservedBit1M = 6, | 184 kReservedBit1M = 6, |
| 185 kReservedBit10M = 7, | 185 kReservedBit10M = 7, |
| 186 kSizeTagBit = 8, | 186 kSizeTagBit = 8, |
| 187 kSizeTagSize = 8, | 187 kSizeTagSize = 8, |
| 188 kClassIdTagBit = kSizeTagBit + kSizeTagSize, | 188 kClassIdTagBit = kSizeTagBit + kSizeTagSize, |
| 189 kClassIdTagSize = 16 | 189 kClassIdTagSize = 16 |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | |
|
Ivan Posva
2012/06/08 12:50:20
Do you still need to make this public?
Vyacheslav Egorov (Google)
2012/06/08 12:58:27
We still initialize it in the FreeListElement::AsE
| |
| 193 | |
| 192 // Encodes the object size in the tag in units of object alignment. | 194 // Encodes the object size in the tag in units of object alignment. |
| 193 class SizeTag { | 195 class SizeTag { |
| 194 public: | 196 public: |
| 195 static const intptr_t kMaxSizeTag = | 197 static const intptr_t kMaxSizeTag = |
| 196 ((1 << RawObject::kSizeTagSize) - 1) << kObjectAlignmentLog2; | 198 ((1 << RawObject::kSizeTagSize) - 1) << kObjectAlignmentLog2; |
| 197 | 199 |
| 198 static uword encode(intptr_t size) { | 200 static uword encode(intptr_t size) { |
| 199 return SizeBits::encode(SizeToTagValue(size)); | 201 return SizeBits::encode(SizeToTagValue(size)); |
| 200 } | 202 } |
| 201 | 203 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 return CreatedFromSnapshotTag::decode(ptr()->tags_); | 267 return CreatedFromSnapshotTag::decode(ptr()->tags_); |
| 266 } | 268 } |
| 267 void SetCreatedFromSnapshot() { | 269 void SetCreatedFromSnapshot() { |
| 268 uword tags = ptr()->tags_; | 270 uword tags = ptr()->tags_; |
| 269 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags); | 271 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags); |
| 270 } | 272 } |
| 271 | 273 |
| 272 intptr_t Size() const { | 274 intptr_t Size() const { |
| 273 uword tags = ptr()->tags_; | 275 uword tags = ptr()->tags_; |
| 274 intptr_t result = SizeTag::decode(tags); | 276 intptr_t result = SizeTag::decode(tags); |
| 275 if ((result != 0) && !FreeBit::decode(tags)) { | 277 if (result != 0) { |
| 276 ASSERT(result == SizeFromClass()); | 278 ASSERT(result == SizeFromClass()); |
| 277 return result; | 279 return result; |
| 278 } | 280 } |
| 279 result = SizeFromClass(); | 281 result = SizeFromClass(); |
| 280 ASSERT((result > SizeTag::kMaxSizeTag) || FreeBit::decode(tags)); | 282 ASSERT(result > SizeTag::kMaxSizeTag); |
| 281 return result; | 283 return result; |
| 282 } | 284 } |
| 283 | 285 |
| 284 void Validate(Isolate* isolate) const; | 286 void Validate(Isolate* isolate) const; |
| 285 intptr_t VisitPointers(ObjectPointerVisitor* visitor); | 287 intptr_t VisitPointers(ObjectPointerVisitor* visitor); |
| 286 bool FindObject(FindObjectVisitor* visitor); | 288 bool FindObject(FindObjectVisitor* visitor); |
| 287 | 289 |
| 288 static RawObject* FromAddr(uword addr) { | 290 static RawObject* FromAddr(uword addr) { |
| 289 // We expect the untagged address here. | 291 // We expect the untagged address here. |
| 290 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); | 292 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 311 static bool IsOneByteStringClassId(intptr_t index); | 313 static bool IsOneByteStringClassId(intptr_t index); |
| 312 static bool IsTwoByteStringClassId(intptr_t index); | 314 static bool IsTwoByteStringClassId(intptr_t index); |
| 313 static bool IsExternalStringClassId(intptr_t index); | 315 static bool IsExternalStringClassId(intptr_t index); |
| 314 static bool IsBuiltinListClassId(intptr_t index); | 316 static bool IsBuiltinListClassId(intptr_t index); |
| 315 static bool IsByteArrayClassId(intptr_t index); | 317 static bool IsByteArrayClassId(intptr_t index); |
| 316 | 318 |
| 317 protected: | 319 protected: |
| 318 uword tags_; // Various object tags (bits). | 320 uword tags_; // Various object tags (bits). |
| 319 | 321 |
| 320 private: | 322 private: |
| 321 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | |
| 322 | |
| 323 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 323 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
| 324 | 324 |
| 325 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 325 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
| 326 | 326 |
| 327 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 327 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
| 328 | 328 |
| 329 RawObject* ptr() const { | 329 RawObject* ptr() const { |
| 330 ASSERT(IsHeapObject()); | 330 ASSERT(IsHeapObject()); |
| 331 return reinterpret_cast<RawObject*>( | 331 return reinterpret_cast<RawObject*>( |
| 332 reinterpret_cast<uword>(this) - kHeapObjectTag); | 332 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 333 } | 333 } |
| 334 | 334 |
| 335 intptr_t SizeFromClass() const; | 335 intptr_t SizeFromClass() const; |
| 336 | 336 |
| 337 intptr_t GetClassId() const { | 337 intptr_t GetClassId() const { |
| 338 uword tags = ptr()->tags_; | 338 uword tags = ptr()->tags_; |
| 339 // TODO(vegorov): stop destroying tags_ when creating FreeListElement. | |
| 340 ASSERT(!FreeBit::decode(tags)); | |
| 341 return ClassIdTag::decode(tags); | 339 return ClassIdTag::decode(tags); |
| 342 } | 340 } |
| 343 | 341 |
| 344 friend class Api; | 342 friend class Api; |
| 345 friend class Array; | 343 friend class Array; |
| 346 friend class Heap; | 344 friend class Heap; |
| 347 friend class MarkingVisitor; | 345 friend class MarkingVisitor; |
| 348 friend class Object; | 346 friend class Object; |
| 349 friend class RawInstructions; | 347 friend class RawInstructions; |
| 350 friend class RawInstance; | 348 friend class RawInstance; |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 kExternalUint64Array == kByteArray + 18 && | 1498 kExternalUint64Array == kByteArray + 18 && |
| 1501 kExternalFloat32Array == kByteArray + 19 && | 1499 kExternalFloat32Array == kByteArray + 19 && |
| 1502 kExternalFloat64Array == kByteArray + 20 && | 1500 kExternalFloat64Array == kByteArray + 20 && |
| 1503 kClosure == kByteArray + 21); | 1501 kClosure == kByteArray + 21); |
| 1504 return (index >= kByteArray && index <= kClosure); | 1502 return (index >= kByteArray && index <= kClosure); |
| 1505 } | 1503 } |
| 1506 | 1504 |
| 1507 } // namespace dart | 1505 } // namespace dart |
| 1508 | 1506 |
| 1509 #endif // VM_RAW_OBJECT_H_ | 1507 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |