Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: runtime/vm/object.h

Issue 868913002: Add Zone-based handle allocation interface and reduce use of Isolate-based interfaces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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); \
Ivan Posva 2015/01/23 04:53:04 I thought we had switched to isolate->zone() from
koda 2015/01/23 14:29:31 No, that renaming concerned Thread::zone. Since Is
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); \
102 } \
103 static object& ZoneHandle(Zone* zone, Raw##object* raw_ptr) { \
104 object* obj = reinterpret_cast<object*>( \
105 VMHandles::AllocateZoneHandle(zone)); \
106 initializeHandle(obj, raw_ptr); \
107 return *obj; \
89 } \ 108 } \
90 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \ 109 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \
91 object* obj = reinterpret_cast<object*>( \ 110 return ZoneHandle(isolate->current_zone(), raw_ptr); \
92 VMHandles::AllocateZoneHandle(isolate)); \
93 initializeHandle(obj, raw_ptr); \
94 return *obj; \
95 } \ 111 } \
96 static object* ReadOnlyHandle() { \ 112 static object* ReadOnlyHandle() { \
97 object* obj = reinterpret_cast<object*>( \ 113 object* obj = reinterpret_cast<object*>( \
98 Dart::AllocateReadOnlyHandle()); \ 114 Dart::AllocateReadOnlyHandle()); \
99 initializeHandle(obj, object::null()); \ 115 initializeHandle(obj, object::null()); \
100 return obj; \ 116 return obj; \
101 } \ 117 } \
118 static object& ZoneHandle(Zone* zone) { \
119 return ZoneHandle(zone, object::null()); \
120 } \
121 /* DEPRECATED: Use Zone version. */ \
102 static object& ZoneHandle(Isolate* isolate) { \ 122 static object& ZoneHandle(Isolate* isolate) { \
103 return ZoneHandle(isolate, object::null()); \ 123 return ZoneHandle(isolate->current_zone(), object::null()); \
104 } \ 124 } \
105 static object& ZoneHandle() { \ 125 static object& ZoneHandle() { \
106 return ZoneHandle(Isolate::Current(), object::null()); \ 126 return ZoneHandle(Thread::Current()->zone(), object::null()); \
107 } \ 127 } \
108 static object& ZoneHandle(Raw##object* raw_ptr) { \ 128 static object& ZoneHandle(Raw##object* raw_ptr) { \
109 return ZoneHandle(Isolate::Current(), raw_ptr); \ 129 return ZoneHandle(Thread::Current()->zone(), raw_ptr); \
110 } \ 130 } \
111 static object& CheckedZoneHandle(Isolate* isolate, RawObject* raw_ptr) { \ 131 static object& CheckedZoneHandle(Zone* zone, RawObject* raw_ptr) { \
112 object* obj = reinterpret_cast<object*>( \ 132 object* obj = reinterpret_cast<object*>( \
113 VMHandles::AllocateZoneHandle(isolate)); \ 133 VMHandles::AllocateZoneHandle(zone)); \
114 initializeHandle(obj, raw_ptr); \ 134 initializeHandle(obj, raw_ptr); \
115 if (!obj->Is##object()) { \ 135 if (!obj->Is##object()) { \
116 FATAL2("Handle check failed: saw %s expected %s", \ 136 FATAL2("Handle check failed: saw %s expected %s", \
117 obj->ToCString(), #object); \ 137 obj->ToCString(), #object); \
118 } \ 138 } \
119 return *obj; \ 139 return *obj; \
120 } \ 140 } \
121 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ 141 static object& CheckedZoneHandle(RawObject* raw_ptr) { \
122 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \ 142 return CheckedZoneHandle(Thread::Current()->zone(), raw_ptr); \
123 } \ 143 } \
124 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ 144 /* 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 */ \ 145 /* is not setup for type T, although some methods are supposed to work */ \
126 /* with null, for example Instance::Equals(). */ \ 146 /* with null, for example Instance::Equals(). */ \
127 static const object& Cast(const Object& obj) { \ 147 static const object& Cast(const Object& obj) { \
128 ASSERT(obj.Is##object()); \ 148 ASSERT(obj.Is##object()); \
129 return reinterpret_cast<const object&>(obj); \ 149 return reinterpret_cast<const object&>(obj); \
130 } \ 150 } \
131 static Raw##object* RawCast(RawObject* raw) { \ 151 static Raw##object* RawCast(RawObject* raw) { \
132 ASSERT(Object::Handle(raw).Is##object()); \ 152 ASSERT(Object::Handle(raw).Is##object()); \
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void Print() const; 334 void Print() const;
315 335
316 bool IsZoneHandle() const { 336 bool IsZoneHandle() const {
317 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); 337 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this));
318 } 338 }
319 339
320 bool IsReadOnlyHandle() const; 340 bool IsReadOnlyHandle() const;
321 341
322 bool IsNotTemporaryScopedHandle() const; 342 bool IsNotTemporaryScopedHandle() const;
323 343
324 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { 344 static Object& Handle(Zone* zone, RawObject* raw_ptr) {
325 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); 345 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(zone));
326 initializeHandle(obj, raw_ptr); 346 initializeHandle(obj, raw_ptr);
327 return *obj; 347 return *obj;
328 } 348 }
349 // DEPRECATED: Use Zone version.
350 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) {
351 return Handle(isolate->current_zone(), raw_ptr);
352 }
329 static Object* ReadOnlyHandle() { 353 static Object* ReadOnlyHandle() {
330 Object* obj = reinterpret_cast<Object*>( 354 Object* obj = reinterpret_cast<Object*>(
331 Dart::AllocateReadOnlyHandle()); 355 Dart::AllocateReadOnlyHandle());
332 initializeHandle(obj, Object::null()); 356 initializeHandle(obj, Object::null());
333 return obj; 357 return obj;
334 } 358 }
335 359
336 static Object& Handle() { 360 static Object& Handle() {
337 return Handle(Isolate::Current(), null_); 361 return Handle(Isolate::Current(), null_);
338 } 362 }
339 363
364 static Object& Handle(Zone* zone) {
365 return Handle(zone, null_);
366 }
367 // DEPRECATED: Use Zone version.
340 static Object& Handle(Isolate* isolate) { 368 static Object& Handle(Isolate* isolate) {
341 return Handle(isolate, null_); 369 return Handle(isolate->current_zone(), null_);
342 } 370 }
343 371
344 static Object& Handle(RawObject* raw_ptr) { 372 static Object& Handle(RawObject* raw_ptr) {
345 return Handle(Isolate::Current(), raw_ptr); 373 return Handle(Isolate::Current(), raw_ptr);
346 } 374 }
347 375
348 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { 376 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) {
siva 2015/01/23 19:29:27 DEPRECATED tag for this too.
koda 2015/01/23 21:09:42 Done.
349 Object* obj = reinterpret_cast<Object*>( 377 Object* obj = reinterpret_cast<Object*>(
350 VMHandles::AllocateZoneHandle(isolate)); 378 VMHandles::AllocateZoneHandle(isolate->current_zone()));
351 initializeHandle(obj, raw_ptr); 379 initializeHandle(obj, raw_ptr);
352 return *obj; 380 return *obj;
353 } 381 }
354 382
355 static Object& ZoneHandle() { 383 static Object& ZoneHandle() {
356 return ZoneHandle(Isolate::Current(), null_); 384 return ZoneHandle(Isolate::Current(), null_);
357 } 385 }
358 386
359 static Object& ZoneHandle(RawObject* raw_ptr) { 387 static Object& ZoneHandle(RawObject* raw_ptr) {
360 return ZoneHandle(Isolate::Current(), raw_ptr); 388 return ZoneHandle(Isolate::Current(), raw_ptr);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 825
798 826
799 class PassiveObject : public Object { 827 class PassiveObject : public Object {
800 public: 828 public:
801 void operator=(RawObject* value) { 829 void operator=(RawObject* value) {
802 raw_ = value; 830 raw_ = value;
803 } 831 }
804 void operator^=(RawObject* value) { 832 void operator^=(RawObject* value) {
805 raw_ = value; 833 raw_ = value;
806 } 834 }
807 static PassiveObject& Handle(Isolate* I, RawObject* raw_ptr) { 835 static PassiveObject& Handle(Isolate* I, RawObject* raw_ptr) {
siva 2015/01/23 19:29:27 Deprecated tag for this too.
koda 2015/01/23 21:09:42 Done.
808 PassiveObject* obj = 836 PassiveObject* obj = reinterpret_cast<PassiveObject*>(
809 reinterpret_cast<PassiveObject*>(VMHandles::AllocateHandle(I)); 837 VMHandles::AllocateHandle(I->current_zone()));
810 obj->raw_ = raw_ptr; 838 obj->raw_ = raw_ptr;
811 obj->set_vtable(0); 839 obj->set_vtable(0);
812 return *obj; 840 return *obj;
813 } 841 }
814 static PassiveObject& Handle(RawObject* raw_ptr) { 842 static PassiveObject& Handle(RawObject* raw_ptr) {
815 return Handle(Isolate::Current(), raw_ptr); 843 return Handle(Isolate::Current(), raw_ptr);
816 } 844 }
817 static PassiveObject& Handle() { 845 static PassiveObject& Handle() {
818 return Handle(Isolate::Current(), Object::null()); 846 return Handle(Isolate::Current(), Object::null());
819 } 847 }
820 static PassiveObject& Handle(Isolate* I) { 848 static PassiveObject& Handle(Isolate* I) {
siva 2015/01/23 19:29:27 Deprecated tag.
koda 2015/01/23 21:09:42 Done.
821 return Handle(I, Object::null()); 849 return Handle(I, Object::null());
822 } 850 }
823 static PassiveObject& ZoneHandle(Isolate* I, RawObject* raw_ptr) { 851 static PassiveObject& ZoneHandle(Isolate* I, RawObject* raw_ptr) {
siva 2015/01/23 19:29:27 Deprecated tag?
koda 2015/01/23 21:09:42 Done.
824 PassiveObject* obj = reinterpret_cast<PassiveObject*>( 852 PassiveObject* obj = reinterpret_cast<PassiveObject*>(
825 VMHandles::AllocateZoneHandle(I)); 853 VMHandles::AllocateZoneHandle(I->current_zone()));
826 obj->raw_ = raw_ptr; 854 obj->raw_ = raw_ptr;
827 obj->set_vtable(0); 855 obj->set_vtable(0);
828 return *obj; 856 return *obj;
829 } 857 }
830 static PassiveObject& ZoneHandle(RawObject* raw_ptr) { 858 static PassiveObject& ZoneHandle(RawObject* raw_ptr) {
831 return ZoneHandle(Isolate::Current(), raw_ptr); 859 return ZoneHandle(Isolate::Current(), raw_ptr);
832 } 860 }
833 static PassiveObject& ZoneHandle() { 861 static PassiveObject& ZoneHandle() {
834 return ZoneHandle(Isolate::Current(), Object::null()); 862 return ZoneHandle(Isolate::Current(), Object::null());
835 } 863 }
(...skipping 6868 matching lines...) Expand 10 before | Expand all | Expand 10 after
7704 7732
7705 7733
7706 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7734 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7707 intptr_t index) { 7735 intptr_t index) {
7708 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7736 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7709 } 7737 }
7710 7738
7711 } // namespace dart 7739 } // namespace dart
7712 7740
7713 #endif // VM_OBJECT_H_ 7741 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698