| 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" |
| 11 #include "vm/json_stream.h" | 11 #include "vm/json_stream.h" |
| 12 #include "vm/bitmap.h" | 12 #include "vm/bitmap.h" |
| 13 #include "vm/dart.h" | 13 #include "vm/dart.h" |
| 14 #include "vm/globals.h" | 14 #include "vm/globals.h" |
| 15 #include "vm/handles.h" | 15 #include "vm/handles.h" |
| 16 #include "vm/heap.h" | 16 #include "vm/heap.h" |
| 17 #include "vm/isolate.h" | 17 #include "vm/isolate.h" |
| 18 #include "vm/method_recognizer.h" | 18 #include "vm/method_recognizer.h" |
| 19 #include "vm/os.h" | 19 #include "vm/os.h" |
| 20 #include "vm/raw_object.h" | 20 #include "vm/raw_object.h" |
| 21 #include "vm/report.h" | 21 #include "vm/report.h" |
| 22 #include "vm/scanner.h" | 22 #include "vm/scanner.h" |
| 23 #include "vm/tags.h" | 23 #include "vm/tags.h" |
| 24 #include "vm/thread.h" |
| 24 #include "vm/verified_memory.h" | 25 #include "vm/verified_memory.h" |
| 25 | 26 |
| 26 namespace dart { | 27 namespace dart { |
| 27 | 28 |
| 28 DECLARE_FLAG(bool, use_jscre); | 29 DECLARE_FLAG(bool, use_jscre); |
| 29 | 30 |
| 30 // Forward declarations. | 31 // Forward declarations. |
| 31 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 32 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
| 32 class clazz; | 33 class clazz; |
| 33 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 34 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 #if defined(DEBUG) | 53 #if defined(DEBUG) |
| 53 #define CHECK_HANDLE() CheckHandle(); | 54 #define CHECK_HANDLE() CheckHandle(); |
| 54 #else | 55 #else |
| 55 #define CHECK_HANDLE() | 56 #define CHECK_HANDLE() |
| 56 #endif | 57 #endif |
| 57 | 58 |
| 58 #define BASE_OBJECT_IMPLEMENTATION(object, super) \ | 59 #define BASE_OBJECT_IMPLEMENTATION(object, super) \ |
| 59 public: /* NOLINT */ \ | 60 public: /* NOLINT */ \ |
| 60 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ | 61 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ |
| 61 bool Is##object() const { return true; } \ | 62 bool Is##object() const { return true; } \ |
| 62 static object& Handle(Isolate* isolate, Raw##object* raw_ptr) { \ | 63 static object& Handle(Zone* zone, Raw##object* raw_ptr) { \ |
| 63 object* obj = \ | 64 object* obj = \ |
| 64 reinterpret_cast<object*>(VMHandles::AllocateHandle(isolate)); \ | 65 reinterpret_cast<object*>(VMHandles::AllocateHandle(zone)); \ |
| 65 initializeHandle(obj, raw_ptr); \ | 66 initializeHandle(obj, raw_ptr); \ |
| 66 return *obj; \ | 67 return *obj; \ |
| 67 } \ | 68 } \ |
| 69 /* DEPRECATED: Use Zone version. */ \ |
| 70 static object& Handle(Isolate* isolate, Raw##object* raw_ptr) { \ |
| 71 return Handle(isolate->current_zone(), raw_ptr); \ |
| 72 } \ |
| 68 static object& Handle() { \ | 73 static object& Handle() { \ |
| 69 return Handle(Isolate::Current(), object::null()); \ | 74 return Handle(Thread::Current()->zone(), object::null()); \ |
| 70 } \ | 75 } \ |
| 76 static object& Handle(Zone* zone) { \ |
| 77 return Handle(zone, object::null()); \ |
| 78 } \ |
| 79 /* DEPRECATED: Use Zone version. */ \ |
| 71 static object& Handle(Isolate* isolate) { \ | 80 static object& Handle(Isolate* isolate) { \ |
| 72 return Handle(isolate, object::null()); \ | 81 return Handle(isolate->current_zone(), object::null()); \ |
| 73 } \ | 82 } \ |
| 74 static object& Handle(Raw##object* raw_ptr) { \ | 83 static object& Handle(Raw##object* raw_ptr) { \ |
| 75 return Handle(Isolate::Current(), raw_ptr); \ | 84 return Handle(Thread::Current()->zone(), raw_ptr); \ |
| 76 } \ | 85 } \ |
| 77 static object& CheckedHandle(Isolate* isolate, RawObject* raw_ptr) { \ | 86 static object& CheckedHandle(Zone* zone, RawObject* raw_ptr) { \ |
| 78 object* obj = \ | 87 object* obj = \ |
| 79 reinterpret_cast<object*>(VMHandles::AllocateHandle(isolate)); \ | 88 reinterpret_cast<object*>(VMHandles::AllocateHandle(zone)); \ |
| 80 initializeHandle(obj, raw_ptr); \ | 89 initializeHandle(obj, raw_ptr); \ |
| 81 if (!obj->Is##object()) { \ | 90 if (!obj->Is##object()) { \ |
| 82 FATAL2("Handle check failed: saw %s expected %s", \ | 91 FATAL2("Handle check failed: saw %s expected %s", \ |
| 83 obj->ToCString(), #object); \ | 92 obj->ToCString(), #object); \ |
| 84 } \ | 93 } \ |
| 85 return *obj; \ | 94 return *obj; \ |
| 86 } \ | 95 } \ |
| 96 /* DEPRECATED: Use Zone version. */ \ |
| 97 static object& CheckedHandle(Isolate* isolate, RawObject* raw_ptr) { \ |
| 98 return CheckedHandle(isolate->current_zone(), raw_ptr); \ |
| 99 } \ |
| 87 static object& CheckedHandle(RawObject* raw_ptr) { \ | 100 static object& CheckedHandle(RawObject* raw_ptr) { \ |
| 88 return CheckedHandle(Isolate::Current(), raw_ptr); \ | 101 return CheckedHandle(Thread::Current()->zone(), raw_ptr); \ |
| 89 } \ | 102 } \ |
| 90 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \ | 103 static object& ZoneHandle(Zone* zone, Raw##object* raw_ptr) { \ |
| 91 object* obj = reinterpret_cast<object*>( \ | 104 object* obj = reinterpret_cast<object*>( \ |
| 92 VMHandles::AllocateZoneHandle(isolate)); \ | 105 VMHandles::AllocateZoneHandle(zone)); \ |
| 93 initializeHandle(obj, raw_ptr); \ | 106 initializeHandle(obj, raw_ptr); \ |
| 94 return *obj; \ | 107 return *obj; \ |
| 95 } \ | 108 } \ |
| 109 /* DEPRECATED: Use Zone version. */ \ |
| 110 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \ |
| 111 return ZoneHandle(isolate->current_zone(), raw_ptr); \ |
| 112 } \ |
| 96 static object* ReadOnlyHandle() { \ | 113 static object* ReadOnlyHandle() { \ |
| 97 object* obj = reinterpret_cast<object*>( \ | 114 object* obj = reinterpret_cast<object*>( \ |
| 98 Dart::AllocateReadOnlyHandle()); \ | 115 Dart::AllocateReadOnlyHandle()); \ |
| 99 initializeHandle(obj, object::null()); \ | 116 initializeHandle(obj, object::null()); \ |
| 100 return obj; \ | 117 return obj; \ |
| 101 } \ | 118 } \ |
| 119 static object& ZoneHandle(Zone* zone) { \ |
| 120 return ZoneHandle(zone, object::null()); \ |
| 121 } \ |
| 122 /* DEPRECATED: Use Zone version. */ \ |
| 102 static object& ZoneHandle(Isolate* isolate) { \ | 123 static object& ZoneHandle(Isolate* isolate) { \ |
| 103 return ZoneHandle(isolate, object::null()); \ | 124 return ZoneHandle(isolate->current_zone(), object::null()); \ |
| 104 } \ | 125 } \ |
| 105 static object& ZoneHandle() { \ | 126 static object& ZoneHandle() { \ |
| 106 return ZoneHandle(Isolate::Current(), object::null()); \ | 127 return ZoneHandle(Thread::Current()->zone(), object::null()); \ |
| 107 } \ | 128 } \ |
| 108 static object& ZoneHandle(Raw##object* raw_ptr) { \ | 129 static object& ZoneHandle(Raw##object* raw_ptr) { \ |
| 109 return ZoneHandle(Isolate::Current(), raw_ptr); \ | 130 return ZoneHandle(Thread::Current()->zone(), raw_ptr); \ |
| 110 } \ | 131 } \ |
| 111 static object& CheckedZoneHandle(Isolate* isolate, RawObject* raw_ptr) { \ | 132 static object& CheckedZoneHandle(Zone* zone, RawObject* raw_ptr) { \ |
| 112 object* obj = reinterpret_cast<object*>( \ | 133 object* obj = reinterpret_cast<object*>( \ |
| 113 VMHandles::AllocateZoneHandle(isolate)); \ | 134 VMHandles::AllocateZoneHandle(zone)); \ |
| 114 initializeHandle(obj, raw_ptr); \ | 135 initializeHandle(obj, raw_ptr); \ |
| 115 if (!obj->Is##object()) { \ | 136 if (!obj->Is##object()) { \ |
| 116 FATAL2("Handle check failed: saw %s expected %s", \ | 137 FATAL2("Handle check failed: saw %s expected %s", \ |
| 117 obj->ToCString(), #object); \ | 138 obj->ToCString(), #object); \ |
| 118 } \ | 139 } \ |
| 119 return *obj; \ | 140 return *obj; \ |
| 120 } \ | 141 } \ |
| 121 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ | 142 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ |
| 122 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \ | 143 return CheckedZoneHandle(Thread::Current()->zone(), raw_ptr); \ |
| 123 } \ | 144 } \ |
| 124 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ | 145 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ |
| 125 /* is not setup for type T, although some methods are supposed to work */ \ | 146 /* is not setup for type T, although some methods are supposed to work */ \ |
| 126 /* with null, for example Instance::Equals(). */ \ | 147 /* with null, for example Instance::Equals(). */ \ |
| 127 static const object& Cast(const Object& obj) { \ | 148 static const object& Cast(const Object& obj) { \ |
| 128 ASSERT(obj.Is##object()); \ | 149 ASSERT(obj.Is##object()); \ |
| 129 return reinterpret_cast<const object&>(obj); \ | 150 return reinterpret_cast<const object&>(obj); \ |
| 130 } \ | 151 } \ |
| 131 static Raw##object* RawCast(RawObject* raw) { \ | 152 static Raw##object* RawCast(RawObject* raw) { \ |
| 132 ASSERT(Object::Handle(raw).Is##object()); \ | 153 ASSERT(Object::Handle(raw).Is##object()); \ |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void Print() const; | 335 void Print() const; |
| 315 | 336 |
| 316 bool IsZoneHandle() const { | 337 bool IsZoneHandle() const { |
| 317 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); | 338 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); |
| 318 } | 339 } |
| 319 | 340 |
| 320 bool IsReadOnlyHandle() const; | 341 bool IsReadOnlyHandle() const; |
| 321 | 342 |
| 322 bool IsNotTemporaryScopedHandle() const; | 343 bool IsNotTemporaryScopedHandle() const; |
| 323 | 344 |
| 324 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { | 345 static Object& Handle(Zone* zone, RawObject* raw_ptr) { |
| 325 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); | 346 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(zone)); |
| 326 initializeHandle(obj, raw_ptr); | 347 initializeHandle(obj, raw_ptr); |
| 327 return *obj; | 348 return *obj; |
| 328 } | 349 } |
| 350 // DEPRECATED: Use Zone version. |
| 351 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { |
| 352 return Handle(isolate->current_zone(), raw_ptr); |
| 353 } |
| 329 static Object* ReadOnlyHandle() { | 354 static Object* ReadOnlyHandle() { |
| 330 Object* obj = reinterpret_cast<Object*>( | 355 Object* obj = reinterpret_cast<Object*>( |
| 331 Dart::AllocateReadOnlyHandle()); | 356 Dart::AllocateReadOnlyHandle()); |
| 332 initializeHandle(obj, Object::null()); | 357 initializeHandle(obj, Object::null()); |
| 333 return obj; | 358 return obj; |
| 334 } | 359 } |
| 335 | 360 |
| 336 static Object& Handle() { | 361 static Object& Handle() { |
| 337 return Handle(Isolate::Current(), null_); | 362 return Handle(Isolate::Current(), null_); |
| 338 } | 363 } |
| 339 | 364 |
| 365 static Object& Handle(Zone* zone) { |
| 366 return Handle(zone, null_); |
| 367 } |
| 368 // DEPRECATED: Use Zone version. |
| 340 static Object& Handle(Isolate* isolate) { | 369 static Object& Handle(Isolate* isolate) { |
| 341 return Handle(isolate, null_); | 370 return Handle(isolate->current_zone(), null_); |
| 342 } | 371 } |
| 343 | 372 |
| 344 static Object& Handle(RawObject* raw_ptr) { | 373 static Object& Handle(RawObject* raw_ptr) { |
| 345 return Handle(Isolate::Current(), raw_ptr); | 374 return Handle(Isolate::Current(), raw_ptr); |
| 346 } | 375 } |
| 347 | 376 |
| 348 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { | 377 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { |
| 349 Object* obj = reinterpret_cast<Object*>( | 378 Object* obj = reinterpret_cast<Object*>( |
| 350 VMHandles::AllocateZoneHandle(isolate)); | 379 VMHandles::AllocateZoneHandle(isolate->current_zone())); |
| 351 initializeHandle(obj, raw_ptr); | 380 initializeHandle(obj, raw_ptr); |
| 352 return *obj; | 381 return *obj; |
| 353 } | 382 } |
| 354 | 383 |
| 355 static Object& ZoneHandle() { | 384 static Object& ZoneHandle() { |
| 356 return ZoneHandle(Isolate::Current(), null_); | 385 return ZoneHandle(Isolate::Current(), null_); |
| 357 } | 386 } |
| 358 | 387 |
| 359 static Object& ZoneHandle(RawObject* raw_ptr) { | 388 static Object& ZoneHandle(RawObject* raw_ptr) { |
| 360 return ZoneHandle(Isolate::Current(), raw_ptr); | 389 return ZoneHandle(Isolate::Current(), raw_ptr); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 | 827 |
| 799 class PassiveObject : public Object { | 828 class PassiveObject : public Object { |
| 800 public: | 829 public: |
| 801 void operator=(RawObject* value) { | 830 void operator=(RawObject* value) { |
| 802 raw_ = value; | 831 raw_ = value; |
| 803 } | 832 } |
| 804 void operator^=(RawObject* value) { | 833 void operator^=(RawObject* value) { |
| 805 raw_ = value; | 834 raw_ = value; |
| 806 } | 835 } |
| 807 static PassiveObject& Handle(Isolate* I, RawObject* raw_ptr) { | 836 static PassiveObject& Handle(Isolate* I, RawObject* raw_ptr) { |
| 808 PassiveObject* obj = | 837 PassiveObject* obj = reinterpret_cast<PassiveObject*>( |
| 809 reinterpret_cast<PassiveObject*>(VMHandles::AllocateHandle(I)); | 838 VMHandles::AllocateHandle(I->current_zone())); |
| 810 obj->raw_ = raw_ptr; | 839 obj->raw_ = raw_ptr; |
| 811 obj->set_vtable(0); | 840 obj->set_vtable(0); |
| 812 return *obj; | 841 return *obj; |
| 813 } | 842 } |
| 814 static PassiveObject& Handle(RawObject* raw_ptr) { | 843 static PassiveObject& Handle(RawObject* raw_ptr) { |
| 815 return Handle(Isolate::Current(), raw_ptr); | 844 return Handle(Isolate::Current(), raw_ptr); |
| 816 } | 845 } |
| 817 static PassiveObject& Handle() { | 846 static PassiveObject& Handle() { |
| 818 return Handle(Isolate::Current(), Object::null()); | 847 return Handle(Isolate::Current(), Object::null()); |
| 819 } | 848 } |
| 849 // DEPRECATED |
| 850 // TODO(koda): Add Zone version. |
| 820 static PassiveObject& Handle(Isolate* I) { | 851 static PassiveObject& Handle(Isolate* I) { |
| 821 return Handle(I, Object::null()); | 852 return Handle(I, Object::null()); |
| 822 } | 853 } |
| 854 // DEPRECATED |
| 855 // TODO(koda): Add Zone version. |
| 823 static PassiveObject& ZoneHandle(Isolate* I, RawObject* raw_ptr) { | 856 static PassiveObject& ZoneHandle(Isolate* I, RawObject* raw_ptr) { |
| 824 PassiveObject* obj = reinterpret_cast<PassiveObject*>( | 857 PassiveObject* obj = reinterpret_cast<PassiveObject*>( |
| 825 VMHandles::AllocateZoneHandle(I)); | 858 VMHandles::AllocateZoneHandle(I->current_zone())); |
| 826 obj->raw_ = raw_ptr; | 859 obj->raw_ = raw_ptr; |
| 827 obj->set_vtable(0); | 860 obj->set_vtable(0); |
| 828 return *obj; | 861 return *obj; |
| 829 } | 862 } |
| 830 static PassiveObject& ZoneHandle(RawObject* raw_ptr) { | 863 static PassiveObject& ZoneHandle(RawObject* raw_ptr) { |
| 831 return ZoneHandle(Isolate::Current(), raw_ptr); | 864 return ZoneHandle(Isolate::Current(), raw_ptr); |
| 832 } | 865 } |
| 833 static PassiveObject& ZoneHandle() { | 866 static PassiveObject& ZoneHandle() { |
| 834 return ZoneHandle(Isolate::Current(), Object::null()); | 867 return ZoneHandle(Isolate::Current(), Object::null()); |
| 835 } | 868 } |
| 869 // DEPRECATED |
| 870 // TODO(koda): Add Zone version. |
| 836 static PassiveObject& ZoneHandle(Isolate* I) { | 871 static PassiveObject& ZoneHandle(Isolate* I) { |
| 837 return ZoneHandle(I, Object::null()); | 872 return ZoneHandle(I, Object::null()); |
| 838 } | 873 } |
| 839 | 874 |
| 840 private: | 875 private: |
| 841 PassiveObject() : Object() {} | 876 PassiveObject() : Object() {} |
| 842 DISALLOW_ALLOCATION(); | 877 DISALLOW_ALLOCATION(); |
| 843 DISALLOW_COPY_AND_ASSIGN(PassiveObject); | 878 DISALLOW_COPY_AND_ASSIGN(PassiveObject); |
| 844 }; | 879 }; |
| 845 | 880 |
| (...skipping 6858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7704 | 7739 |
| 7705 | 7740 |
| 7706 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7741 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 7707 intptr_t index) { | 7742 intptr_t index) { |
| 7708 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7743 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 7709 } | 7744 } |
| 7710 | 7745 |
| 7711 } // namespace dart | 7746 } // namespace dart |
| 7712 | 7747 |
| 7713 #endif // VM_OBJECT_H_ | 7748 #endif // VM_OBJECT_H_ |
| OLD | NEW |