| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return raw()->ptr(); \ | 143 return raw()->ptr(); \ |
| 144 } \ | 144 } \ |
| 145 SNAPSHOT_READER_SUPPORT(object) \ | 145 SNAPSHOT_READER_SUPPORT(object) \ |
| 146 friend class StackFrame; \ | 146 friend class StackFrame; \ |
| 147 | 147 |
| 148 class Object { | 148 class Object { |
| 149 public: | 149 public: |
| 150 virtual ~Object() { } | 150 virtual ~Object() { } |
| 151 | 151 |
| 152 RawObject* raw() const { return raw_; } | 152 RawObject* raw() const { return raw_; } |
| 153 void operator=(RawObject* value) { SetRaw(value); } | 153 void operator=(RawObject* value) { |
| 154 initializeHandle(this, value); |
| 155 } |
| 154 | 156 |
| 155 void set_tags(intptr_t value) const { | 157 void set_tags(intptr_t value) const { |
| 156 // TODO(asiva): Remove the capability of setting tags in general. The mask | 158 // TODO(asiva): Remove the capability of setting tags in general. The mask |
| 157 // here only allows for canonical and from_snapshot flags to be set. | 159 // here only allows for canonical and from_snapshot flags to be set. |
| 158 ASSERT(!IsNull()); | 160 ASSERT(!IsNull()); |
| 159 uword tags = raw()->ptr()->tags_ & ~0x0000000c; | 161 uword tags = raw()->ptr()->tags_ & ~0x0000000c; |
| 160 raw()->ptr()->tags_ = tags | (value & 0x0000000c); | 162 raw()->ptr()->tags_ = tags | (value & 0x0000000c); |
| 161 } | 163 } |
| 162 void SetCreatedFromSnapshot() const { | 164 void SetCreatedFromSnapshot() const { |
| 163 ASSERT(!IsNull()); | 165 ASSERT(!IsNull()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 void Print() const; | 207 void Print() const; |
| 206 | 208 |
| 207 bool IsZoneHandle() const { | 209 bool IsZoneHandle() const { |
| 208 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); | 210 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); |
| 209 } | 211 } |
| 210 | 212 |
| 211 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew); | 213 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew); |
| 212 | 214 |
| 213 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { | 215 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { |
| 214 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); | 216 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); |
| 215 obj->SetRaw(raw_ptr); | 217 initializeHandle(obj, raw_ptr); |
| 216 return *obj; | 218 return *obj; |
| 217 } | 219 } |
| 218 | 220 |
| 219 static Object& Handle() { | 221 static Object& Handle() { |
| 220 return Handle(Isolate::Current(), null_); | 222 return Handle(Isolate::Current(), null_); |
| 221 } | 223 } |
| 222 | 224 |
| 223 static Object& Handle(Isolate* isolate) { | 225 static Object& Handle(Isolate* isolate) { |
| 224 return Handle(isolate, null_); | 226 return Handle(isolate, null_); |
| 225 } | 227 } |
| 226 | 228 |
| 227 static Object& Handle(RawObject* raw_ptr) { | 229 static Object& Handle(RawObject* raw_ptr) { |
| 228 return Handle(Isolate::Current(), raw_ptr); | 230 return Handle(Isolate::Current(), raw_ptr); |
| 229 } | 231 } |
| 230 | 232 |
| 231 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { | 233 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { |
| 232 Object* obj = reinterpret_cast<Object*>( | 234 Object* obj = reinterpret_cast<Object*>( |
| 233 VMHandles::AllocateZoneHandle(isolate)); | 235 VMHandles::AllocateZoneHandle(isolate)); |
| 234 obj->SetRaw(raw_ptr); | 236 initializeHandle(obj, raw_ptr); |
| 235 return *obj; | 237 return *obj; |
| 236 } | 238 } |
| 237 | 239 |
| 238 static Object& ZoneHandle() { | 240 static Object& ZoneHandle() { |
| 239 return ZoneHandle(Isolate::Current(), null_); | 241 return ZoneHandle(Isolate::Current(), null_); |
| 240 } | 242 } |
| 241 | 243 |
| 242 static Object& ZoneHandle(RawObject* raw_ptr) { | 244 static Object& ZoneHandle(RawObject* raw_ptr) { |
| 243 return ZoneHandle(Isolate::Current(), raw_ptr); | 245 return ZoneHandle(Isolate::Current(), raw_ptr); |
| 244 } | 246 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 static RawClass* CreateAndRegisterInterface(const char* cname, | 366 static RawClass* CreateAndRegisterInterface(const char* cname, |
| 365 const Script& script, | 367 const Script& script, |
| 366 const Library& lib); | 368 const Library& lib); |
| 367 static void RegisterClass(const Class& cls, | 369 static void RegisterClass(const Class& cls, |
| 368 const String& name, | 370 const String& name, |
| 369 const Library& lib); | 371 const Library& lib); |
| 370 static void RegisterPrivateClass(const Class& cls, | 372 static void RegisterPrivateClass(const Class& cls, |
| 371 const String& name, | 373 const String& name, |
| 372 const Library& lib); | 374 const Library& lib); |
| 373 | 375 |
| 376 /* Initialize the handle based on the raw_ptr in the presence of null. */ |
| 377 static void initializeHandle(Object* obj, RawObject* raw_ptr) { |
| 378 if (raw_ptr != Object::null()) { |
| 379 obj->SetRaw(raw_ptr); |
| 380 } else { |
| 381 obj->raw_ = Object::null(); |
| 382 Object fake_object; |
| 383 obj->set_vtable(fake_object.vtable()); |
| 384 } |
| 385 } |
| 386 |
| 374 cpp_vtable* vtable_address() const { | 387 cpp_vtable* vtable_address() const { |
| 375 uword vtable_addr = reinterpret_cast<uword>(this); | 388 uword vtable_addr = reinterpret_cast<uword>(this); |
| 376 return reinterpret_cast<cpp_vtable*>(vtable_addr); | 389 return reinterpret_cast<cpp_vtable*>(vtable_addr); |
| 377 } | 390 } |
| 378 | 391 |
| 379 static cpp_vtable handle_vtable_; | 392 static cpp_vtable handle_vtable_; |
| 380 static cpp_vtable builtin_vtables_[kNumPredefinedCids]; | 393 static cpp_vtable builtin_vtables_[kNumPredefinedCids]; |
| 381 | 394 |
| 382 // The static values below are singletons shared between the different | 395 // The static values below are singletons shared between the different |
| 383 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. | 396 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. |
| (...skipping 5385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5769 | 5782 |
| 5770 | 5783 |
| 5771 void Object::SetRaw(RawObject* value) { | 5784 void Object::SetRaw(RawObject* value) { |
| 5772 // NOTE: The assignment "raw_ = value" should be the first statement in | 5785 // NOTE: The assignment "raw_ = value" should be the first statement in |
| 5773 // this function. Also do not use 'value' in this function after the | 5786 // this function. Also do not use 'value' in this function after the |
| 5774 // assignment (use 'raw_' instead). | 5787 // assignment (use 'raw_' instead). |
| 5775 raw_ = value; | 5788 raw_ = value; |
| 5776 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) { | 5789 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) { |
| 5777 set_vtable(Smi::handle_vtable_); | 5790 set_vtable(Smi::handle_vtable_); |
| 5778 return; | 5791 return; |
| 5779 } else if (raw_ == null_) { | |
| 5780 set_vtable(handle_vtable_); | |
| 5781 return; | |
| 5782 } | 5792 } |
| 5783 | 5793 intptr_t cid = raw_->GetClassId(); |
| 5794 if (cid >= kNumPredefinedCids) { |
| 5795 cid = kInstanceCid; |
| 5796 } |
| 5797 set_vtable(builtin_vtables_[cid]); |
| 5784 #if defined(DEBUG) | 5798 #if defined(DEBUG) |
| 5785 Isolate* isolate = Isolate::Current(); | 5799 Isolate* isolate = Isolate::Current(); |
| 5786 if (FLAG_verify_handles) { | 5800 if (FLAG_verify_handles) { |
| 5787 Heap* isolate_heap = isolate->heap(); | 5801 Heap* isolate_heap = isolate->heap(); |
| 5788 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 5802 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
| 5789 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || | 5803 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || |
| 5790 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); | 5804 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); |
| 5791 } | 5805 } |
| 5806 ASSERT(builtin_vtables_[cid] == |
| 5807 isolate->class_table()->At(cid)->ptr()->handle_vtable_); |
| 5792 #endif | 5808 #endif |
| 5793 intptr_t cid = raw_->GetClassId(); | |
| 5794 if (cid < kNumPredefinedCids) { | |
| 5795 #if defined(DEBUG) | |
| 5796 ASSERT(builtin_vtables_[cid] == | |
| 5797 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | |
| 5798 #endif | |
| 5799 set_vtable(builtin_vtables_[cid]); | |
| 5800 } else { | |
| 5801 set_vtable(builtin_vtables_[kInstanceCid]); | |
| 5802 } | |
| 5803 } | 5809 } |
| 5804 | 5810 |
| 5805 | 5811 |
| 5806 bool Function::HasCode() const { | 5812 bool Function::HasCode() const { |
| 5807 return raw_ptr()->code_ != Code::null(); | 5813 return raw_ptr()->code_ != Code::null(); |
| 5808 } | 5814 } |
| 5809 | 5815 |
| 5810 | 5816 |
| 5811 intptr_t Field::Offset() const { | 5817 intptr_t Field::Offset() const { |
| 5812 ASSERT(!is_static()); // Offset is valid only for instance fields. | 5818 ASSERT(!is_static()); // Offset is valid only for instance fields. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5850 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5856 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5851 return false; | 5857 return false; |
| 5852 } | 5858 } |
| 5853 } | 5859 } |
| 5854 return true; | 5860 return true; |
| 5855 } | 5861 } |
| 5856 | 5862 |
| 5857 } // namespace dart | 5863 } // namespace dart |
| 5858 | 5864 |
| 5859 #endif // VM_OBJECT_H_ | 5865 #endif // VM_OBJECT_H_ |
| OLD | NEW |