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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ASSERT(Object::Handle(raw).Is##object()); \ | 127 ASSERT(Object::Handle(raw).Is##object()); \ |
128 return reinterpret_cast<Raw##object*>(raw); \ | 128 return reinterpret_cast<Raw##object*>(raw); \ |
129 } \ | 129 } \ |
130 static Raw##object* null() { \ | 130 static Raw##object* null() { \ |
131 return reinterpret_cast<Raw##object*>(Object::null()); \ | 131 return reinterpret_cast<Raw##object*>(Object::null()); \ |
132 } \ | 132 } \ |
133 virtual const char* ToCString() const; \ | 133 virtual const char* ToCString() const; \ |
134 /* Object is printed as JSON into stream. If ref is true only a header */ \ | 134 /* Object is printed as JSON into stream. If ref is true only a header */ \ |
135 /* with an object id is printed. If ref is false the object is fully */ \ | 135 /* with an object id is printed. If ref is false the object is fully */ \ |
136 /* printed. */ \ | 136 /* printed. */ \ |
137 virtual void PrintToJSONStream(JSONStream* stream, bool ref = true) const; \ | |
138 virtual const char* JSONType(bool ref) const { \ | 137 virtual const char* JSONType(bool ref) const { \ |
139 return ref ? "@"#object : ""#object; \ | 138 return ref ? "@"#object : ""#object; \ |
140 } \ | 139 } \ |
141 static const ClassId kClassId = k##object##Cid; \ | 140 static const ClassId kClassId = k##object##Cid; \ |
| 141 protected: /* NOLINT */ \ |
| 142 virtual void PrintJSONImpl(JSONStream* stream, bool ref) const; \ |
142 private: /* NOLINT */ \ | 143 private: /* NOLINT */ \ |
143 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ | 144 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ |
144 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ | 145 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ |
145 if (raw_ptr != Object::null()) { \ | 146 if (raw_ptr != Object::null()) { \ |
146 obj->SetRaw(raw_ptr); \ | 147 obj->SetRaw(raw_ptr); \ |
147 } else { \ | 148 } else { \ |
148 obj->raw_ = Object::null(); \ | 149 obj->raw_ = Object::null(); \ |
149 object fake_object; \ | 150 object fake_object; \ |
150 obj->set_vtable(fake_object.vtable()); \ | 151 obj->set_vtable(fake_object.vtable()); \ |
151 } \ | 152 } \ |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 bool IsNull() const { return raw_ == null_; } | 262 bool IsNull() const { return raw_ == null_; } |
262 | 263 |
263 virtual const char* ToCString() const { | 264 virtual const char* ToCString() const { |
264 if (IsNull()) { | 265 if (IsNull()) { |
265 return "null"; | 266 return "null"; |
266 } else { | 267 } else { |
267 return "Object"; | 268 return "Object"; |
268 } | 269 } |
269 } | 270 } |
270 | 271 |
271 virtual void PrintToJSONStream(JSONStream* stream, bool ref = true) const { | 272 void PrintJSON(JSONStream* stream, bool ref = true) const; |
272 JSONObject jsobj(stream); | |
273 jsobj.AddProperty("type", JSONType(ref)); | |
274 } | |
275 | 273 |
276 virtual const char* JSONType(bool ref) const { | 274 virtual const char* JSONType(bool ref) const { |
277 return IsNull() ? "null" : "Object"; | 275 return IsNull() ? "null" : "Object"; |
278 } | 276 } |
279 | 277 |
280 // Returns the name that is used to identify an object in the | 278 // Returns the name that is used to identify an object in the |
281 // namespace dictionary. | 279 // namespace dictionary. |
282 // Object::DictionaryName() returns String::null(). Only subclasses | 280 // Object::DictionaryName() returns String::null(). Only subclasses |
283 // of Object that need to be entered in the library and library prefix | 281 // of Object that need to be entered in the library and library prefix |
284 // namespaces need to provide an implementation. | 282 // namespaces need to provide an implementation. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (!value->IsHeapObject()) return; | 535 if (!value->IsHeapObject()) return; |
538 if (value->IsNewObject() && raw()->IsOldObject() && | 536 if (value->IsNewObject() && raw()->IsOldObject() && |
539 !raw()->IsRemembered()) { | 537 !raw()->IsRemembered()) { |
540 raw()->SetRememberedBit(); | 538 raw()->SetRememberedBit(); |
541 Isolate::Current()->store_buffer()->AddObject(raw()); | 539 Isolate::Current()->store_buffer()->AddObject(raw()); |
542 } | 540 } |
543 } | 541 } |
544 | 542 |
545 RawObject* raw_; // The raw object reference. | 543 RawObject* raw_; // The raw object reference. |
546 | 544 |
| 545 protected: |
| 546 virtual void PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 547 JSONObject jsobj(stream); |
| 548 jsobj.AddProperty("type", JSONType(ref)); |
| 549 } |
| 550 |
547 private: | 551 private: |
548 static intptr_t NextFieldOffset() { | 552 static intptr_t NextFieldOffset() { |
549 // Indicates this class cannot be extended by dart code. | 553 // Indicates this class cannot be extended by dart code. |
550 return -kWordSize; | 554 return -kWordSize; |
551 } | 555 } |
552 | 556 |
553 static void InitializeObject(uword address, intptr_t id, intptr_t size); | 557 static void InitializeObject(uword address, intptr_t id, intptr_t size); |
554 | 558 |
555 static void RegisterClass(const Class& cls, | 559 static void RegisterClass(const Class& cls, |
556 const String& name, | 560 const String& name, |
(...skipping 3609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4166 bool IsValidFieldOffset(intptr_t offset) const; | 4170 bool IsValidFieldOffset(intptr_t offset) const; |
4167 | 4171 |
4168 static intptr_t NextFieldOffset() { | 4172 static intptr_t NextFieldOffset() { |
4169 return sizeof(RawInstance); | 4173 return sizeof(RawInstance); |
4170 } | 4174 } |
4171 | 4175 |
4172 // TODO(iposva): Determine if this gets in the way of Smi. | 4176 // TODO(iposva): Determine if this gets in the way of Smi. |
4173 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 4177 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
4174 friend class Class; | 4178 friend class Class; |
4175 friend class Closure; | 4179 friend class Closure; |
| 4180 friend class DeferredObject; |
4176 friend class SnapshotWriter; | 4181 friend class SnapshotWriter; |
4177 friend class StubCode; | 4182 friend class StubCode; |
4178 friend class TypedDataView; | 4183 friend class TypedDataView; |
4179 friend class DeferredObject; | |
4180 }; | 4184 }; |
4181 | 4185 |
4182 | 4186 |
4183 class LibraryPrefix : public Instance { | 4187 class LibraryPrefix : public Instance { |
4184 public: | 4188 public: |
4185 RawString* name() const { return raw_ptr()->name_; } | 4189 RawString* name() const { return raw_ptr()->name_; } |
4186 virtual RawString* DictionaryName() const { return name(); } | 4190 virtual RawString* DictionaryName() const { return name(); } |
4187 | 4191 |
4188 RawArray* imports() const { return raw_ptr()->imports_; } | 4192 RawArray* imports() const { return raw_ptr()->imports_; } |
4189 intptr_t num_imports() const { return raw_ptr()->num_imports_; } | 4193 intptr_t num_imports() const { return raw_ptr()->num_imports_; } |
(...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6972 | 6976 |
6973 | 6977 |
6974 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 6978 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
6975 intptr_t index) { | 6979 intptr_t index) { |
6976 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 6980 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
6977 } | 6981 } |
6978 | 6982 |
6979 } // namespace dart | 6983 } // namespace dart |
6980 | 6984 |
6981 #endif // VM_OBJECT_H_ | 6985 #endif // VM_OBJECT_H_ |
OLD | NEW |