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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 /* is not setup for type T, although some methods are supposed to work */ \ | 99 /* is not setup for type T, although some methods are supposed to work */ \ |
100 /* with null, for example Instance::Equals(). */ \ | 100 /* with null, for example Instance::Equals(). */ \ |
101 static const object& Cast(const Object& obj) { \ | 101 static const object& Cast(const Object& obj) { \ |
102 ASSERT(obj.Is##object()); \ | 102 ASSERT(obj.Is##object()); \ |
103 return reinterpret_cast<const object&>(obj); \ | 103 return reinterpret_cast<const object&>(obj); \ |
104 } \ | 104 } \ |
105 static Raw##object* null() { \ | 105 static Raw##object* null() { \ |
106 return reinterpret_cast<Raw##object*>(Object::null()); \ | 106 return reinterpret_cast<Raw##object*>(Object::null()); \ |
107 } \ | 107 } \ |
108 virtual const char* ToCString() const; \ | 108 virtual const char* ToCString() const; \ |
109 static const ObjectKind kInstanceKind = k##object; \ | 109 static const ClassId kClassId = k##object##Cid; \ |
110 protected: /* NOLINT */ \ | 110 protected: /* NOLINT */ \ |
111 object() : super() {} \ | 111 object() : super() {} \ |
112 private: /* NOLINT */ \ | 112 private: /* NOLINT */ \ |
113 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ | 113 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ |
114 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ | 114 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ |
115 if (raw_ptr != Object::null()) { \ | 115 if (raw_ptr != Object::null()) { \ |
116 obj->SetRaw(raw_ptr); \ | 116 obj->SetRaw(raw_ptr); \ |
117 } else { \ | 117 } else { \ |
118 obj->raw_ = Object::null(); \ | 118 obj->raw_ = Object::null(); \ |
119 object fake_object; \ | 119 object fake_object; \ |
(...skipping 18 matching lines...) Expand all Loading... |
138 OBJECT_IMPLEMENTATION(object, super); \ | 138 OBJECT_IMPLEMENTATION(object, super); \ |
139 Raw##object* raw_ptr() const { \ | 139 Raw##object* raw_ptr() const { \ |
140 ASSERT(raw() != null()); \ | 140 ASSERT(raw() != null()); \ |
141 return raw()->ptr(); \ | 141 return raw()->ptr(); \ |
142 } \ | 142 } \ |
143 SNAPSHOT_READER_SUPPORT(object) \ | 143 SNAPSHOT_READER_SUPPORT(object) \ |
144 friend class StackFrame; \ | 144 friend class StackFrame; \ |
145 | 145 |
146 class Object { | 146 class Object { |
147 public: | 147 public: |
148 // Index for Singleton internal VM classes, | |
149 // this index is used in snapshots to refer to these classes directly. | |
150 enum { | |
151 kNullObject = 0, | |
152 kSentinelObject, | |
153 kClassClass, | |
154 kNullClass, | |
155 kDynamicClass, | |
156 kVoidClass, | |
157 kUnresolvedClassClass, | |
158 kTypeClass, | |
159 kTypeParameterClass, | |
160 kTypeArgumentsClass, | |
161 kInstantiatedTypeArgumentsClass, | |
162 kFunctionClass, | |
163 kFieldClass, | |
164 kLiteralTokenClass, | |
165 kTokenStreamClass, | |
166 kScriptClass, | |
167 kLibraryClass, | |
168 kLibraryPrefixClass, | |
169 kCodeClass, | |
170 kInstructionsClass, | |
171 kPcDescriptorsClass, | |
172 kStackmapClass, | |
173 kLocalVarDescriptorsClass, | |
174 kExceptionHandlersClass, | |
175 kDeoptInfoClass, | |
176 kContextClass, | |
177 kContextScopeClass, | |
178 kICDataClass, | |
179 kSubtypeTestCacheClass, | |
180 kApiErrorClass, | |
181 kLanguageErrorClass, | |
182 kUnhandledExceptionClass, | |
183 kUnwindErrorClass, | |
184 kMaxId, | |
185 kInvalidIndex = -1, | |
186 }; | |
187 | |
188 virtual ~Object() { } | 148 virtual ~Object() { } |
189 | 149 |
190 RawObject* raw() const { return raw_; } | 150 RawObject* raw() const { return raw_; } |
191 void operator=(RawObject* value) { SetRaw(value); } | 151 void operator=(RawObject* value) { SetRaw(value); } |
192 | 152 |
193 void set_tags(intptr_t value) const { | 153 void set_tags(intptr_t value) const { |
194 // TODO(asiva): Remove the capability of setting tags in general. The mask | 154 // TODO(asiva): Remove the capability of setting tags in general. The mask |
195 // here only allows for canonical and from_snapshot flags to be set. | 155 // here only allows for canonical and from_snapshot flags to be set. |
196 ASSERT(!IsNull()); | 156 ASSERT(!IsNull()); |
197 uword tags = raw()->ptr()->tags_ & ~0x0000000c; | 157 uword tags = raw()->ptr()->tags_ & ~0x0000000c; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 static RawClass* context_scope_class() { return context_scope_class_; } | 277 static RawClass* context_scope_class() { return context_scope_class_; } |
318 static RawClass* api_error_class() { return api_error_class_; } | 278 static RawClass* api_error_class() { return api_error_class_; } |
319 static RawClass* language_error_class() { return language_error_class_; } | 279 static RawClass* language_error_class() { return language_error_class_; } |
320 static RawClass* unhandled_exception_class() { | 280 static RawClass* unhandled_exception_class() { |
321 return unhandled_exception_class_; | 281 return unhandled_exception_class_; |
322 } | 282 } |
323 static RawClass* unwind_error_class() { return unwind_error_class_; } | 283 static RawClass* unwind_error_class() { return unwind_error_class_; } |
324 static RawClass* icdata_class() { return icdata_class_; } | 284 static RawClass* icdata_class() { return icdata_class_; } |
325 static RawClass* subtypetestcache_class() { return subtypetestcache_class_; } | 285 static RawClass* subtypetestcache_class() { return subtypetestcache_class_; } |
326 | 286 |
327 static int GetSingletonClassIndex(const RawClass* raw_class); | 287 static const char* GetSingletonClassName(intptr_t class_id); |
328 static RawClass* GetSingletonClass(int index); | |
329 static const char* GetSingletonClassName(int index); | |
330 | 288 |
331 static RawClass* CreateAndRegisterInterface(const char* cname, | 289 static RawClass* CreateAndRegisterInterface(const char* cname, |
332 const Script& script, | 290 const Script& script, |
333 const Library& lib); | 291 const Library& lib); |
334 static void RegisterClass(const Class& cls, | 292 static void RegisterClass(const Class& cls, |
335 const char* cname, | 293 const char* cname, |
336 const Script& script, | 294 const Script& script, |
337 const Library& lib); | 295 const Library& lib); |
338 | 296 |
339 static void RegisterPrivateClass(const Class& cls, | 297 static void RegisterPrivateClass(const Class& cls, |
340 const char* cname, | 298 const char* cname, |
341 const Script& script, | 299 const Script& script, |
342 const Library& lib); | 300 const Library& lib); |
343 | 301 |
344 static RawError* Init(Isolate* isolate); | 302 static RawError* Init(Isolate* isolate); |
345 static void InitFromSnapshot(Isolate* isolate); | 303 static void InitFromSnapshot(Isolate* isolate); |
346 static void InitOnce(); | 304 static void InitOnce(); |
347 | 305 |
348 static intptr_t InstanceSize() { | 306 static intptr_t InstanceSize() { |
349 return RoundedAllocationSize(sizeof(RawObject)); | 307 return RoundedAllocationSize(sizeof(RawObject)); |
350 } | 308 } |
351 | 309 |
352 static const ObjectKind kInstanceKind = kObject; | 310 static const ClassId kClassId = kObjectCid; |
353 | 311 |
354 // Different kinds of type tests. | 312 // Different kinds of type tests. |
355 enum TypeTestKind { | 313 enum TypeTestKind { |
356 kIsSubtypeOf = 0, | 314 kIsSubtypeOf = 0, |
357 kIsMoreSpecificThan | 315 kIsMoreSpecificThan |
358 }; | 316 }; |
359 | 317 |
360 // Different kinds of name visibility. | 318 // Different kinds of name visibility. |
361 enum NameVisibility { | 319 enum NameVisibility { |
362 kInternalName = 0, | 320 kInternalName = 0, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 364 |
407 private: | 365 private: |
408 static void InitializeObject(uword address, intptr_t id, intptr_t size); | 366 static void InitializeObject(uword address, intptr_t id, intptr_t size); |
409 | 367 |
410 cpp_vtable* vtable_address() const { | 368 cpp_vtable* vtable_address() const { |
411 uword vtable_addr = reinterpret_cast<uword>(this); | 369 uword vtable_addr = reinterpret_cast<uword>(this); |
412 return reinterpret_cast<cpp_vtable*>(vtable_addr); | 370 return reinterpret_cast<cpp_vtable*>(vtable_addr); |
413 } | 371 } |
414 | 372 |
415 static cpp_vtable handle_vtable_; | 373 static cpp_vtable handle_vtable_; |
416 static cpp_vtable builtin_vtables_[kNumPredefinedKinds]; | 374 static cpp_vtable builtin_vtables_[kNumPredefinedCids]; |
417 | 375 |
418 // The static values below are singletons shared between the different | 376 // The static values below are singletons shared between the different |
419 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. | 377 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. |
420 static RawObject* null_; | 378 static RawObject* null_; |
421 static RawInstance* sentinel_; | 379 static RawInstance* sentinel_; |
422 static RawInstance* transition_sentinel_; | 380 static RawInstance* transition_sentinel_; |
423 | 381 |
424 static RawClass* class_class_; // Class of the Class vm object. | 382 static RawClass* class_class_; // Class of the Class vm object. |
425 static RawClass* null_class_; // Class of the null object. | 383 static RawClass* null_class_; // Class of the null object. |
426 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. | 384 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 (!Utils::IsAligned(value, kObjectAlignment) && | 446 (!Utils::IsAligned(value, kObjectAlignment) && |
489 (value + kWordSize == raw_ptr()->instance_size_))); | 447 (value + kWordSize == raw_ptr()->instance_size_))); |
490 raw_ptr()->next_field_offset_ = value; | 448 raw_ptr()->next_field_offset_ = value; |
491 } | 449 } |
492 | 450 |
493 cpp_vtable handle_vtable() const { return raw_ptr()->handle_vtable_; } | 451 cpp_vtable handle_vtable() const { return raw_ptr()->handle_vtable_; } |
494 void set_handle_vtable(cpp_vtable value) const { | 452 void set_handle_vtable(cpp_vtable value) const { |
495 raw_ptr()->handle_vtable_ = value; | 453 raw_ptr()->handle_vtable_ = value; |
496 } | 454 } |
497 | 455 |
498 ObjectKind instance_kind() const { return raw_ptr()->instance_kind_; } | |
499 void set_instance_kind(ObjectKind value) const { | |
500 raw_ptr()->instance_kind_ = value; | |
501 } | |
502 | |
503 intptr_t id() const { return raw_ptr()->id_; } | 456 intptr_t id() const { return raw_ptr()->id_; } |
504 void set_id(intptr_t value) const { | 457 void set_id(intptr_t value) const { |
505 raw_ptr()->id_ = value; | 458 raw_ptr()->id_ = value; |
506 } | 459 } |
507 | 460 |
508 RawString* Name() const; | 461 RawString* Name() const; |
509 | 462 |
510 RawString* UserVisibleName() const; | 463 RawString* UserVisibleName() const; |
511 | 464 |
512 RawScript* script() const { return raw_ptr()->script_; } | 465 RawScript* script() const { return raw_ptr()->script_; } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // Check if this class represents the 'void' class. | 570 // Check if this class represents the 'void' class. |
618 bool IsVoidClass() const { return raw() == Object::void_class(); } | 571 bool IsVoidClass() const { return raw() == Object::void_class(); } |
619 | 572 |
620 // Check if this class represents the 'Object' class. | 573 // Check if this class represents the 'Object' class. |
621 bool IsObjectClass() const; | 574 bool IsObjectClass() const; |
622 | 575 |
623 // Check if this class represents a signature class. | 576 // Check if this class represents a signature class. |
624 bool IsSignatureClass() const { | 577 bool IsSignatureClass() const { |
625 return signature_function() != Object::null(); | 578 return signature_function() != Object::null(); |
626 } | 579 } |
| 580 static bool IsSignatureClass(RawClass* cls) { |
| 581 return cls->ptr()->signature_function_ != Object::null(); |
| 582 } |
627 | 583 |
628 // Check if this class represents a canonical signature class, i.e. not an | 584 // Check if this class represents a canonical signature class, i.e. not an |
629 // alias as defined in a typedef. | 585 // alias as defined in a typedef. |
630 bool IsCanonicalSignatureClass() const; | 586 bool IsCanonicalSignatureClass() const; |
631 | 587 |
632 // Check the subtype relationship. | 588 // Check the subtype relationship. |
633 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, | 589 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, |
634 const Class& other, | 590 const Class& other, |
635 const AbstractTypeArguments& other_type_arguments, | 591 const AbstractTypeArguments& other_type_arguments, |
636 Error* malformed_error) const { | 592 Error* malformed_error) const { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 // The class may be type parameterized unless the signature_function is in a | 707 // The class may be type parameterized unless the signature_function is in a |
752 // static scope. In that case, the type parameters are copied from the owner | 708 // static scope. In that case, the type parameters are copied from the owner |
753 // class of signature_function. | 709 // class of signature_function. |
754 static RawClass* NewSignatureClass(const String& name, | 710 static RawClass* NewSignatureClass(const String& name, |
755 const Function& signature_function, | 711 const Function& signature_function, |
756 const Script& script); | 712 const Script& script); |
757 | 713 |
758 // Return a class object corresponding to the specified kind. If | 714 // Return a class object corresponding to the specified kind. If |
759 // a canonicalized version of it exists then that object is returned | 715 // a canonicalized version of it exists then that object is returned |
760 // otherwise a new object is allocated and returned. | 716 // otherwise a new object is allocated and returned. |
761 static RawClass* GetClass(ObjectKind kind); | 717 static RawClass* GetClass(intptr_t class_id, bool is_signature_class); |
762 | 718 |
763 private: | 719 private: |
764 void set_name(const String& value) const; | 720 void set_name(const String& value) const; |
765 void set_script(const Script& value) const; | 721 void set_script(const Script& value) const; |
766 void set_token_pos(intptr_t value) const; | 722 void set_token_pos(intptr_t value) const; |
767 void set_signature_function(const Function& value) const; | 723 void set_signature_function(const Function& value) const; |
768 void set_signature_type(const AbstractType& value) const; | 724 void set_signature_type(const AbstractType& value) const; |
769 void set_class_state(int8_t state) const; | 725 void set_class_state(int8_t state) const; |
770 | 726 |
771 void set_constants(const Array& value) const; | 727 void set_constants(const Array& value) const; |
(...skipping 4607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5379 } | 5335 } |
5380 | 5336 |
5381 #if defined(DEBUG) | 5337 #if defined(DEBUG) |
5382 Isolate* isolate = Isolate::Current(); | 5338 Isolate* isolate = Isolate::Current(); |
5383 Heap* isolate_heap = isolate->heap(); | 5339 Heap* isolate_heap = isolate->heap(); |
5384 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 5340 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
5385 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || | 5341 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || |
5386 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); | 5342 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); |
5387 #endif | 5343 #endif |
5388 intptr_t cid = raw_->GetClassId(); | 5344 intptr_t cid = raw_->GetClassId(); |
5389 if (cid < kNumPredefinedKinds) { | 5345 if (cid < kNumPredefinedCids) { |
5390 #if defined(DEBUG) | 5346 #if defined(DEBUG) |
5391 ASSERT(builtin_vtables_[cid] == | 5347 ASSERT(builtin_vtables_[cid] == |
5392 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | 5348 isolate->class_table()->At(cid)->ptr()->handle_vtable_); |
5393 #endif | 5349 #endif |
5394 set_vtable(builtin_vtables_[cid]); | 5350 set_vtable(builtin_vtables_[cid]); |
5395 } else { | 5351 } else { |
5396 #if !defined(DEBUG) | 5352 #if !defined(DEBUG) |
5397 Isolate* isolate = Isolate::Current(); | 5353 Isolate* isolate = Isolate::Current(); |
5398 #endif | 5354 #endif |
5399 RawClass* raw_class = isolate->class_table()->At(cid); | 5355 RawClass* raw_class = isolate->class_table()->At(cid); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5459 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5415 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5460 return false; | 5416 return false; |
5461 } | 5417 } |
5462 } | 5418 } |
5463 return true; | 5419 return true; |
5464 } | 5420 } |
5465 | 5421 |
5466 } // namespace dart | 5422 } // namespace dart |
5467 | 5423 |
5468 #endif // VM_OBJECT_H_ | 5424 #endif // VM_OBJECT_H_ |
OLD | NEW |