| 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" |
| 11 #include "vm/snapshot.h" | 11 #include "vm/snapshot.h" |
| 12 #include "vm/token.h" | 12 #include "vm/token.h" |
| 13 #include "vm/token_position.h" | 13 #include "vm/token_position.h" |
| 14 #include "vm/verified_memory.h" | |
| 15 | 14 |
| 16 namespace dart { | 15 namespace dart { |
| 17 | 16 |
| 18 // Macrobatics to define the Object hierarchy of VM implementation classes. | 17 // Macrobatics to define the Object hierarchy of VM implementation classes. |
| 19 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \ | 18 #define CLASS_LIST_NO_OBJECT_NOR_STRING_NOR_ARRAY(V) \ |
| 20 V(Class) \ | 19 V(Class) \ |
| 21 V(UnresolvedClass) \ | 20 V(UnresolvedClass) \ |
| 22 V(TypeArguments) \ | 21 V(TypeArguments) \ |
| 23 V(PatchClass) \ | 22 V(PatchClass) \ |
| 24 V(Function) \ | 23 V(Function) \ |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } while (tags != old_tags); | 564 } while (tags != old_tags); |
| 566 return true; | 565 return true; |
| 567 } | 566 } |
| 568 | 567 |
| 569 // All writes to heap objects should ultimately pass through one of the | 568 // All writes to heap objects should ultimately pass through one of the |
| 570 // methods below or their counterparts in Object, to ensure that the | 569 // methods below or their counterparts in Object, to ensure that the |
| 571 // write barrier is correctly applied. | 570 // write barrier is correctly applied. |
| 572 | 571 |
| 573 template<typename type> | 572 template<typename type> |
| 574 void StorePointer(type const* addr, type value) { | 573 void StorePointer(type const* addr, type value) { |
| 575 #if defined(DEBUG) | 574 *const_cast<type*>(addr) = value; |
| 576 ValidateOverwrittenPointer(*addr); | |
| 577 #endif // DEBUG | |
| 578 VerifiedMemory::Write(const_cast<type*>(addr), value); | |
| 579 // Filter stores based on source and target. | 575 // Filter stores based on source and target. |
| 580 if (!value->IsHeapObject()) return; | 576 if (!value->IsHeapObject()) return; |
| 581 if (value->IsNewObject() && this->IsOldObject() && | 577 if (value->IsNewObject() && this->IsOldObject() && |
| 582 !this->IsRemembered()) { | 578 !this->IsRemembered()) { |
| 583 this->SetRememberedBit(); | 579 this->SetRememberedBit(); |
| 584 Thread::Current()->StoreBufferAddObject(this); | 580 Thread::Current()->StoreBufferAddObject(this); |
| 585 } | 581 } |
| 586 } | 582 } |
| 587 | 583 |
| 588 // Use for storing into an explicitly Smi-typed field of an object | 584 // Use for storing into an explicitly Smi-typed field of an object |
| 589 // (i.e., both the previous and new value are Smis). | 585 // (i.e., both the previous and new value are Smis). |
| 590 void StoreSmi(RawSmi* const* addr, RawSmi* value) { | 586 void StoreSmi(RawSmi* const* addr, RawSmi* value) { |
| 591 #if defined(DEBUG) | |
| 592 ValidateOverwrittenSmi(*addr); | |
| 593 #endif // DEBUG | |
| 594 // Can't use Contains, as array length is initialized through this method. | 587 // Can't use Contains, as array length is initialized through this method. |
| 595 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); | 588 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); |
| 596 VerifiedMemory::Write(const_cast<RawSmi**>(addr), value); | 589 *const_cast<RawSmi**>(addr) = value; |
| 597 } | 590 } |
| 598 | 591 |
| 599 void InitializeSmi(RawSmi* const* addr, RawSmi* value) { | |
| 600 // Can't use Contains, as array length is initialized through this method. | |
| 601 ASSERT(reinterpret_cast<uword>(addr) >= RawObject::ToAddr(this)); | |
| 602 // This is an initializing store, so any previous content is OK. | |
| 603 VerifiedMemory::Accept(reinterpret_cast<uword>(addr), kWordSize); | |
| 604 VerifiedMemory::Write(const_cast<RawSmi**>(addr), value); | |
| 605 } | |
| 606 | |
| 607 #if defined(DEBUG) | |
| 608 static void ValidateOverwrittenPointer(RawObject* raw); | |
| 609 static void ValidateOverwrittenSmi(RawSmi* raw); | |
| 610 #endif // DEBUG | |
| 611 | |
| 612 friend class Api; | 592 friend class Api; |
| 613 friend class ApiMessageReader; // GetClassId | 593 friend class ApiMessageReader; // GetClassId |
| 614 friend class Serializer; // GetClassId | 594 friend class Serializer; // GetClassId |
| 615 friend class Array; | 595 friend class Array; |
| 616 friend class Bigint; | 596 friend class Bigint; |
| 617 friend class ByteBuffer; | 597 friend class ByteBuffer; |
| 618 friend class Closure; | 598 friend class Closure; |
| 619 friend class Code; | 599 friend class Code; |
| 620 friend class Double; | 600 friend class Double; |
| 621 friend class ForwardPointersVisitor; // StorePointer | 601 friend class ForwardPointersVisitor; // StorePointer |
| (...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2446 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2426 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
| 2447 kTypedDataInt8ArrayViewCid + 15); | 2427 kTypedDataInt8ArrayViewCid + 15); |
| 2448 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2428 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
| 2449 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2429 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
| 2450 return (kNullCid - kTypedDataInt8ArrayCid); | 2430 return (kNullCid - kTypedDataInt8ArrayCid); |
| 2451 } | 2431 } |
| 2452 | 2432 |
| 2453 } // namespace dart | 2433 } // namespace dart |
| 2454 | 2434 |
| 2455 #endif // VM_RAW_OBJECT_H_ | 2435 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |