| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 447   void* operator new(size_t size); | 447   void* operator new(size_t size); | 
| 448   // Disallow copy constructor. | 448   // Disallow copy constructor. | 
| 449   DISALLOW_COPY_AND_ASSIGN(Object); | 449   DISALLOW_COPY_AND_ASSIGN(Object); | 
| 450 }; | 450 }; | 
| 451 | 451 | 
| 452 | 452 | 
| 453 class Class : public Object { | 453 class Class : public Object { | 
| 454  public: | 454  public: | 
| 455   intptr_t instance_size() const { | 455   intptr_t instance_size() const { | 
| 456     ASSERT(is_finalized() || is_prefinalized()); | 456     ASSERT(is_finalized() || is_prefinalized()); | 
| 457     return raw_ptr()->instance_size_; | 457     return (raw_ptr()->instance_size_in_words_ * kWordSize); | 
| 458   } | 458   } | 
| 459   void set_instance_size(intptr_t value) const { | 459   void set_instance_size(intptr_t value_in_bytes) const { | 
| 460     ASSERT(Utils::IsAligned(value, kObjectAlignment)); | 460     ASSERT(kWordSize != 0); | 
| 461     raw_ptr()->instance_size_ = value; | 461     set_instance_size_in_words(value_in_bytes / kWordSize); | 
| 462   } | 462   } | 
| 463   static intptr_t instance_size_offset() { | 463   void set_instance_size_in_words(intptr_t value) const { | 
| 464     return OFFSET_OF(RawClass, instance_size_); | 464     ASSERT(Utils::IsAligned((value * kWordSize), kObjectAlignment)); | 
|  | 465     raw_ptr()->instance_size_in_words_ = value; | 
| 465   } | 466   } | 
| 466 | 467 | 
| 467   intptr_t next_field_offset() const { | 468   intptr_t next_field_offset() const { | 
| 468     return raw_ptr()->next_field_offset_; | 469     return raw_ptr()->next_field_offset_in_words_ * kWordSize; | 
| 469   } | 470   } | 
| 470   void set_next_field_offset(intptr_t value) const { | 471   void set_next_field_offset(intptr_t value_in_bytes) const { | 
| 471     ASSERT((Utils::IsAligned(value, kObjectAlignment) && | 472     ASSERT(kWordSize != 0); | 
| 472             (value == raw_ptr()->instance_size_)) || | 473     set_next_field_offset_in_words(value_in_bytes / kWordSize); | 
| 473            (!Utils::IsAligned(value, kObjectAlignment) && | 474   } | 
| 474             (value + kWordSize == raw_ptr()->instance_size_))); | 475   void set_next_field_offset_in_words(intptr_t value) const { | 
| 475     raw_ptr()->next_field_offset_ = value; | 476     ASSERT((Utils::IsAligned((value * kWordSize), kObjectAlignment) && | 
|  | 477             (value == raw_ptr()->instance_size_in_words_)) || | 
|  | 478            (!Utils::IsAligned((value * kWordSize), kObjectAlignment) && | 
|  | 479             ((value + 1) == raw_ptr()->instance_size_in_words_))); | 
|  | 480     raw_ptr()->next_field_offset_in_words_ = value; | 
| 476   } | 481   } | 
| 477 | 482 | 
| 478   cpp_vtable handle_vtable() const { return raw_ptr()->handle_vtable_; } | 483   cpp_vtable handle_vtable() const { return raw_ptr()->handle_vtable_; } | 
| 479   void set_handle_vtable(cpp_vtable value) const { | 484   void set_handle_vtable(cpp_vtable value) const { | 
| 480     raw_ptr()->handle_vtable_ = value; | 485     raw_ptr()->handle_vtable_ = value; | 
| 481   } | 486   } | 
| 482 | 487 | 
| 483   intptr_t id() const { return raw_ptr()->id_; } | 488   intptr_t id() const { return raw_ptr()->id_; } | 
| 484   void set_id(intptr_t value) const { | 489   void set_id(intptr_t value) const { | 
| 485     raw_ptr()->id_ = value; | 490     raw_ptr()->id_ = value; | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 535 | 540 | 
| 536   // The type argument vector is flattened and includes the type arguments of | 541   // The type argument vector is flattened and includes the type arguments of | 
| 537   // the super class. | 542   // the super class. | 
| 538   bool HasTypeArguments() const; | 543   bool HasTypeArguments() const; | 
| 539   intptr_t NumTypeArguments() const; | 544   intptr_t NumTypeArguments() const; | 
| 540 | 545 | 
| 541   // If this class is parameterized, each instance has a type_arguments field. | 546   // If this class is parameterized, each instance has a type_arguments field. | 
| 542   static const intptr_t kNoTypeArguments = -1; | 547   static const intptr_t kNoTypeArguments = -1; | 
| 543   intptr_t type_arguments_field_offset() const { | 548   intptr_t type_arguments_field_offset() const { | 
| 544     ASSERT(is_finalized() || is_prefinalized()); | 549     ASSERT(is_finalized() || is_prefinalized()); | 
| 545     return raw_ptr()->type_arguments_field_offset_; | 550     if (raw_ptr()->type_arguments_field_offset_in_words_ == kNoTypeArguments) { | 
|  | 551       return kNoTypeArguments; | 
|  | 552     } | 
|  | 553     return raw_ptr()->type_arguments_field_offset_in_words_ * kWordSize; | 
| 546   } | 554   } | 
| 547   void set_type_arguments_field_offset(intptr_t value) const { | 555   void set_type_arguments_field_offset(intptr_t value_in_bytes) const { | 
| 548     raw_ptr()->type_arguments_field_offset_ = value; | 556     intptr_t value; | 
|  | 557     if (value_in_bytes == kNoTypeArguments) { | 
|  | 558       value = kNoTypeArguments; | 
|  | 559     } else { | 
|  | 560       ASSERT(kWordSize != 0); | 
|  | 561       value = value_in_bytes / kWordSize; | 
|  | 562     } | 
|  | 563     set_type_arguments_field_offset_in_words(value); | 
| 549   } | 564   } | 
| 550   static intptr_t type_arguments_field_offset_offset() { | 565   void set_type_arguments_field_offset_in_words(intptr_t value) const { | 
| 551     return OFFSET_OF(RawClass, type_arguments_field_offset_); | 566     raw_ptr()->type_arguments_field_offset_in_words_ = value; | 
|  | 567   } | 
|  | 568   static intptr_t type_arguments_field_offset_in_words_offset() { | 
|  | 569     return OFFSET_OF(RawClass, type_arguments_field_offset_in_words_); | 
| 552   } | 570   } | 
| 553 | 571 | 
| 554   // The super type of this class, Object type if not explicitly specified. | 572   // The super type of this class, Object type if not explicitly specified. | 
| 555   RawType* super_type() const { return raw_ptr()->super_type_; } | 573   RawType* super_type() const { return raw_ptr()->super_type_; } | 
| 556   void set_super_type(const Type& value) const; | 574   void set_super_type(const Type& value) const; | 
| 557   static intptr_t super_type_offset() { | 575   static intptr_t super_type_offset() { | 
| 558     return OFFSET_OF(RawClass, super_type_); | 576     return OFFSET_OF(RawClass, super_type_); | 
| 559   } | 577   } | 
| 560 | 578 | 
| 561   // Asserts that the class of the super type has been resolved. | 579   // Asserts that the class of the super type has been resolved. | 
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1571  public: | 1589  public: | 
| 1572   RawString* name() const { return raw_ptr()->name_; } | 1590   RawString* name() const { return raw_ptr()->name_; } | 
| 1573   RawString* UserVisibleName() const; | 1591   RawString* UserVisibleName() const; | 
| 1574   virtual RawString* DictionaryName() const { return name(); } | 1592   virtual RawString* DictionaryName() const { return name(); } | 
| 1575 | 1593 | 
| 1576   bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } | 1594   bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } | 
| 1577   bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } | 1595   bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } | 
| 1578   bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } | 1596   bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } | 
| 1579 | 1597 | 
| 1580   inline intptr_t Offset() const; | 1598   inline intptr_t Offset() const; | 
| 1581   inline void SetOffset(intptr_t value) const; | 1599   inline void SetOffset(intptr_t value_in_bytes) const; | 
| 1582 | 1600 | 
| 1583   RawInstance* value() const; | 1601   RawInstance* value() const; | 
| 1584   void set_value(const Instance& value) const; | 1602   void set_value(const Instance& value) const; | 
| 1585 | 1603 | 
| 1586   RawClass* owner() const { return raw_ptr()->owner_; } | 1604   RawClass* owner() const { return raw_ptr()->owner_; } | 
| 1587 | 1605 | 
| 1588   RawAbstractType* type() const  { return raw_ptr()->type_; } | 1606   RawAbstractType* type() const  { return raw_ptr()->type_; } | 
| 1589   void set_type(const AbstractType& value) const; | 1607   void set_type(const AbstractType& value) const; | 
| 1590 | 1608 | 
| 1591   static intptr_t InstanceSize() { | 1609   static intptr_t InstanceSize() { | 
| (...skipping 4317 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5909 } | 5927 } | 
| 5910 | 5928 | 
| 5911 | 5929 | 
| 5912 bool Function::HasCode() const { | 5930 bool Function::HasCode() const { | 
| 5913   return raw_ptr()->code_ != Code::null(); | 5931   return raw_ptr()->code_ != Code::null(); | 
| 5914 } | 5932 } | 
| 5915 | 5933 | 
| 5916 | 5934 | 
| 5917 intptr_t Field::Offset() const { | 5935 intptr_t Field::Offset() const { | 
| 5918   ASSERT(!is_static());  // Offset is valid only for instance fields. | 5936   ASSERT(!is_static());  // Offset is valid only for instance fields. | 
| 5919   return Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); | 5937   intptr_t value = Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); | 
|  | 5938   return (value * kWordSize); | 
| 5920 } | 5939 } | 
| 5921 | 5940 | 
| 5922 | 5941 | 
| 5923 void Field::SetOffset(intptr_t value) const { | 5942 void Field::SetOffset(intptr_t value_in_bytes) const { | 
| 5924   ASSERT(!is_static());  // SetOffset is valid only for instance fields. | 5943   ASSERT(!is_static());  // SetOffset is valid only for instance fields. | 
| 5925   raw_ptr()->value_ = Smi::New(value); | 5944   ASSERT(kWordSize != 0); | 
|  | 5945   raw_ptr()->value_ = Smi::New(value_in_bytes / kWordSize); | 
| 5926 } | 5946 } | 
| 5927 | 5947 | 
| 5928 | 5948 | 
| 5929 void Context::SetAt(intptr_t index, const Instance& value) const { | 5949 void Context::SetAt(intptr_t index, const Instance& value) const { | 
| 5930   StorePointer(InstanceAddr(index), value.raw()); | 5950   StorePointer(InstanceAddr(index), value.raw()); | 
| 5931 } | 5951 } | 
| 5932 | 5952 | 
| 5933 | 5953 | 
| 5934 intptr_t Instance::GetNativeField(Isolate* isolate, int index) const { | 5954 intptr_t Instance::GetNativeField(Isolate* isolate, int index) const { | 
| 5935   ASSERT(IsValidNativeIndex(index)); | 5955   ASSERT(IsValidNativeIndex(index)); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5968     if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5988     if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 
| 5969       return false; | 5989       return false; | 
| 5970     } | 5990     } | 
| 5971   } | 5991   } | 
| 5972   return true; | 5992   return true; | 
| 5973 } | 5993 } | 
| 5974 | 5994 | 
| 5975 }  // namespace dart | 5995 }  // namespace dart | 
| 5976 | 5996 | 
| 5977 #endif  // VM_OBJECT_H_ | 5997 #endif  // VM_OBJECT_H_ | 
| OLD | NEW | 
|---|