| 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/atomic.h" | 9 #include "vm/atomic.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 intptr_t result = SizeTag::decode(tags); | 396 intptr_t result = SizeTag::decode(tags); |
| 397 if (result != 0) { | 397 if (result != 0) { |
| 398 ASSERT(result == SizeFromClass()); | 398 ASSERT(result == SizeFromClass()); |
| 399 return result; | 399 return result; |
| 400 } | 400 } |
| 401 result = SizeFromClass(); | 401 result = SizeFromClass(); |
| 402 ASSERT(result > SizeTag::kMaxSizeTag); | 402 ASSERT(result > SizeTag::kMaxSizeTag); |
| 403 return result; | 403 return result; |
| 404 } | 404 } |
| 405 | 405 |
| 406 bool Contains(uword addr) const { |
| 407 intptr_t this_size = Size(); |
| 408 uword this_addr = RawObject::ToAddr(this); |
| 409 return (addr >= this_addr) && (addr < (this_addr + this_size)); |
| 410 } |
| 411 |
| 406 void Validate(Isolate* isolate) const; | 412 void Validate(Isolate* isolate) const; |
| 407 intptr_t VisitPointers(ObjectPointerVisitor* visitor); | 413 intptr_t VisitPointers(ObjectPointerVisitor* visitor); |
| 408 bool FindObject(FindObjectVisitor* visitor); | 414 bool FindObject(FindObjectVisitor* visitor); |
| 409 | 415 |
| 410 static RawObject* FromAddr(uword addr) { | 416 static RawObject* FromAddr(uword addr) { |
| 411 // We expect the untagged address here. | 417 // We expect the untagged address here. |
| 412 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); | 418 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); |
| 413 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); | 419 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); |
| 414 } | 420 } |
| 415 | 421 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 458 |
| 453 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; | 459 class RememberedBit : public BitField<bool, kRememberedBit, 1> {}; |
| 454 | 460 |
| 455 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 461 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
| 456 | 462 |
| 457 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 463 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
| 458 | 464 |
| 459 class ReservedBits : public | 465 class ReservedBits : public |
| 460 BitField<intptr_t, kReservedTagPos, kReservedTagSize> {}; // NOLINT | 466 BitField<intptr_t, kReservedTagPos, kReservedTagSize> {}; // NOLINT |
| 461 | 467 |
| 462 // TODO(koda): Return const*, like Object::raw_ptr(). | 468 // TODO(koda): After handling tags_, return const*, like Object::raw_ptr(). |
| 463 RawObject* ptr() const { | 469 RawObject* ptr() const { |
| 464 ASSERT(IsHeapObject()); | 470 ASSERT(IsHeapObject()); |
| 465 return reinterpret_cast<RawObject*>( | 471 return reinterpret_cast<RawObject*>( |
| 466 reinterpret_cast<uword>(this) - kHeapObjectTag); | 472 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 467 } | 473 } |
| 468 | 474 |
| 469 intptr_t SizeFromClass() const; | 475 intptr_t SizeFromClass() const; |
| 470 | 476 |
| 471 intptr_t GetClassId() const { | 477 intptr_t GetClassId() const { |
| 472 uword tags = ptr()->tags_; | 478 uword tags = ptr()->tags_; |
| 473 return ClassIdTag::decode(tags); | 479 return ClassIdTag::decode(tags); |
| 474 } | 480 } |
| 475 | 481 |
| 482 // All writes to heap objects should ultimately pass through one of the |
| 483 // methods below or their counterparts in Object, to ensure that the |
| 484 // write barrier is correctly applied. |
| 485 |
| 486 template<typename type> |
| 487 void StorePointer(type const* addr, type value) { |
| 488 // Ensure that this object contains the addr. |
| 489 ASSERT(Contains(reinterpret_cast<uword>(addr))); |
| 490 *const_cast<type*>(addr) = value; |
| 491 // Filter stores based on source and target. |
| 492 if (!value->IsHeapObject()) return; |
| 493 if (value->IsNewObject() && this->IsOldObject() && |
| 494 !this->IsRemembered()) { |
| 495 this->SetRememberedBit(); |
| 496 Isolate::Current()->store_buffer()->AddObject(this); |
| 497 } |
| 498 } |
| 499 |
| 500 // Use for storing into an explicitly Smi-typed field of an object |
| 501 // (i.e., both the previous and new value are Smis). |
| 502 void StoreSmi(RawSmi* const* addr, RawSmi* value) { |
| 503 // Can't use Contains, as array length is initialized through this method. |
| 504 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); |
| 505 *const_cast<RawSmi**>(addr) = value; |
| 506 } |
| 507 |
| 476 friend class Api; | 508 friend class Api; |
| 477 friend class Array; | 509 friend class Array; |
| 478 friend class ByteBuffer; | 510 friend class ByteBuffer; |
| 479 friend class Code; | 511 friend class Code; |
| 480 friend class FreeListElement; | 512 friend class FreeListElement; |
| 481 friend class GCMarker; | 513 friend class GCMarker; |
| 482 friend class ExternalTypedData; | 514 friend class ExternalTypedData; |
| 483 friend class ForwardList; | 515 friend class ForwardList; |
| 516 friend class GrowableObjectArray; // StorePointer |
| 484 friend class Heap; | 517 friend class Heap; |
| 485 friend class HeapMapAsJSONVisitor; | 518 friend class HeapMapAsJSONVisitor; |
| 486 friend class ClassStatsVisitor; | 519 friend class ClassStatsVisitor; |
| 487 friend class MarkingVisitor; | 520 friend class MarkingVisitor; |
| 488 friend class Object; | 521 friend class Object; |
| 522 friend class OneByteString; // StoreSmi |
| 489 friend class RawExternalTypedData; | 523 friend class RawExternalTypedData; |
| 490 friend class RawInstructions; | 524 friend class RawInstructions; |
| 491 friend class RawInstance; | 525 friend class RawInstance; |
| 492 friend class RawTypedData; | 526 friend class RawTypedData; |
| 493 friend class Scavenger; | 527 friend class Scavenger; |
| 494 friend class ScavengerVisitor; | 528 friend class ScavengerVisitor; |
| 495 friend class SizeExcludingClassVisitor; // GetClassId | 529 friend class SizeExcludingClassVisitor; // GetClassId |
| 496 friend class SnapshotReader; | 530 friend class SnapshotReader; |
| 497 friend class SnapshotWriter; | 531 friend class SnapshotWriter; |
| 498 friend class String; | 532 friend class String; |
| 499 friend class TypedData; | 533 friend class TypedData; |
| 500 friend class TypedDataView; | 534 friend class TypedDataView; |
| 535 friend class WeakProperty; // StorePointer |
| 501 | 536 |
| 502 DISALLOW_ALLOCATION(); | 537 DISALLOW_ALLOCATION(); |
| 503 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 538 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
| 504 }; | 539 }; |
| 505 | 540 |
| 506 | 541 |
| 507 class RawClass : public RawObject { | 542 class RawClass : public RawObject { |
| 508 public: | 543 public: |
| 509 enum ClassFinalizedState { | 544 enum ClassFinalizedState { |
| 510 kAllocated = 0, // Initial state. | 545 kAllocated = 0, // Initial state. |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2103 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
| 2069 kTypedDataInt8ArrayViewCid + 15); | 2104 kTypedDataInt8ArrayViewCid + 15); |
| 2070 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2105 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
| 2071 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2106 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
| 2072 return (kNullCid - kTypedDataInt8ArrayCid); | 2107 return (kNullCid - kTypedDataInt8ArrayCid); |
| 2073 } | 2108 } |
| 2074 | 2109 |
| 2075 } // namespace dart | 2110 } // namespace dart |
| 2076 | 2111 |
| 2077 #endif // VM_RAW_OBJECT_H_ | 2112 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |