Chromium Code Reviews| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } \ | 106 } \ |
| 107 static Raw##object* null() { \ | 107 static Raw##object* null() { \ |
| 108 return reinterpret_cast<Raw##object*>(Object::null()); \ | 108 return reinterpret_cast<Raw##object*>(Object::null()); \ |
| 109 } \ | 109 } \ |
| 110 virtual const char* ToCString() const; \ | 110 virtual const char* ToCString() const; \ |
| 111 static const ClassId kClassId = k##object##Cid; \ | 111 static const ClassId kClassId = k##object##Cid; \ |
| 112 protected: /* NOLINT */ \ | 112 protected: /* NOLINT */ \ |
| 113 object() : super() {} \ | 113 object() : super() {} \ |
| 114 private: /* NOLINT */ \ | 114 private: /* NOLINT */ \ |
| 115 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ | 115 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ |
| 116 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ | 116 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ |
|
Florian Schneider
2012/11/01 22:35:36
How about adding a
initializeHandle(object* obj,
siva
2012/11/06 02:27:08
Will have to consider this in a different CL.
On
| |
| 117 if (raw_ptr != Object::null()) { \ | 117 if (raw_ptr != Object::null()) { \ |
| 118 obj->SetRaw(raw_ptr); \ | 118 obj->SetNonNullRaw(raw_ptr); \ |
| 119 } else { \ | 119 } else { \ |
| 120 obj->raw_ = Object::null(); \ | 120 obj->raw_ = Object::null(); \ |
|
Ivan Posva
2012/11/01 21:33:34
We had discussed in the past whether this is the c
siva
2012/11/01 21:59:53
I think we wanted to avoid the case where assignme
| |
| 121 object fake_object; \ | 121 object fake_object; \ |
| 122 obj->set_vtable(fake_object.vtable()); \ | 122 obj->set_vtable(fake_object.vtable()); \ |
| 123 } \ | 123 } \ |
| 124 } \ | 124 } \ |
| 125 /* Disallow allocation, copy constructors and override super assignment. */ \ | 125 /* Disallow allocation, copy constructors and override super assignment. */ \ |
| 126 void* operator new(size_t size); \ | 126 void* operator new(size_t size); \ |
| 127 object(const object& value); \ | 127 object(const object& value); \ |
| 128 void operator=(Raw##super* value); \ | 128 void operator=(Raw##super* value); \ |
| 129 void operator=(const object& value); \ | 129 void operator=(const object& value); \ |
| 130 void operator=(const super& value); \ | 130 void operator=(const super& value); \ |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 319 |
| 320 protected: | 320 protected: |
| 321 // Used for extracting the C++ vtable during bringup. | 321 // Used for extracting the C++ vtable during bringup. |
| 322 Object() : raw_(null_) {} | 322 Object() : raw_(null_) {} |
| 323 | 323 |
| 324 uword raw_value() const { | 324 uword raw_value() const { |
| 325 return reinterpret_cast<uword>(raw()); | 325 return reinterpret_cast<uword>(raw()); |
| 326 } | 326 } |
| 327 | 327 |
| 328 inline void SetRaw(RawObject* value); | 328 inline void SetRaw(RawObject* value); |
| 329 inline void SetNonNullRaw(RawObject* value); | |
| 329 | 330 |
| 330 cpp_vtable vtable() const { return bit_copy<cpp_vtable>(*this); } | 331 cpp_vtable vtable() const { return bit_copy<cpp_vtable>(*this); } |
| 331 void set_vtable(cpp_vtable value) { *vtable_address() = value; } | 332 void set_vtable(cpp_vtable value) { *vtable_address() = value; } |
| 332 | 333 |
| 333 static RawObject* Allocate(intptr_t cls_id, | 334 static RawObject* Allocate(intptr_t cls_id, |
| 334 intptr_t size, | 335 intptr_t size, |
| 335 Heap::Space space); | 336 Heap::Space space); |
| 336 | 337 |
| 337 static intptr_t RoundedAllocationSize(intptr_t size) { | 338 static intptr_t RoundedAllocationSize(intptr_t size) { |
| 338 return Utils::RoundUp(size, kObjectAlignment); | 339 return Utils::RoundUp(size, kObjectAlignment); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 352 if (!value->IsHeapObject()) return; | 353 if (!value->IsHeapObject()) return; |
| 353 if (value->IsNewObject() && raw()->IsOldObject()) { | 354 if (value->IsNewObject() && raw()->IsOldObject()) { |
| 354 uword ptr = reinterpret_cast<uword>(addr); | 355 uword ptr = reinterpret_cast<uword>(addr); |
| 355 Isolate::Current()->store_buffer()->AddPointer(ptr); | 356 Isolate::Current()->store_buffer()->AddPointer(ptr); |
| 356 } | 357 } |
| 357 } | 358 } |
| 358 | 359 |
| 359 RawObject* raw_; // The raw object reference. | 360 RawObject* raw_; // The raw object reference. |
| 360 | 361 |
| 361 private: | 362 private: |
| 363 inline void SetRawHelper(); | |
| 364 | |
| 362 static void InitializeObject(uword address, intptr_t id, intptr_t size); | 365 static void InitializeObject(uword address, intptr_t id, intptr_t size); |
| 363 | 366 |
| 364 static RawClass* CreateAndRegisterInterface(const char* cname, | 367 static RawClass* CreateAndRegisterInterface(const char* cname, |
| 365 const Script& script, | 368 const Script& script, |
| 366 const Library& lib); | 369 const Library& lib); |
| 367 static void RegisterClass(const Class& cls, | 370 static void RegisterClass(const Class& cls, |
| 368 const String& name, | 371 const String& name, |
| 369 const Library& lib); | 372 const Library& lib); |
| 370 static void RegisterPrivateClass(const Class& cls, | 373 static void RegisterPrivateClass(const Class& cls, |
| 371 const String& name, | 374 const String& name, |
| (...skipping 5270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5642 // Breaking cycles and loops. | 5645 // Breaking cycles and loops. |
| 5643 RawClass* Object::clazz() const { | 5646 RawClass* Object::clazz() const { |
| 5644 uword raw_value = reinterpret_cast<uword>(raw_); | 5647 uword raw_value = reinterpret_cast<uword>(raw_); |
| 5645 if ((raw_value & kSmiTagMask) == kSmiTag) { | 5648 if ((raw_value & kSmiTagMask) == kSmiTag) { |
| 5646 return Smi::Class(); | 5649 return Smi::Class(); |
| 5647 } | 5650 } |
| 5648 return Isolate::Current()->class_table()->At(raw()->GetClassId()); | 5651 return Isolate::Current()->class_table()->At(raw()->GetClassId()); |
| 5649 } | 5652 } |
| 5650 | 5653 |
| 5651 | 5654 |
| 5655 | |
| 5652 void Object::SetRaw(RawObject* value) { | 5656 void Object::SetRaw(RawObject* value) { |
| 5653 // NOTE: The assignment "raw_ = value" should be the first statement in | 5657 // NOTE: The assignment "raw_ = value" should be the first statement in |
| 5654 // this function. Also do not use 'value' in this function after the | 5658 // this function. Also do not use 'value' in this function after the |
| 5655 // assignment (use 'raw_' instead). | 5659 // assignment (use 'raw_' instead). |
| 5656 raw_ = value; | 5660 raw_ = value; |
| 5661 if (raw_ == null_) { | |
|
Ivan Posva
2012/11/01 21:33:34
The special case should not have been necessary in
siva
2012/11/01 21:59:53
the vtable of kNullCid in builtin_vtables_ you mea
| |
| 5662 set_vtable(handle_vtable_); | |
| 5663 return; | |
| 5664 } | |
| 5665 SetRawHelper(); | |
| 5666 } | |
| 5667 | |
| 5668 | |
| 5669 void Object::SetNonNullRaw(RawObject* value) { | |
| 5670 // NOTE: The assignment "raw_ = value" should be the first statement in | |
| 5671 // this function. Also do not use 'value' in this function after the | |
| 5672 // assignment (use 'raw_' instead). | |
| 5673 raw_ = value; | |
| 5674 ASSERT(raw_ != null_); | |
| 5675 SetRawHelper(); | |
| 5676 } | |
| 5677 | |
| 5678 | |
| 5679 void Object::SetRawHelper() { | |
| 5657 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) { | 5680 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) { |
| 5658 set_vtable(Smi::handle_vtable_); | 5681 set_vtable(Smi::handle_vtable_); |
| 5659 return; | 5682 return; |
| 5660 } else if (raw_ == null_) { | |
| 5661 set_vtable(handle_vtable_); | |
| 5662 return; | |
| 5663 } | 5683 } |
| 5664 | 5684 intptr_t cid = raw_->GetClassId(); |
| 5685 if (cid >= kNumPredefinedCids) { | |
| 5686 cid = kInstanceCid; | |
| 5687 } | |
| 5688 set_vtable(builtin_vtables_[cid]); | |
| 5665 #if defined(DEBUG) | 5689 #if defined(DEBUG) |
| 5666 Isolate* isolate = Isolate::Current(); | 5690 Isolate* isolate = Isolate::Current(); |
| 5667 if (FLAG_verify_handles) { | 5691 if (FLAG_verify_handles) { |
| 5668 Heap* isolate_heap = isolate->heap(); | 5692 Heap* isolate_heap = isolate->heap(); |
| 5669 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 5693 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
| 5670 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || | 5694 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || |
| 5671 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); | 5695 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); |
| 5672 } | 5696 } |
| 5697 ASSERT(builtin_vtables_[cid] == | |
| 5698 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | |
| 5673 #endif | 5699 #endif |
| 5674 intptr_t cid = raw_->GetClassId(); | |
| 5675 if (cid < kNumPredefinedCids) { | |
| 5676 #if defined(DEBUG) | |
| 5677 ASSERT(builtin_vtables_[cid] == | |
| 5678 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | |
| 5679 #endif | |
| 5680 set_vtable(builtin_vtables_[cid]); | |
| 5681 } else { | |
| 5682 set_vtable(builtin_vtables_[kInstanceCid]); | |
| 5683 } | |
| 5684 } | 5700 } |
| 5685 | 5701 |
| 5686 | 5702 |
| 5687 bool Function::HasCode() const { | 5703 bool Function::HasCode() const { |
| 5688 return raw_ptr()->code_ != Code::null(); | 5704 return raw_ptr()->code_ != Code::null(); |
| 5689 } | 5705 } |
| 5690 | 5706 |
| 5691 | 5707 |
| 5692 intptr_t Field::Offset() const { | 5708 intptr_t Field::Offset() const { |
| 5693 ASSERT(!is_static()); // Offset is valid only for instance fields. | 5709 ASSERT(!is_static()); // Offset is valid only for instance fields. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5731 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5747 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5732 return false; | 5748 return false; |
| 5733 } | 5749 } |
| 5734 } | 5750 } |
| 5735 return true; | 5751 return true; |
| 5736 } | 5752 } |
| 5737 | 5753 |
| 5738 } // namespace dart | 5754 } // namespace dart |
| 5739 | 5755 |
| 5740 #endif // VM_OBJECT_H_ | 5756 #endif // VM_OBJECT_H_ |
| OLD | NEW |