| 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/bitmap.h" | 11 #include "vm/bitmap.h" |
| 12 #include "vm/dart.h" | 12 #include "vm/dart.h" |
| 13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
| 14 #include "vm/handles.h" | 14 #include "vm/handles.h" |
| 15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
| 16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
| 17 #include "vm/os.h" | 17 #include "vm/os.h" |
| 18 #include "vm/raw_object.h" | 18 #include "vm/raw_object.h" |
| 19 #include "vm/scanner.h" | 19 #include "vm/scanner.h" |
| 20 | 20 |
| 21 namespace dart { | 21 namespace dart { |
| 22 | 22 |
| 23 // Forward declarations. | 23 // Forward declarations. |
| 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
| 25 class clazz; | 25 class clazz; |
| 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
| 27 #undef DEFINE_FORWARD_DECLARATION | 27 #undef DEFINE_FORWARD_DECLARATION |
| 28 class Api; | 28 class Api; |
| 29 class Assembler; | 29 class Assembler; |
| 30 class Closure; |
| 30 class Code; | 31 class Code; |
| 31 class LocalScope; | 32 class LocalScope; |
| 32 class Symbols; | 33 class Symbols; |
| 33 | 34 |
| 34 #define OBJECT_IMPLEMENTATION(object, super) \ | 35 #define OBJECT_IMPLEMENTATION(object, super) \ |
| 35 public: /* NOLINT */ \ | 36 public: /* NOLINT */ \ |
| 36 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ | 37 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ |
| 37 void operator=(Raw##object* value) { \ | 38 void operator=(Raw##object* value) { \ |
| 38 initializeHandle(this, value); \ | 39 initializeHandle(this, value); \ |
| 39 } \ | 40 } \ |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 static RawClass* context_scope_class_; // Class of ContextScope vm object. | 415 static RawClass* context_scope_class_; // Class of ContextScope vm object. |
| 415 static RawClass* icdata_class_; // Class of ICData. | 416 static RawClass* icdata_class_; // Class of ICData. |
| 416 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. | 417 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. |
| 417 static RawClass* api_error_class_; // Class of ApiError. | 418 static RawClass* api_error_class_; // Class of ApiError. |
| 418 static RawClass* language_error_class_; // Class of LanguageError. | 419 static RawClass* language_error_class_; // Class of LanguageError. |
| 419 static RawClass* unhandled_exception_class_; // Class of UnhandledException. | 420 static RawClass* unhandled_exception_class_; // Class of UnhandledException. |
| 420 static RawClass* unwind_error_class_; // Class of UnwindError. | 421 static RawClass* unwind_error_class_; // Class of UnwindError. |
| 421 | 422 |
| 422 friend void ClassTable::Register(const Class& cls); | 423 friend void ClassTable::Register(const Class& cls); |
| 423 friend void RawObject::Validate(Isolate* isolate) const; | 424 friend void RawObject::Validate(Isolate* isolate) const; |
| 425 friend class Closure; |
| 424 friend class SnapshotReader; | 426 friend class SnapshotReader; |
| 425 | 427 |
| 426 // Disallow allocation. | 428 // Disallow allocation. |
| 427 void* operator new(size_t size); | 429 void* operator new(size_t size); |
| 428 // Disallow copy constructor. | 430 // Disallow copy constructor. |
| 429 DISALLOW_COPY_AND_ASSIGN(Object); | 431 DISALLOW_COPY_AND_ASSIGN(Object); |
| 430 }; | 432 }; |
| 431 | 433 |
| 432 | 434 |
| 433 class Class : public Object { | 435 class Class : public Object { |
| (...skipping 2568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3002 } | 3004 } |
| 3003 | 3005 |
| 3004 intptr_t GetNativeField(int index) const { | 3006 intptr_t GetNativeField(int index) const { |
| 3005 return *NativeFieldAddr(index); | 3007 return *NativeFieldAddr(index); |
| 3006 } | 3008 } |
| 3007 | 3009 |
| 3008 void SetNativeField(int index, intptr_t value) const { | 3010 void SetNativeField(int index, intptr_t value) const { |
| 3009 *NativeFieldAddr(index) = value; | 3011 *NativeFieldAddr(index) = value; |
| 3010 } | 3012 } |
| 3011 | 3013 |
| 3014 // Returns true if the instance is a closure object. |
| 3015 bool IsClosure() const; |
| 3016 |
| 3012 static intptr_t InstanceSize() { | 3017 static intptr_t InstanceSize() { |
| 3013 return RoundedAllocationSize(sizeof(RawInstance)); | 3018 return RoundedAllocationSize(sizeof(RawInstance)); |
| 3014 } | 3019 } |
| 3015 | 3020 |
| 3016 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); | 3021 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); |
| 3017 | 3022 |
| 3018 private: | 3023 private: |
| 3019 RawObject** FieldAddrAtOffset(intptr_t offset) const { | 3024 RawObject** FieldAddrAtOffset(intptr_t offset) const { |
| 3020 ASSERT(IsValidFieldOffset(offset)); | 3025 ASSERT(IsValidFieldOffset(offset)); |
| 3021 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 3026 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |
| 3022 } | 3027 } |
| 3023 RawObject** FieldAddr(const Field& field) const { | 3028 RawObject** FieldAddr(const Field& field) const { |
| 3024 return FieldAddrAtOffset(field.Offset()); | 3029 return FieldAddrAtOffset(field.Offset()); |
| 3025 } | 3030 } |
| 3026 intptr_t* NativeFieldAddr(int index) const { | 3031 intptr_t* NativeFieldAddr(int index) const { |
| 3027 ASSERT(IsValidNativeIndex(index)); | 3032 ASSERT(IsValidNativeIndex(index)); |
| 3028 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) | 3033 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) |
| 3029 + (index * kWordSize) | 3034 + (index * kWordSize) |
| 3030 + sizeof(RawObject)); | 3035 + sizeof(RawObject)); |
| 3031 } | 3036 } |
| 3032 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 3037 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
| 3033 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 3038 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
| 3034 } | 3039 } |
| 3035 bool IsValidFieldOffset(int offset) const; | 3040 bool IsValidFieldOffset(int offset) const; |
| 3036 | 3041 |
| 3037 // TODO(iposva): Determine if this gets in the way of Smi. | 3042 // TODO(iposva): Determine if this gets in the way of Smi. |
| 3038 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 3043 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
| 3039 friend class Class; | 3044 friend class Class; |
| 3045 friend class Closure; |
| 3040 }; | 3046 }; |
| 3041 | 3047 |
| 3042 | 3048 |
| 3043 // AbstractType is an abstract superclass. | 3049 // AbstractType is an abstract superclass. |
| 3044 // Subclasses of AbstractType are Type and TypeParameter. | 3050 // Subclasses of AbstractType are Type and TypeParameter. |
| 3045 class AbstractType : public Instance { | 3051 class AbstractType : public Instance { |
| 3046 public: | 3052 public: |
| 3047 virtual bool IsFinalized() const; | 3053 virtual bool IsFinalized() const; |
| 3048 virtual bool IsBeingFinalized() const; | 3054 virtual bool IsBeingFinalized() const; |
| 3049 virtual bool IsMalformed() const; | 3055 virtual bool IsMalformed() const; |
| (...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5448 | 5454 |
| 5449 // DartFunction represents the abstract Dart class 'Function'. | 5455 // DartFunction represents the abstract Dart class 'Function'. |
| 5450 class DartFunction : public Instance { | 5456 class DartFunction : public Instance { |
| 5451 private: | 5457 private: |
| 5452 HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); | 5458 HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); |
| 5453 friend class Class; | 5459 friend class Class; |
| 5454 friend class Instance; | 5460 friend class Instance; |
| 5455 }; | 5461 }; |
| 5456 | 5462 |
| 5457 | 5463 |
| 5458 class Closure : public Instance { | 5464 class Closure : public AllStatic { |
| 5459 public: | 5465 public: |
| 5460 RawFunction* function() const { return raw_ptr()->function_; } | 5466 static RawFunction* function(const Instance& closure) { |
| 5467 return *FunctionAddr(closure); |
| 5468 } |
| 5461 static intptr_t function_offset() { | 5469 static intptr_t function_offset() { |
| 5462 return OFFSET_OF(RawClosure, function_); | 5470 return static_cast<intptr_t>(kFunctionOffset * kWordSize); |
| 5463 } | 5471 } |
| 5464 | 5472 |
| 5465 RawContext* context() const { return raw_ptr()->context_; } | 5473 static RawContext* context(const Instance& closure) { |
| 5466 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 5474 return *ContextAddr(closure); |
| 5475 } |
| 5476 static intptr_t context_offset() { |
| 5477 return static_cast<intptr_t>(kContextOffset * kWordSize); |
| 5478 } |
| 5467 | 5479 |
| 5468 virtual RawAbstractTypeArguments* GetTypeArguments() const { | 5480 static RawAbstractTypeArguments* GetTypeArguments(const Instance& closure) { |
| 5469 return raw_ptr()->type_arguments_; | 5481 return *TypeArgumentsAddr(closure); |
| 5470 } | 5482 } |
| 5471 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { | 5483 static void SetTypeArguments(const Instance& closure, |
| 5472 StorePointer(&raw_ptr()->type_arguments_, value.raw()); | 5484 const AbstractTypeArguments& value) { |
| 5485 closure.StorePointer(TypeArgumentsAddr(closure), value.raw()); |
| 5473 } | 5486 } |
| 5474 static intptr_t type_arguments_offset() { | 5487 static intptr_t type_arguments_offset() { |
| 5475 return OFFSET_OF(RawClosure, type_arguments_); | 5488 return static_cast<intptr_t>(kTypeArgumentsOffset * kWordSize); |
| 5476 } | 5489 } |
| 5477 | 5490 |
| 5491 static const char* ToCString(const Instance& closure); |
| 5492 |
| 5478 static intptr_t InstanceSize() { | 5493 static intptr_t InstanceSize() { |
| 5479 return RoundedAllocationSize(sizeof(RawClosure)); | 5494 intptr_t size = sizeof(RawInstance) + (kNumFields * kWordSize); |
| 5495 ASSERT(size == Object::RoundedAllocationSize(size)); |
| 5496 return size; |
| 5480 } | 5497 } |
| 5481 | 5498 |
| 5482 static RawClosure* New(const Function& function, | 5499 static RawInstance* New(const Function& function, |
| 5483 const Context& context, | 5500 const Context& context, |
| 5484 Heap::Space space = Heap::kNew); | 5501 Heap::Space space = Heap::kNew); |
| 5485 | 5502 |
| 5486 private: | 5503 private: |
| 5487 void set_function(const Function& value) const; | 5504 static const int kTypeArgumentsOffset = 1; |
| 5488 void set_context(const Context& value) const; | 5505 static const int kFunctionOffset = 2; |
| 5506 static const int kContextOffset = 3; |
| 5507 static const int kNumFields = 3; |
| 5489 | 5508 |
| 5490 HEAP_OBJECT_IMPLEMENTATION(Closure, Instance); | 5509 static RawAbstractTypeArguments** TypeArgumentsAddr(const Instance& obj) { |
| 5510 ASSERT(obj.IsClosure()); |
| 5511 return reinterpret_cast<RawAbstractTypeArguments**>( |
| 5512 reinterpret_cast<intptr_t>(obj.raw_ptr()) + type_arguments_offset()); |
| 5513 } |
| 5514 static RawFunction** FunctionAddr(const Instance& obj) { |
| 5515 ASSERT(obj.IsClosure()); |
| 5516 return reinterpret_cast<RawFunction**>( |
| 5517 reinterpret_cast<intptr_t>(obj.raw_ptr()) + function_offset()); |
| 5518 } |
| 5519 static RawContext** ContextAddr(const Instance& obj) { |
| 5520 ASSERT(obj.IsClosure()); |
| 5521 return reinterpret_cast<RawContext**>( |
| 5522 reinterpret_cast<intptr_t>(obj.raw_ptr()) + context_offset()); |
| 5523 } |
| 5524 static void set_function(const Instance& closure, |
| 5525 const Function& value) { |
| 5526 closure.StorePointer(FunctionAddr(closure), value.raw()); |
| 5527 } |
| 5528 static void set_context(const Instance& closure, |
| 5529 const Context& value) { |
| 5530 closure.StorePointer(ContextAddr(closure), value.raw()); |
| 5531 } |
| 5532 |
| 5491 friend class Class; | 5533 friend class Class; |
| 5492 }; | 5534 }; |
| 5493 | 5535 |
| 5494 | 5536 |
| 5495 // Internal stacktrace object used in exceptions for printing stack traces. | 5537 // Internal stacktrace object used in exceptions for printing stack traces. |
| 5496 class Stacktrace : public Instance { | 5538 class Stacktrace : public Instance { |
| 5497 public: | 5539 public: |
| 5498 intptr_t Length() const; | 5540 intptr_t Length() const; |
| 5499 RawFunction* FunctionAtFrame(intptr_t frame_index) const; | 5541 RawFunction* FunctionAtFrame(intptr_t frame_index) const; |
| 5500 RawCode* CodeAtFrame(intptr_t frame_index) const; | 5542 RawCode* CodeAtFrame(intptr_t frame_index) const; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5671 } | 5713 } |
| 5672 #endif | 5714 #endif |
| 5673 intptr_t cid = raw_->GetClassId(); | 5715 intptr_t cid = raw_->GetClassId(); |
| 5674 if (cid < kNumPredefinedCids) { | 5716 if (cid < kNumPredefinedCids) { |
| 5675 #if defined(DEBUG) | 5717 #if defined(DEBUG) |
| 5676 ASSERT(builtin_vtables_[cid] == | 5718 ASSERT(builtin_vtables_[cid] == |
| 5677 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | 5719 isolate->class_table()->At(cid)->ptr()->handle_vtable_); |
| 5678 #endif | 5720 #endif |
| 5679 set_vtable(builtin_vtables_[cid]); | 5721 set_vtable(builtin_vtables_[cid]); |
| 5680 } else { | 5722 } else { |
| 5681 #if !defined(DEBUG) | 5723 set_vtable(builtin_vtables_[kInstanceCid]); |
| 5682 Isolate* isolate = Isolate::Current(); | |
| 5683 #endif | |
| 5684 RawClass* raw_class = isolate->class_table()->At(cid); | |
| 5685 set_vtable(raw_class->ptr()->handle_vtable_); | |
| 5686 } | 5724 } |
| 5687 } | 5725 } |
| 5688 | 5726 |
| 5689 | 5727 |
| 5690 bool Function::HasCode() const { | 5728 bool Function::HasCode() const { |
| 5691 return raw_ptr()->code_ != Code::null(); | 5729 return raw_ptr()->code_ != Code::null(); |
| 5692 } | 5730 } |
| 5693 | 5731 |
| 5694 | 5732 |
| 5695 intptr_t Field::Offset() const { | 5733 intptr_t Field::Offset() const { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5734 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5772 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5735 return false; | 5773 return false; |
| 5736 } | 5774 } |
| 5737 } | 5775 } |
| 5738 return true; | 5776 return true; |
| 5739 } | 5777 } |
| 5740 | 5778 |
| 5741 } // namespace dart | 5779 } // namespace dart |
| 5742 | 5780 |
| 5743 #endif // VM_OBJECT_H_ | 5781 #endif // VM_OBJECT_H_ |
| OLD | NEW |