| 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const; | 631 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const; |
| 632 | 632 |
| 633 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const; | 633 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const; |
| 634 | 634 |
| 635 static intptr_t InstanceSize() { | 635 static intptr_t InstanceSize() { |
| 636 return RoundedAllocationSize(sizeof(RawClass)); | 636 return RoundedAllocationSize(sizeof(RawClass)); |
| 637 } | 637 } |
| 638 | 638 |
| 639 bool is_interface() const { | 639 bool is_interface() const { |
| 640 return raw_ptr()->is_interface_; | 640 return InterfaceBit::decode(raw_ptr()->state_bits_); |
| 641 } | 641 } |
| 642 void set_is_interface() const; | 642 void set_is_interface() const; |
| 643 static intptr_t is_interface_offset() { | |
| 644 return OFFSET_OF(RawClass, is_interface_); | |
| 645 } | |
| 646 | 643 |
| 647 bool is_finalized() const { | 644 bool is_finalized() const { |
| 648 return raw_ptr()->class_state_ == RawClass::kFinalized; | 645 return StateBits::decode(raw_ptr()->state_bits_) == RawClass::kFinalized; |
| 649 } | 646 } |
| 650 void set_is_finalized() const; | 647 void set_is_finalized() const; |
| 651 | 648 |
| 652 bool is_prefinalized() const { | 649 bool is_prefinalized() const { |
| 653 return raw_ptr()->class_state_ == RawClass::kPreFinalized; | 650 return StateBits::decode(raw_ptr()->state_bits_) == RawClass::kPreFinalized; |
| 654 } | 651 } |
| 655 | 652 |
| 656 void set_is_prefinalized() const; | 653 void set_is_prefinalized() const; |
| 657 | 654 |
| 658 bool is_const() const { | 655 bool is_const() const { return ConstBit::decode(raw_ptr()->state_bits_); } |
| 659 return raw_ptr()->is_const_; | |
| 660 } | |
| 661 void set_is_const() const; | 656 void set_is_const() const; |
| 662 | 657 |
| 663 int num_native_fields() const { | 658 int num_native_fields() const { |
| 664 return raw_ptr()->num_native_fields_; | 659 return raw_ptr()->num_native_fields_; |
| 665 } | 660 } |
| 666 void set_num_native_fields(int value) const { | 661 void set_num_native_fields(int value) const { |
| 667 raw_ptr()->num_native_fields_ = value; | 662 raw_ptr()->num_native_fields_ = value; |
| 668 } | 663 } |
| 669 static intptr_t num_native_fields_offset() { | 664 static intptr_t num_native_fields_offset() { |
| 670 return OFFSET_OF(RawClass, num_native_fields_); | 665 return OFFSET_OF(RawClass, num_native_fields_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 static RawClass* NewSignatureClass(const String& name, | 699 static RawClass* NewSignatureClass(const String& name, |
| 705 const Function& signature_function, | 700 const Function& signature_function, |
| 706 const Script& script); | 701 const Script& script); |
| 707 | 702 |
| 708 // Return a class object corresponding to the specified kind. If | 703 // Return a class object corresponding to the specified kind. If |
| 709 // a canonicalized version of it exists then that object is returned | 704 // a canonicalized version of it exists then that object is returned |
| 710 // otherwise a new object is allocated and returned. | 705 // otherwise a new object is allocated and returned. |
| 711 static RawClass* GetClass(intptr_t class_id, bool is_signature_class); | 706 static RawClass* GetClass(intptr_t class_id, bool is_signature_class); |
| 712 | 707 |
| 713 private: | 708 private: |
| 709 enum { |
| 710 kConstBit = 1, |
| 711 kInterfaceBit = 2, |
| 712 kStateTagBit = 3, |
| 713 kStateTagSize = 2, |
| 714 }; |
| 715 class ConstBit : public BitField<bool, kConstBit, 1> {}; |
| 716 class InterfaceBit : public BitField<bool, kInterfaceBit, 1> {}; |
| 717 class StateBits : public BitField<RawClass::ClassState, |
| 718 kStateTagBit, kStateTagSize> {}; // NOLINT |
| 719 |
| 714 void set_name(const String& value) const; | 720 void set_name(const String& value) const; |
| 715 void set_token_pos(intptr_t value) const; | 721 void set_token_pos(intptr_t value) const; |
| 716 void set_signature_function(const Function& value) const; | 722 void set_signature_function(const Function& value) const; |
| 717 void set_signature_type(const AbstractType& value) const; | 723 void set_signature_type(const AbstractType& value) const; |
| 718 void set_class_state(int8_t state) const; | 724 void set_class_state(RawClass::ClassState state) const; |
| 725 void set_state_bits(uint8_t bits) const; |
| 719 | 726 |
| 720 void set_constants(const Array& value) const; | 727 void set_constants(const Array& value) const; |
| 721 | 728 |
| 722 void set_canonical_types(const Array& value) const; | 729 void set_canonical_types(const Array& value) const; |
| 723 RawArray* canonical_types() const; | 730 RawArray* canonical_types() const; |
| 724 | 731 |
| 725 void CalculateFieldOffsets() const; | 732 void CalculateFieldOffsets() const; |
| 726 | 733 |
| 727 // Assigns empty array to all raw class array fields. | 734 // Assigns empty array to all raw class array fields. |
| 728 void InitEmptyFields(); | 735 void InitEmptyFields(); |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 kKindTagSize = 4, | 1637 kKindTagSize = 4, |
| 1631 }; | 1638 }; |
| 1632 class StaticBit : public BitField<bool, kStaticBit, 1> {}; | 1639 class StaticBit : public BitField<bool, kStaticBit, 1> {}; |
| 1633 class ConstBit : public BitField<bool, kConstBit, 1> {}; | 1640 class ConstBit : public BitField<bool, kConstBit, 1> {}; |
| 1634 class OptimizableBit : public BitField<bool, kOptimizableBit, 1> {}; | 1641 class OptimizableBit : public BitField<bool, kOptimizableBit, 1> {}; |
| 1635 class HasFinallyBit : public BitField<bool, kHasFinallyBit, 1> {}; | 1642 class HasFinallyBit : public BitField<bool, kHasFinallyBit, 1> {}; |
| 1636 class NativeBit : public BitField<bool, kNativeBit, 1> {}; | 1643 class NativeBit : public BitField<bool, kNativeBit, 1> {}; |
| 1637 class AbstractBit : public BitField<bool, kAbstractBit, 1> {}; | 1644 class AbstractBit : public BitField<bool, kAbstractBit, 1> {}; |
| 1638 class ExternalBit : public BitField<bool, kExternalBit, 1> {}; | 1645 class ExternalBit : public BitField<bool, kExternalBit, 1> {}; |
| 1639 class KindBits : | 1646 class KindBits : |
| 1640 public BitField<RawFunction::Kind, kKindTagBit, kKindTagSize> {}; // NOLINT | 1647 public BitField<RawFunction::Kind, kKindTagBit, kKindTagSize> {}; // NOLINT |
| 1641 | 1648 |
| 1642 void set_name(const String& value) const; | 1649 void set_name(const String& value) const; |
| 1643 void set_kind(RawFunction::Kind value) const; | 1650 void set_kind(RawFunction::Kind value) const; |
| 1644 void set_is_static(bool is_static) const; | 1651 void set_is_static(bool is_static) const; |
| 1645 void set_is_const(bool is_const) const; | 1652 void set_is_const(bool is_const) const; |
| 1646 void set_is_external(bool value) const; | 1653 void set_is_external(bool value) const; |
| 1647 void set_parent_function(const Function& value) const; | 1654 void set_parent_function(const Function& value) const; |
| 1648 void set_owner(const Object& value) const; | 1655 void set_owner(const Object& value) const; |
| 1649 void set_token_pos(intptr_t value) const; | 1656 void set_token_pos(intptr_t value) const; |
| 1650 void set_implicit_closure_function(const Function& value) const; | 1657 void set_implicit_closure_function(const Function& value) const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1675 HEAP_OBJECT_IMPLEMENTATION(Function, Object); | 1682 HEAP_OBJECT_IMPLEMENTATION(Function, Object); |
| 1676 friend class Class; | 1683 friend class Class; |
| 1677 }; | 1684 }; |
| 1678 | 1685 |
| 1679 | 1686 |
| 1680 class Field : public Object { | 1687 class Field : public Object { |
| 1681 public: | 1688 public: |
| 1682 RawString* name() const { return raw_ptr()->name_; } | 1689 RawString* name() const { return raw_ptr()->name_; } |
| 1683 RawString* UserVisibleName() const; | 1690 RawString* UserVisibleName() const; |
| 1684 | 1691 |
| 1685 bool is_static() const { return raw_ptr()->is_static_; } | 1692 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } |
| 1686 bool is_final() const { return raw_ptr()->is_final_; } | 1693 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } |
| 1687 bool is_const() const { return raw_ptr()->is_const_; } | 1694 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } |
| 1688 | 1695 |
| 1689 inline intptr_t Offset() const; | 1696 inline intptr_t Offset() const; |
| 1690 inline void SetOffset(intptr_t value) const; | 1697 inline void SetOffset(intptr_t value) const; |
| 1691 | 1698 |
| 1692 RawInstance* value() const; | 1699 RawInstance* value() const; |
| 1693 void set_value(const Instance& value) const; | 1700 void set_value(const Instance& value) const; |
| 1694 | 1701 |
| 1695 RawClass* owner() const { return raw_ptr()->owner_; } | 1702 RawClass* owner() const { return raw_ptr()->owner_; } |
| 1696 | 1703 |
| 1697 RawAbstractType* type() const { return raw_ptr()->type_; } | 1704 RawAbstractType* type() const { return raw_ptr()->type_; } |
| 1698 void set_type(const AbstractType& value) const; | 1705 void set_type(const AbstractType& value) const; |
| 1699 | 1706 |
| 1700 static intptr_t InstanceSize() { | 1707 static intptr_t InstanceSize() { |
| 1701 return RoundedAllocationSize(sizeof(RawField)); | 1708 return RoundedAllocationSize(sizeof(RawField)); |
| 1702 } | 1709 } |
| 1703 | 1710 |
| 1704 static RawField* New(const String& name, | 1711 static RawField* New(const String& name, |
| 1705 bool is_static, | 1712 bool is_static, |
| 1706 bool is_final, | 1713 bool is_final, |
| 1707 bool is_const, | 1714 bool is_const, |
| 1708 const Class& owner, | 1715 const Class& owner, |
| 1709 intptr_t token_pos); | 1716 intptr_t token_pos); |
| 1710 | 1717 |
| 1711 static intptr_t value_offset() { return OFFSET_OF(RawField, value_); } | 1718 static intptr_t value_offset() { return OFFSET_OF(RawField, value_); } |
| 1712 | 1719 |
| 1713 intptr_t token_pos() const { return raw_ptr()->token_pos_; } | 1720 intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
| 1714 | 1721 |
| 1715 bool has_initializer() const { return raw_ptr()->has_initializer_; } | 1722 bool has_initializer() const { |
| 1723 return HasInitializerBit::decode(raw_ptr()->kind_bits_); |
| 1724 } |
| 1716 void set_has_initializer(bool has_initializer) const { | 1725 void set_has_initializer(bool has_initializer) const { |
| 1717 raw_ptr()->has_initializer_ = has_initializer; | 1726 uword bits = raw_ptr()->kind_bits_; |
| 1727 raw_ptr()->kind_bits_ = HasInitializerBit::update(has_initializer, bits); |
| 1718 } | 1728 } |
| 1719 | 1729 |
| 1720 // Constructs getter and setter names for fields and vice versa. | 1730 // Constructs getter and setter names for fields and vice versa. |
| 1721 static RawString* GetterName(const String& field_name); | 1731 static RawString* GetterName(const String& field_name); |
| 1722 static RawString* GetterSymbol(const String& field_name); | 1732 static RawString* GetterSymbol(const String& field_name); |
| 1723 static RawString* SetterName(const String& field_name); | 1733 static RawString* SetterName(const String& field_name); |
| 1724 static RawString* SetterSymbol(const String& field_name); | 1734 static RawString* SetterSymbol(const String& field_name); |
| 1725 static RawString* NameFromGetter(const String& getter_name); | 1735 static RawString* NameFromGetter(const String& getter_name); |
| 1726 static RawString* NameFromSetter(const String& setter_name); | 1736 static RawString* NameFromSetter(const String& setter_name); |
| 1727 static bool IsGetterName(const String& function_name); | 1737 static bool IsGetterName(const String& function_name); |
| 1728 static bool IsSetterName(const String& function_name); | 1738 static bool IsSetterName(const String& function_name); |
| 1729 | 1739 |
| 1730 private: | 1740 private: |
| 1741 enum { |
| 1742 kConstBit = 1, |
| 1743 kStaticBit, |
| 1744 kFinalBit, |
| 1745 kHasInitializerBit, |
| 1746 }; |
| 1747 class ConstBit : public BitField<bool, kConstBit, 1> {}; |
| 1748 class StaticBit : public BitField<bool, kStaticBit, 1> {}; |
| 1749 class FinalBit : public BitField<bool, kFinalBit, 1> {}; |
| 1750 class HasInitializerBit : public BitField<bool, kHasInitializerBit, 1> {}; |
| 1751 |
| 1731 void set_name(const String& value) const; | 1752 void set_name(const String& value) const; |
| 1732 void set_is_static(bool is_static) const { | 1753 void set_is_static(bool is_static) const { |
| 1733 raw_ptr()->is_static_ = is_static; | 1754 uword bits = raw_ptr()->kind_bits_; |
| 1755 raw_ptr()->kind_bits_ = StaticBit::update(is_static, bits); |
| 1734 } | 1756 } |
| 1735 void set_is_final(bool is_final) const { | 1757 void set_is_final(bool is_final) const { |
| 1736 raw_ptr()->is_final_ = is_final; | 1758 uword bits = raw_ptr()->kind_bits_; |
| 1759 raw_ptr()->kind_bits_ = FinalBit::update(is_final, bits); |
| 1737 } | 1760 } |
| 1738 void set_is_const(bool value) const { | 1761 void set_is_const(bool value) const { |
| 1739 raw_ptr()->is_const_ = value; | 1762 uword bits = raw_ptr()->kind_bits_; |
| 1763 raw_ptr()->kind_bits_ = ConstBit::update(value, bits); |
| 1740 } | 1764 } |
| 1741 void set_owner(const Class& value) const { | 1765 void set_owner(const Class& value) const { |
| 1742 StorePointer(&raw_ptr()->owner_, value.raw()); | 1766 StorePointer(&raw_ptr()->owner_, value.raw()); |
| 1743 } | 1767 } |
| 1744 void set_token_pos(intptr_t token_pos) const { | 1768 void set_token_pos(intptr_t token_pos) const { |
| 1745 raw_ptr()->token_pos_ = token_pos; | 1769 raw_ptr()->token_pos_ = token_pos; |
| 1746 } | 1770 } |
| 1771 void set_kind_bits(intptr_t value) const { |
| 1772 raw_ptr()->kind_bits_ = value; |
| 1773 } |
| 1747 static RawField* New(); | 1774 static RawField* New(); |
| 1748 | 1775 |
| 1749 HEAP_OBJECT_IMPLEMENTATION(Field, Object); | 1776 HEAP_OBJECT_IMPLEMENTATION(Field, Object); |
| 1750 friend class Class; | 1777 friend class Class; |
| 1778 friend class HeapProfiler; |
| 1751 }; | 1779 }; |
| 1752 | 1780 |
| 1753 | 1781 |
| 1754 class LiteralToken : public Object { | 1782 class LiteralToken : public Object { |
| 1755 public: | 1783 public: |
| 1756 Token::Kind kind() const { return raw_ptr()->kind_; } | 1784 Token::Kind kind() const { return raw_ptr()->kind_; } |
| 1757 RawString* literal() const { return raw_ptr()->literal_; } | 1785 RawString* literal() const { return raw_ptr()->literal_; } |
| 1758 RawObject* value() const { return raw_ptr()->value_; } | 1786 RawObject* value() const { return raw_ptr()->value_; } |
| 1759 | 1787 |
| 1760 static intptr_t InstanceSize() { | 1788 static intptr_t InstanceSize() { |
| (...skipping 3725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5486 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5514 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5487 return false; | 5515 return false; |
| 5488 } | 5516 } |
| 5489 } | 5517 } |
| 5490 return true; | 5518 return true; |
| 5491 } | 5519 } |
| 5492 | 5520 |
| 5493 } // namespace dart | 5521 } // namespace dart |
| 5494 | 5522 |
| 5495 #endif // VM_OBJECT_H_ | 5523 #endif // VM_OBJECT_H_ |
| OLD | NEW |