| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 class RawObject { | 226 class RawObject { |
| 227 public: | 227 public: |
| 228 // The tags field which is a part of the object header uses the following | 228 // The tags field which is a part of the object header uses the following |
| 229 // bit fields for storing tags. | 229 // bit fields for storing tags. |
| 230 enum TagBits { | 230 enum TagBits { |
| 231 kWatchedBit = 0, | 231 kWatchedBit = 0, |
| 232 kMarkBit = 1, | 232 kMarkBit = 1, |
| 233 kCanonicalBit = 2, | 233 kCanonicalBit = 2, |
| 234 kFromSnapshotBit = 3, | 234 kFromSnapshotBit = 3, |
| 235 kRememberedBit = 4, | 235 kRememberedBit = 4, |
| 236 kReservedTagBit = 5, // kReservedBit{10K,100K,1M,10M} | 236 kReservedTagPos = 5, // kReservedBit{10K,100K,1M,10M} |
| 237 kReservedTagSize = 3, | 237 kReservedTagSize = 3, |
| 238 kSizeTagBit = 8, | 238 kSizeTagPos = kReservedTagPos + kReservedTagSize, // = 8 |
| 239 kSizeTagSize = 8, | 239 kSizeTagSize = 8, |
| 240 kClassIdTagBit = kSizeTagBit + kSizeTagSize, | 240 kClassIdTagPos = kSizeTagPos + kSizeTagSize, // = 16 |
| 241 kClassIdTagSize = 16 | 241 kClassIdTagSize = 16, |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 // Encodes the object size in the tag in units of object alignment. | 244 // Encodes the object size in the tag in units of object alignment. |
| 245 class SizeTag { | 245 class SizeTag { |
| 246 public: | 246 public: |
| 247 static const intptr_t kMaxSizeTag = | 247 static const intptr_t kMaxSizeTag = |
| 248 ((1 << RawObject::kSizeTagSize) - 1) << kObjectAlignmentLog2; | 248 ((1 << RawObject::kSizeTagSize) - 1) << kObjectAlignmentLog2; |
| 249 | 249 |
| 250 static uword encode(intptr_t size) { | 250 static uword encode(intptr_t size) { |
| 251 return SizeBits::encode(SizeToTagValue(size)); | 251 return SizeBits::encode(SizeToTagValue(size)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 static intptr_t decode(uword tag) { | 254 static intptr_t decode(uword tag) { |
| 255 return TagValueToSize(SizeBits::decode(tag)); | 255 return TagValueToSize(SizeBits::decode(tag)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 static uword update(intptr_t size, uword tag) { | 258 static uword update(intptr_t size, uword tag) { |
| 259 return SizeBits::update(SizeToTagValue(size), tag); | 259 return SizeBits::update(SizeToTagValue(size), tag); |
| 260 } | 260 } |
| 261 | 261 |
| 262 private: | 262 private: |
| 263 // The actual unscaled bit field used within the tag field. | 263 // The actual unscaled bit field used within the tag field. |
| 264 class SizeBits : public BitField<intptr_t, kSizeTagBit, kSizeTagSize> {}; | 264 class SizeBits : public BitField<intptr_t, kSizeTagPos, kSizeTagSize> {}; |
| 265 | 265 |
| 266 static intptr_t SizeToTagValue(intptr_t size) { | 266 static intptr_t SizeToTagValue(intptr_t size) { |
| 267 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 267 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 268 return (size > kMaxSizeTag) ? 0 : (size >> kObjectAlignmentLog2); | 268 return (size > kMaxSizeTag) ? 0 : (size >> kObjectAlignmentLog2); |
| 269 } | 269 } |
| 270 static intptr_t TagValueToSize(intptr_t value) { | 270 static intptr_t TagValueToSize(intptr_t value) { |
| 271 return value << kObjectAlignmentLog2; | 271 return value << kObjectAlignmentLog2; |
| 272 } | 272 } |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 class ClassIdTag : public BitField<intptr_t, | 275 class ClassIdTag : |
| 276 kClassIdTagBit, | 276 public BitField<intptr_t, kClassIdTagPos, kClassIdTagSize> {}; // NOLINT |
| 277 kClassIdTagSize> {}; // NOLINT | |
| 278 | 277 |
| 279 bool IsHeapObject() const { | 278 bool IsHeapObject() const { |
| 280 uword value = reinterpret_cast<uword>(this); | 279 uword value = reinterpret_cast<uword>(this); |
| 281 return (value & kSmiTagMask) == kHeapObjectTag; | 280 return (value & kSmiTagMask) == kHeapObjectTag; |
| 282 } | 281 } |
| 283 | 282 |
| 284 bool IsNewObject() const { | 283 bool IsNewObject() const { |
| 285 ASSERT(IsHeapObject()); | 284 ASSERT(IsHeapObject()); |
| 286 uword addr = reinterpret_cast<uword>(this); | 285 uword addr = reinterpret_cast<uword>(this); |
| 287 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; | 286 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; | 416 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; |
| 418 | 417 |
| 419 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 418 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
| 420 | 419 |
| 421 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; | 420 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; |
| 422 | 421 |
| 423 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 422 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
| 424 | 423 |
| 425 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 424 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
| 426 | 425 |
| 427 class ReservedBits : public BitField<intptr_t, | 426 class ReservedBits : public |
| 428 kReservedTagBit, | 427 BitField<intptr_t, kReservedTagPos, kReservedTagSize> {}; // NOLINT |
| 429 kReservedTagSize> {}; // NOLINT | |
| 430 | 428 |
| 431 RawObject* ptr() const { | 429 RawObject* ptr() const { |
| 432 ASSERT(IsHeapObject()); | 430 ASSERT(IsHeapObject()); |
| 433 return reinterpret_cast<RawObject*>( | 431 return reinterpret_cast<RawObject*>( |
| 434 reinterpret_cast<uword>(this) - kHeapObjectTag); | 432 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 435 } | 433 } |
| 436 | 434 |
| 437 intptr_t SizeFromClass() const; | 435 intptr_t SizeFromClass() const; |
| 438 | 436 |
| 439 intptr_t GetClassId() const { | 437 intptr_t GetClassId() const { |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 // Make sure this is updated when new TypedData types are added. | 1833 // Make sure this is updated when new TypedData types are added. |
| 1836 ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); | 1834 ASSERT(kTypedDataInt8ArrayViewCid == kTypedDataInt8ArrayCid + 14); |
| 1837 ASSERT(kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayViewCid + 15); | 1835 ASSERT(kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayViewCid + 15); |
| 1838 ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); | 1836 ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 14); |
| 1839 return (kNullCid - kTypedDataInt8ArrayCid); | 1837 return (kNullCid - kTypedDataInt8ArrayCid); |
| 1840 } | 1838 } |
| 1841 | 1839 |
| 1842 } // namespace dart | 1840 } // namespace dart |
| 1843 | 1841 |
| 1844 #endif // VM_RAW_OBJECT_H_ | 1842 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |