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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 // be dereferenced (e.g. RawSmi). | 216 // be dereferenced (e.g. RawSmi). |
| 217 class RawObject { | 217 class RawObject { |
| 218 public: | 218 public: |
| 219 // The tags field which is a part of the object header uses the following | 219 // The tags field which is a part of the object header uses the following |
| 220 // bit fields for storing tags. | 220 // bit fields for storing tags. |
| 221 enum TagBits { | 221 enum TagBits { |
| 222 kFreeBit = 0, | 222 kFreeBit = 0, |
| 223 kMarkBit = 1, | 223 kMarkBit = 1, |
| 224 kCanonicalBit = 2, | 224 kCanonicalBit = 2, |
| 225 kFromSnapshotBit = 3, | 225 kFromSnapshotBit = 3, |
| 226 kWatchedBit = 4, | 226 kWatchedBit = 4, |
|
siva
2013/04/27 00:49:37
The WatchedBit is only used during GC right so we
| |
| 227 kReservedTagBit = 5, // kReservedBit{10K,100K,1M,10M} | 227 kRememberedBit = 5, |
| 228 kReservedTagSize = 3, | 228 kReservedTagBit = 6, // kReservedBit{10K,100K,1M,10M} |
| 229 kReservedTagSize = 2, | |
| 229 kSizeTagBit = 8, | 230 kSizeTagBit = 8, |
| 230 kSizeTagSize = 8, | 231 kSizeTagSize = 8, |
| 231 kClassIdTagBit = kSizeTagBit + kSizeTagSize, | 232 kClassIdTagBit = kSizeTagBit + kSizeTagSize, |
| 232 kClassIdTagSize = 16 | 233 kClassIdTagSize = 16 |
| 233 }; | 234 }; |
| 234 | 235 |
| 235 // Encodes the object size in the tag in units of object alignment. | 236 // Encodes the object size in the tag in units of object alignment. |
| 236 class SizeTag { | 237 class SizeTag { |
| 237 public: | 238 public: |
| 238 static const intptr_t kMaxSizeTag = | 239 static const intptr_t kMaxSizeTag = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 ASSERT(!IsMarked()); | 293 ASSERT(!IsMarked()); |
| 293 uword tags = ptr()->tags_; | 294 uword tags = ptr()->tags_; |
| 294 ptr()->tags_ = MarkBit::update(true, tags); | 295 ptr()->tags_ = MarkBit::update(true, tags); |
| 295 } | 296 } |
| 296 void ClearMarkBit() { | 297 void ClearMarkBit() { |
| 297 ASSERT(IsMarked()); | 298 ASSERT(IsMarked()); |
| 298 uword tags = ptr()->tags_; | 299 uword tags = ptr()->tags_; |
| 299 ptr()->tags_ = MarkBit::update(false, tags); | 300 ptr()->tags_ = MarkBit::update(false, tags); |
| 300 } | 301 } |
| 301 | 302 |
| 302 // Support for GC watched bit. | 303 // Support for remembered bit. |
| 303 bool IsWatched() const { | 304 bool IsRemembered() const { |
| 304 return WatchedBit::decode(ptr()->tags_); | 305 return RememberedBit::decode(ptr()->tags_); |
| 305 } | 306 } |
| 306 void SetWatchedBit() { | 307 void SetRememberedBit() { |
| 307 ASSERT(!IsWatched()); | 308 ASSERT(!IsRemembered()); |
| 308 uword tags = ptr()->tags_; | 309 uword tags = ptr()->tags_; |
| 309 ptr()->tags_ = WatchedBit::update(true, tags); | 310 ptr()->tags_ = RememberedBit::update(true, tags); |
| 310 } | 311 } |
| 311 void ClearWatchedBit() { | 312 void ClearRememberedBit() { |
| 312 ASSERT(IsWatched()); | |
| 313 uword tags = ptr()->tags_; | 313 uword tags = ptr()->tags_; |
| 314 ptr()->tags_ = WatchedBit::update(false, tags); | 314 ptr()->tags_ = RememberedBit::update(false, tags); |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Support for object tags. | 317 // Support for object tags. |
| 318 bool IsCanonical() const { | 318 bool IsCanonical() const { |
| 319 return CanonicalObjectTag::decode(ptr()->tags_); | 319 return CanonicalObjectTag::decode(ptr()->tags_); |
| 320 } | 320 } |
| 321 void SetCanonical() { | 321 void SetCanonical() { |
| 322 uword tags = ptr()->tags_; | 322 uword tags = ptr()->tags_; |
| 323 ptr()->tags_ = CanonicalObjectTag::update(true, tags); | 323 ptr()->tags_ = CanonicalObjectTag::update(true, tags); |
| 324 } | 324 } |
| 325 bool IsCreatedFromSnapshot() const { | 325 bool IsCreatedFromSnapshot() const { |
| 326 return CreatedFromSnapshotTag::decode(ptr()->tags_); | 326 return CreatedFromSnapshotTag::decode(ptr()->tags_); |
| 327 } | 327 } |
| 328 void SetCreatedFromSnapshot() { | 328 void SetCreatedFromSnapshot() { |
| 329 uword tags = ptr()->tags_; | 329 uword tags = ptr()->tags_; |
| 330 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags); | 330 ptr()->tags_ = CreatedFromSnapshotTag::update(true, tags); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Support for GC watched bit. | |
| 334 bool IsWatched() const { | |
| 335 return WatchedBit::decode(ptr()->tags_); | |
| 336 } | |
| 337 void SetWatchedBit() { | |
| 338 ASSERT(!IsWatched()); | |
| 339 uword tags = ptr()->tags_; | |
| 340 ptr()->tags_ = WatchedBit::update(true, tags); | |
| 341 } | |
| 342 void ClearWatchedBit() { | |
| 343 ASSERT(IsWatched()); | |
| 344 uword tags = ptr()->tags_; | |
| 345 ptr()->tags_ = WatchedBit::update(false, tags); | |
| 346 } | |
| 347 | |
| 333 bool IsDartInstance() { | 348 bool IsDartInstance() { |
| 334 return (!IsHeapObject() || (GetClassId() >= kInstanceCid)); | 349 return (!IsHeapObject() || (GetClassId() >= kInstanceCid)); |
| 335 } | 350 } |
| 336 | 351 |
| 337 intptr_t Size() const { | 352 intptr_t Size() const { |
| 338 uword tags = ptr()->tags_; | 353 uword tags = ptr()->tags_; |
| 339 intptr_t result = SizeTag::decode(tags); | 354 intptr_t result = SizeTag::decode(tags); |
| 340 if (result != 0) { | 355 if (result != 0) { |
| 341 ASSERT(result == SizeFromClass()); | 356 ASSERT(result == SizeFromClass()); |
| 342 return result; | 357 return result; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 static bool IsBuiltinListClassId(intptr_t index); | 394 static bool IsBuiltinListClassId(intptr_t index); |
| 380 static bool IsTypedDataClassId(intptr_t index); | 395 static bool IsTypedDataClassId(intptr_t index); |
| 381 static bool IsTypedDataViewClassId(intptr_t index); | 396 static bool IsTypedDataViewClassId(intptr_t index); |
| 382 static bool IsExternalTypedDataClassId(intptr_t index); | 397 static bool IsExternalTypedDataClassId(intptr_t index); |
| 383 | 398 |
| 384 static intptr_t NumberOfTypedDataClasses(); | 399 static intptr_t NumberOfTypedDataClasses(); |
| 385 | 400 |
| 386 private: | 401 private: |
| 387 uword tags_; // Various object tags (bits). | 402 uword tags_; // Various object tags (bits). |
| 388 | 403 |
| 389 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | 404 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
| 390 | 405 |
| 391 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 406 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; |
| 392 | 407 |
| 393 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; | 408 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; |
| 394 | 409 |
| 395 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 410 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
| 396 | 411 |
| 397 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 412 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
| 398 | 413 |
| 399 class ReservedBits : public BitField<intptr_t, | 414 class ReservedBits : public BitField<intptr_t, |
| 400 kReservedTagBit, | 415 kReservedTagBit, |
| 401 kReservedTagSize> {}; // NOLINT | 416 kReservedTagSize> {}; // NOLINT |
| (...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1664 // Make sure this is updated when new TypedData types are added. | 1679 // Make sure this is updated when new TypedData types are added. |
| 1665 ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 12); | 1680 ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 12); |
| 1666 ASSERT(kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayViewCid + 13); | 1681 ASSERT(kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayViewCid + 13); |
| 1667 ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 12); | 1682 ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 12); |
| 1668 return (kNullCid - kTypedDataInt8ArrayCid); | 1683 return (kNullCid - kTypedDataInt8ArrayCid); |
| 1669 } | 1684 } |
| 1670 | 1685 |
| 1671 } // namespace dart | 1686 } // namespace dart |
| 1672 | 1687 |
| 1673 #endif // VM_RAW_OBJECT_H_ | 1688 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |