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_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 void set_vtable(cpp_vtable value) { *vtable_address() = value; } | 372 void set_vtable(cpp_vtable value) { *vtable_address() = value; } |
373 | 373 |
374 static RawObject* Allocate(const Class& cls, | 374 static RawObject* Allocate(const Class& cls, |
375 intptr_t size, | 375 intptr_t size, |
376 Heap::Space space); | 376 Heap::Space space); |
377 | 377 |
378 static intptr_t RoundedAllocationSize(intptr_t size) { | 378 static intptr_t RoundedAllocationSize(intptr_t size) { |
379 return Utils::RoundUp(size, kObjectAlignment); | 379 return Utils::RoundUp(size, kObjectAlignment); |
380 } | 380 } |
381 | 381 |
| 382 bool Contains(uword addr) const { |
| 383 intptr_t this_size = raw()->Size(); |
| 384 uword this_addr = RawObject::ToAddr(raw()); |
| 385 return (addr >= this_addr) && (addr < (this_addr + this_size)); |
| 386 } |
| 387 |
382 template<typename type> void StorePointer(type* addr, type value) const { | 388 template<typename type> void StorePointer(type* addr, type value) const { |
383 // TODO(iposva): Implement real store barrier here. | 389 // Ensure that this object contains the addr. |
| 390 ASSERT(Contains(reinterpret_cast<uword>(addr))); |
384 *addr = value; | 391 *addr = value; |
385 // Filter stores based on source and target. | 392 // Filter stores based on source and target. |
386 if (!value->IsHeapObject()) return; | 393 if (!value->IsHeapObject()) return; |
387 if (value->IsNewObject() && raw()->IsOldObject()) { | 394 if (value->IsNewObject() && raw()->IsOldObject()) { |
388 uword ptr = reinterpret_cast<uword>(addr); | 395 uword ptr = reinterpret_cast<uword>(addr); |
389 Isolate::Current()->store_buffer()->AddPointer(ptr); | 396 Isolate::Current()->store_buffer()->AddPointer(ptr); |
390 } | 397 } |
391 } | 398 } |
392 | 399 |
393 RawObject* raw_; // The raw object reference. | 400 RawObject* raw_; // The raw object reference. |
(...skipping 3427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3821 StorePointer(&raw_ptr()->data_, value.raw()); | 3828 StorePointer(&raw_ptr()->data_, value.raw()); |
3822 } | 3829 } |
3823 | 3830 |
3824 RawObject* At(intptr_t index) const { | 3831 RawObject* At(intptr_t index) const { |
3825 NoGCScope no_gc; | 3832 NoGCScope no_gc; |
3826 ASSERT(!IsNull()); | 3833 ASSERT(!IsNull()); |
3827 ASSERT(index < Length()); | 3834 ASSERT(index < Length()); |
3828 return *ObjectAddr(index); | 3835 return *ObjectAddr(index); |
3829 } | 3836 } |
3830 void SetAt(intptr_t index, const Object& value) const { | 3837 void SetAt(intptr_t index, const Object& value) const { |
3831 NoGCScope no_gc; | |
3832 ASSERT(!IsNull()); | 3838 ASSERT(!IsNull()); |
3833 ASSERT(index < Length()); | 3839 ASSERT(index < Length()); |
3834 StorePointer(ObjectAddr(index), value.raw()); | 3840 const Array& arr = Array::Handle(data()); |
| 3841 arr.SetAt(index, value); |
3835 } | 3842 } |
3836 | 3843 |
3837 void Add(const Object& value, Heap::Space space = Heap::kNew) const; | 3844 void Add(const Object& value, Heap::Space space = Heap::kNew) const; |
3838 void Grow(intptr_t new_capacity, Heap::Space space = Heap::kNew) const; | 3845 void Grow(intptr_t new_capacity, Heap::Space space = Heap::kNew) const; |
3839 RawObject* RemoveLast() const; | 3846 RawObject* RemoveLast() const; |
3840 | 3847 |
3841 virtual RawAbstractTypeArguments* GetTypeArguments() const { | 3848 virtual RawAbstractTypeArguments* GetTypeArguments() const { |
3842 ASSERT(AbstractTypeArguments::AreEqual( | 3849 ASSERT(AbstractTypeArguments::AreEqual( |
3843 AbstractTypeArguments::Handle(Array::Handle(data()).GetTypeArguments()), | 3850 AbstractTypeArguments::Handle(Array::Handle(data()).GetTypeArguments()), |
3844 AbstractTypeArguments::Handle(raw_ptr()->type_arguments_))); | 3851 AbstractTypeArguments::Handle(raw_ptr()->type_arguments_))); |
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5203 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5210 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5204 return false; | 5211 return false; |
5205 } | 5212 } |
5206 } | 5213 } |
5207 return true; | 5214 return true; |
5208 } | 5215 } |
5209 | 5216 |
5210 } // namespace dart | 5217 } // namespace dart |
5211 | 5218 |
5212 #endif // VM_OBJECT_H_ | 5219 #endif // VM_OBJECT_H_ |
OLD | NEW |