| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 uword tags = ptr()->tags_; | 479 uword tags = ptr()->tags_; |
| 480 return ClassIdTag::decode(tags); | 480 return ClassIdTag::decode(tags); |
| 481 } | 481 } |
| 482 | 482 |
| 483 // All writes to heap objects should ultimately pass through one of the | 483 // All writes to heap objects should ultimately pass through one of the |
| 484 // methods below or their counterparts in Object, to ensure that the | 484 // methods below or their counterparts in Object, to ensure that the |
| 485 // write barrier is correctly applied. | 485 // write barrier is correctly applied. |
| 486 | 486 |
| 487 template<typename type> | 487 template<typename type> |
| 488 void StorePointer(type const* addr, type value) { | 488 void StorePointer(type const* addr, type value) { |
| 489 #if defined(DEBUG) |
| 490 ValidateOverwrittenPointer(*addr); |
| 491 #endif // DEBUG |
| 489 // Ensure that this object contains the addr. | 492 // Ensure that this object contains the addr. |
| 490 ASSERT(Contains(reinterpret_cast<uword>(addr))); | 493 ASSERT(Contains(reinterpret_cast<uword>(addr))); |
| 491 VerifiedMemory::Write(const_cast<type*>(addr), value); | 494 VerifiedMemory::Write(const_cast<type*>(addr), value); |
| 492 // Filter stores based on source and target. | 495 // Filter stores based on source and target. |
| 493 if (!value->IsHeapObject()) return; | 496 if (!value->IsHeapObject()) return; |
| 494 if (value->IsNewObject() && this->IsOldObject() && | 497 if (value->IsNewObject() && this->IsOldObject() && |
| 495 !this->IsRemembered()) { | 498 !this->IsRemembered()) { |
| 496 this->SetRememberedBit(); | 499 this->SetRememberedBit(); |
| 497 Isolate::Current()->store_buffer()->AddObject(this); | 500 Isolate::Current()->store_buffer()->AddObject(this); |
| 498 } | 501 } |
| 499 } | 502 } |
| 500 | 503 |
| 501 // Use for storing into an explicitly Smi-typed field of an object | 504 // Use for storing into an explicitly Smi-typed field of an object |
| 502 // (i.e., both the previous and new value are Smis). | 505 // (i.e., both the previous and new value are Smis). |
| 503 void StoreSmi(RawSmi* const* addr, RawSmi* value) { | 506 void StoreSmi(RawSmi* const* addr, RawSmi* value) { |
| 507 #if defined(DEBUG) |
| 508 ValidateOverwrittenSmi(*addr); |
| 509 #endif // DEBUG |
| 504 // Can't use Contains, as array length is initialized through this method. | 510 // Can't use Contains, as array length is initialized through this method. |
| 505 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); | 511 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); |
| 506 VerifiedMemory::Write(const_cast<RawSmi**>(addr), value); | 512 VerifiedMemory::Write(const_cast<RawSmi**>(addr), value); |
| 507 } | 513 } |
| 508 | 514 |
| 515 void InitializeSmi(RawSmi* const* addr, RawSmi* value) { |
| 516 // Can't use Contains, as array length is initialized through this method. |
| 517 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); |
| 518 VerifiedMemory::Write(const_cast<RawSmi**>(addr), value); |
| 519 } |
| 520 |
| 521 #if defined(DEBUG) |
| 522 static void ValidateOverwrittenPointer(RawObject* raw); |
| 523 static void ValidateOverwrittenSmi(RawSmi* raw); |
| 524 #endif // DEBUG |
| 525 |
| 509 friend class Api; | 526 friend class Api; |
| 510 friend class Array; | 527 friend class Array; |
| 511 friend class ByteBuffer; | 528 friend class ByteBuffer; |
| 512 friend class Code; | 529 friend class Code; |
| 513 friend class FreeListElement; | 530 friend class FreeListElement; |
| 514 friend class GCMarker; | 531 friend class GCMarker; |
| 515 friend class ExternalTypedData; | 532 friend class ExternalTypedData; |
| 516 friend class ForwardList; | 533 friend class ForwardList; |
| 517 friend class GrowableObjectArray; // StorePointer | 534 friend class GrowableObjectArray; // StorePointer |
| 518 friend class Heap; | 535 friend class Heap; |
| (...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2143 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
| 2127 kTypedDataInt8ArrayViewCid + 15); | 2144 kTypedDataInt8ArrayViewCid + 15); |
| 2128 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2145 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
| 2129 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2146 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
| 2130 return (kNullCid - kTypedDataInt8ArrayCid); | 2147 return (kNullCid - kTypedDataInt8ArrayCid); |
| 2131 } | 2148 } |
| 2132 | 2149 |
| 2133 } // namespace dart | 2150 } // namespace dart |
| 2134 | 2151 |
| 2135 #endif // VM_RAW_OBJECT_H_ | 2152 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |