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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 // Returns the cached canonical type of this class, i.e. the canonical type | 1044 // Returns the cached canonical type of this class, i.e. the canonical type |
1045 // whose type class is this class and whose type arguments are the | 1045 // whose type class is this class and whose type arguments are the |
1046 // uninstantiated type parameters declared by this class if it is generic, | 1046 // uninstantiated type parameters declared by this class if it is generic, |
1047 // e.g. Map<K, V>. | 1047 // e.g. Map<K, V>. |
1048 // Returns Type::null() if the canonical type is not cached yet. | 1048 // Returns Type::null() if the canonical type is not cached yet. |
1049 RawType* CanonicalType() const; | 1049 RawType* CanonicalType() const; |
1050 | 1050 |
1051 // Caches the canonical type of this class. | 1051 // Caches the canonical type of this class. |
1052 void SetCanonicalType(const Type& type) const; | 1052 void SetCanonicalType(const Type& type) const; |
1053 | 1053 |
1054 static intptr_t canonical_types_offset() { | 1054 static intptr_t canonical_type_offset() { |
1055 return OFFSET_OF(RawClass, canonical_types_); | 1055 return OFFSET_OF(RawClass, canonical_type_); |
1056 } | 1056 } |
1057 | 1057 |
1058 // The super type of this class, Object type if not explicitly specified. | 1058 // The super type of this class, Object type if not explicitly specified. |
1059 // Note that the super type may be bounded, as in this example: | 1059 // Note that the super type may be bounded, as in this example: |
1060 // class C<T> extends S<T> { }; class S<T extends num> { }; | 1060 // class C<T> extends S<T> { }; class S<T extends num> { }; |
1061 RawAbstractType* super_type() const { return raw_ptr()->super_type_; } | 1061 RawAbstractType* super_type() const { return raw_ptr()->super_type_; } |
1062 void set_super_type(const AbstractType& value) const; | 1062 void set_super_type(const AbstractType& value) const; |
1063 static intptr_t super_type_offset() { | 1063 static intptr_t super_type_offset() { |
1064 return OFFSET_OF(RawClass, super_type_); | 1064 return OFFSET_OF(RawClass, super_type_); |
1065 } | 1065 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 // The methods above are more efficient than this generic one. | 1214 // The methods above are more efficient than this generic one. |
1215 RawInstance* LookupCanonicalInstance(Zone* zone, | 1215 RawInstance* LookupCanonicalInstance(Zone* zone, |
1216 const Instance& value) const; | 1216 const Instance& value) const; |
1217 | 1217 |
1218 RawInstance* InsertCanonicalConstant(Zone* zone, | 1218 RawInstance* InsertCanonicalConstant(Zone* zone, |
1219 const Instance& constant) const; | 1219 const Instance& constant) const; |
1220 void InsertCanonicalNumber(Zone* zone, | 1220 void InsertCanonicalNumber(Zone* zone, |
1221 intptr_t index, | 1221 intptr_t index, |
1222 const Number& constant) const; | 1222 const Number& constant) const; |
1223 | 1223 |
1224 intptr_t FindCanonicalTypeIndex(const AbstractType& needle) const; | |
1225 RawAbstractType* CanonicalTypeFromIndex(intptr_t idx) const; | |
1226 | |
1227 void RehashConstants(Zone* zone) const; | 1224 void RehashConstants(Zone* zone) const; |
1228 | 1225 |
1229 static intptr_t InstanceSize() { | 1226 static intptr_t InstanceSize() { |
1230 return RoundedAllocationSize(sizeof(RawClass)); | 1227 return RoundedAllocationSize(sizeof(RawClass)); |
1231 } | 1228 } |
1232 | 1229 |
1233 bool is_implemented() const { | 1230 bool is_implemented() const { |
1234 return ImplementedBit::decode(raw_ptr()->state_bits_); | 1231 return ImplementedBit::decode(raw_ptr()->state_bits_); |
1235 } | 1232 } |
1236 void set_is_implemented() const; | 1233 void set_is_implemented() const; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {}; | 1444 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {}; |
1448 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {}; | 1445 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {}; |
1449 | 1446 |
1450 void set_name(const String& value) const; | 1447 void set_name(const String& value) const; |
1451 void set_user_name(const String& value) const; | 1448 void set_user_name(const String& value) const; |
1452 RawString* GenerateUserVisibleName() const; | 1449 RawString* GenerateUserVisibleName() const; |
1453 void set_state_bits(intptr_t bits) const; | 1450 void set_state_bits(intptr_t bits) const; |
1454 | 1451 |
1455 void set_constants(const Array& value) const; | 1452 void set_constants(const Array& value) const; |
1456 | 1453 |
1457 void set_canonical_types(const Object& value) const; | 1454 void set_canonical_type(const Type& value) const; |
1458 RawObject* canonical_types() const; | 1455 RawType* canonical_type() const; |
1459 | 1456 |
1460 RawArray* invocation_dispatcher_cache() const; | 1457 RawArray* invocation_dispatcher_cache() const; |
1461 void set_invocation_dispatcher_cache(const Array& cache) const; | 1458 void set_invocation_dispatcher_cache(const Array& cache) const; |
1462 RawFunction* CreateInvocationDispatcher(const String& target_name, | 1459 RawFunction* CreateInvocationDispatcher(const String& target_name, |
1463 const Array& args_desc, | 1460 const Array& args_desc, |
1464 RawFunction::Kind kind) const; | 1461 RawFunction::Kind kind) const; |
1465 | 1462 |
1466 void CalculateFieldOffsets() const; | 1463 void CalculateFieldOffsets() const; |
1467 | 1464 |
1468 // functions_hash_table is in use iff there are at least this many functions. | 1465 // functions_hash_table is in use iff there are at least this many functions. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 static bool TypeTestNonRecursive( | 1509 static bool TypeTestNonRecursive( |
1513 const Class& cls, | 1510 const Class& cls, |
1514 TypeTestKind test_kind, | 1511 TypeTestKind test_kind, |
1515 const TypeArguments& type_arguments, | 1512 const TypeArguments& type_arguments, |
1516 const Class& other, | 1513 const Class& other, |
1517 const TypeArguments& other_type_arguments, | 1514 const TypeArguments& other_type_arguments, |
1518 Error* bound_error, | 1515 Error* bound_error, |
1519 TrailPtr bound_trail, | 1516 TrailPtr bound_trail, |
1520 Heap::Space space); | 1517 Heap::Space space); |
1521 | 1518 |
1522 // Returns AbstractType::null() if type not found. | |
1523 RawAbstractType* LookupCanonicalType(Zone* zone, | |
1524 const AbstractType& type, | |
1525 intptr_t* index) const; | |
1526 | |
1527 // Returns canonical type. Thread safe. | |
1528 RawAbstractType* LookupOrAddCanonicalType(const AbstractType& type, | |
1529 intptr_t start_index) const; | |
1530 | |
1531 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object); | 1519 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object); |
1532 friend class AbstractType; | 1520 friend class AbstractType; |
1533 friend class Instance; | 1521 friend class Instance; |
1534 friend class Object; | 1522 friend class Object; |
1535 friend class Type; | 1523 friend class Type; |
1536 friend class Intrinsifier; | 1524 friend class Intrinsifier; |
1537 friend class Precompiler; | 1525 friend class Precompiler; |
1538 }; | 1526 }; |
1539 | 1527 |
1540 | 1528 |
(...skipping 25 matching lines...) Expand all Loading... |
1566 static RawUnresolvedClass* New(); | 1554 static RawUnresolvedClass* New(); |
1567 | 1555 |
1568 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); | 1556 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); |
1569 friend class Class; | 1557 friend class Class; |
1570 }; | 1558 }; |
1571 | 1559 |
1572 | 1560 |
1573 // A TypeArguments is an array of AbstractType. | 1561 // A TypeArguments is an array of AbstractType. |
1574 class TypeArguments : public Object { | 1562 class TypeArguments : public Object { |
1575 public: | 1563 public: |
| 1564 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 1565 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 1566 // architecture. |
| 1567 static const intptr_t kHashBits = 30; |
| 1568 |
1576 intptr_t Length() const; | 1569 intptr_t Length() const; |
1577 RawAbstractType* TypeAt(intptr_t index) const; | 1570 RawAbstractType* TypeAt(intptr_t index) const; |
1578 static intptr_t type_at_offset(intptr_t index) { | 1571 static intptr_t type_at_offset(intptr_t index) { |
1579 return OFFSET_OF_RETURNED_VALUE( | 1572 return OFFSET_OF_RETURNED_VALUE( |
1580 RawTypeArguments, types) + index * kWordSize; | 1573 RawTypeArguments, types) + index * kWordSize; |
1581 } | 1574 } |
1582 void SetTypeAt(intptr_t index, const AbstractType& value) const; | 1575 void SetTypeAt(intptr_t index, const AbstractType& value) const; |
1583 | 1576 |
1584 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". | 1577 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". |
1585 RawString* Name() const { | 1578 RawString* Name() const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 1703 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
1711 | 1704 |
1712 static intptr_t InstanceSize() { | 1705 static intptr_t InstanceSize() { |
1713 ASSERT(sizeof(RawTypeArguments) == | 1706 ASSERT(sizeof(RawTypeArguments) == |
1714 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); | 1707 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); |
1715 return 0; | 1708 return 0; |
1716 } | 1709 } |
1717 | 1710 |
1718 static intptr_t InstanceSize(intptr_t len) { | 1711 static intptr_t InstanceSize(intptr_t len) { |
1719 // Ensure that the types() is not adding to the object size, which includes | 1712 // Ensure that the types() is not adding to the object size, which includes |
1720 // 2 fields: instantiations_ and length_. | 1713 // 3 fields: instantiations_, length_ and hash_. |
1721 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); | 1714 ASSERT(sizeof(RawTypeArguments) == |
| 1715 (sizeof(RawObject) + (kNumFields * kWordSize))); |
1722 ASSERT(0 <= len && len <= kMaxElements); | 1716 ASSERT(0 <= len && len <= kMaxElements); |
1723 return RoundedAllocationSize( | 1717 return RoundedAllocationSize( |
1724 sizeof(RawTypeArguments) + (len * kBytesPerElement)); | 1718 sizeof(RawTypeArguments) + (len * kBytesPerElement)); |
1725 } | 1719 } |
1726 | 1720 |
1727 intptr_t Hash() const; | 1721 intptr_t Hash() const; |
1728 | 1722 |
1729 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); | 1723 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); |
1730 | 1724 |
1731 private: | 1725 private: |
| 1726 intptr_t ComputeHash() const; |
| 1727 void SetHash(intptr_t value) const; |
| 1728 |
1732 // Check if the subvector of length 'len' starting at 'from_index' of this | 1729 // Check if the subvector of length 'len' starting at 'from_index' of this |
1733 // type argument vector consists solely of DynamicType. | 1730 // type argument vector consists solely of DynamicType. |
1734 // If raw_instantiated is true, consider each type parameter to be first | 1731 // If raw_instantiated is true, consider each type parameter to be first |
1735 // instantiated from a vector of dynamic types. | 1732 // instantiated from a vector of dynamic types. |
1736 bool IsDynamicTypes(bool raw_instantiated, | 1733 bool IsDynamicTypes(bool raw_instantiated, |
1737 intptr_t from_index, | 1734 intptr_t from_index, |
1738 intptr_t len) const; | 1735 intptr_t len) const; |
1739 | 1736 |
1740 // Check the subtype or 'more specific' relationship, considering only a | 1737 // Check the subtype or 'more specific' relationship, considering only a |
1741 // subvector of length 'len' starting at 'from_index'. | 1738 // subvector of length 'len' starting at 'from_index'. |
1742 bool TypeTest(TypeTestKind test_kind, | 1739 bool TypeTest(TypeTestKind test_kind, |
1743 const TypeArguments& other, | 1740 const TypeArguments& other, |
1744 intptr_t from_index, | 1741 intptr_t from_index, |
1745 intptr_t len, | 1742 intptr_t len, |
1746 Error* bound_error, | 1743 Error* bound_error, |
1747 TrailPtr bound_trail, | 1744 TrailPtr bound_trail, |
1748 Heap::Space space) const; | 1745 Heap::Space space) const; |
1749 | 1746 |
1750 // Return the internal or public name of a subvector of this type argument | 1747 // Return the internal or public name of a subvector of this type argument |
1751 // vector, e.g. "<T, dynamic, List<T>, int>". | 1748 // vector, e.g. "<T, dynamic, List<T>, int>". |
1752 RawString* SubvectorName(intptr_t from_index, | 1749 RawString* SubvectorName(intptr_t from_index, |
1753 intptr_t len, | 1750 intptr_t len, |
1754 NameVisibility name_visibility) const; | 1751 NameVisibility name_visibility) const; |
1755 | 1752 |
1756 RawArray* instantiations() const; | 1753 RawArray* instantiations() const; |
1757 void set_instantiations(const Array& value) const; | 1754 void set_instantiations(const Array& value) const; |
1758 RawAbstractType* const* TypeAddr(intptr_t index) const; | 1755 RawAbstractType* const* TypeAddr(intptr_t index) const; |
1759 void SetLength(intptr_t value) const; | 1756 void SetLength(intptr_t value) const; |
| 1757 // Number of fields in the raw object=3 (instantiations_, length_ and hash_). |
| 1758 static const int kNumFields = 3; |
1760 | 1759 |
1761 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object); | 1760 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object); |
1762 friend class AbstractType; | 1761 friend class AbstractType; |
1763 friend class Class; | 1762 friend class Class; |
1764 }; | 1763 }; |
1765 | 1764 |
1766 | 1765 |
1767 class PatchClass : public Object { | 1766 class PatchClass : public Object { |
1768 public: | 1767 public: |
1769 RawClass* patched_class() const { return raw_ptr()->patched_class_; } | 1768 RawClass* patched_class() const { return raw_ptr()->patched_class_; } |
(...skipping 3793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5563 | 5562 |
5564 // A Type consists of a class, possibly parameterized with type | 5563 // A Type consists of a class, possibly parameterized with type |
5565 // arguments. Example: C<T1, T2>. | 5564 // arguments. Example: C<T1, T2>. |
5566 // An unresolved class is a String specifying the class name. | 5565 // An unresolved class is a String specifying the class name. |
5567 // | 5566 // |
5568 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as | 5567 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as |
5569 // opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does not | 5568 // opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does not |
5570 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. | 5569 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. |
5571 class Type : public AbstractType { | 5570 class Type : public AbstractType { |
5572 public: | 5571 public: |
| 5572 // We use 30 bits for the hash code so that we consistently use a |
| 5573 // 32bit Smi representation for the hash code on all architectures. |
| 5574 static const intptr_t kHashBits = 30; |
| 5575 |
5573 static intptr_t type_class_offset() { | 5576 static intptr_t type_class_offset() { |
5574 return OFFSET_OF(RawType, type_class_); | 5577 return OFFSET_OF(RawType, type_class_); |
5575 } | 5578 } |
5576 virtual bool IsFinalized() const { | 5579 virtual bool IsFinalized() const { |
5577 return | 5580 return |
5578 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || | 5581 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || |
5579 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); | 5582 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); |
5580 } | 5583 } |
5581 virtual void SetIsFinalized() const; | 5584 virtual void SetIsFinalized() const; |
5582 void ResetIsFinalized() const; // Ignore current state and set again. | 5585 void ResetIsFinalized() const; // Ignore current state and set again. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5678 | 5681 |
5679 // The finalized type of the given non-parameterized class. | 5682 // The finalized type of the given non-parameterized class. |
5680 static RawType* NewNonParameterizedType(const Class& type_class); | 5683 static RawType* NewNonParameterizedType(const Class& type_class); |
5681 | 5684 |
5682 static RawType* New(const Object& clazz, | 5685 static RawType* New(const Object& clazz, |
5683 const TypeArguments& arguments, | 5686 const TypeArguments& arguments, |
5684 TokenPosition token_pos, | 5687 TokenPosition token_pos, |
5685 Heap::Space space = Heap::kOld); | 5688 Heap::Space space = Heap::kOld); |
5686 | 5689 |
5687 private: | 5690 private: |
| 5691 intptr_t ComputeHash() const; |
| 5692 void SetHash(intptr_t value) const; |
| 5693 |
5688 void set_token_pos(TokenPosition token_pos) const; | 5694 void set_token_pos(TokenPosition token_pos) const; |
5689 void set_type_state(int8_t state) const; | 5695 void set_type_state(int8_t state) const; |
5690 | 5696 |
5691 static RawType* New(Heap::Space space = Heap::kOld); | 5697 static RawType* New(Heap::Space space = Heap::kOld); |
5692 | 5698 |
5693 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); | 5699 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); |
5694 friend class Class; | 5700 friend class Class; |
5695 friend class TypeArguments; | 5701 friend class TypeArguments; |
5696 }; | 5702 }; |
5697 | 5703 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5768 // upper bound. | 5774 // upper bound. |
5769 // For example, the type parameter 'V' is specified as index 1 in the context of | 5775 // For example, the type parameter 'V' is specified as index 1 in the context of |
5770 // the class HashMap<K, V>. At compile time, the TypeParameter is not | 5776 // the class HashMap<K, V>. At compile time, the TypeParameter is not |
5771 // instantiated yet, i.e. it is only a place holder. | 5777 // instantiated yet, i.e. it is only a place holder. |
5772 // Upon finalization, the TypeParameter index is changed to reflect its position | 5778 // Upon finalization, the TypeParameter index is changed to reflect its position |
5773 // as type argument (rather than type parameter) of the parameterized class. | 5779 // as type argument (rather than type parameter) of the parameterized class. |
5774 // If the type parameter is declared without an extends clause, its bound is set | 5780 // If the type parameter is declared without an extends clause, its bound is set |
5775 // to the ObjectType. | 5781 // to the ObjectType. |
5776 class TypeParameter : public AbstractType { | 5782 class TypeParameter : public AbstractType { |
5777 public: | 5783 public: |
| 5784 // We use 30 bits for the hash code so that we consistently use a |
| 5785 // 32bit Smi representation for the hash code on all architectures. |
| 5786 static const intptr_t kHashBits = 30; |
| 5787 |
5778 virtual bool IsFinalized() const { | 5788 virtual bool IsFinalized() const { |
5779 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); | 5789 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); |
5780 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; | 5790 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; |
5781 } | 5791 } |
5782 virtual void SetIsFinalized() const; | 5792 virtual void SetIsFinalized() const; |
5783 virtual bool IsBeingFinalized() const { return false; } | 5793 virtual bool IsBeingFinalized() const { return false; } |
5784 virtual bool IsMalformed() const { return false; } | 5794 virtual bool IsMalformed() const { return false; } |
5785 virtual bool IsMalbounded() const { return false; } | 5795 virtual bool IsMalbounded() const { return false; } |
5786 virtual bool IsMalformedOrMalbounded() const { return false; } | 5796 virtual bool IsMalformedOrMalbounded() const { return false; } |
5787 virtual bool IsResolved() const { return true; } | 5797 virtual bool IsResolved() const { return true; } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5829 return RoundedAllocationSize(sizeof(RawTypeParameter)); | 5839 return RoundedAllocationSize(sizeof(RawTypeParameter)); |
5830 } | 5840 } |
5831 | 5841 |
5832 static RawTypeParameter* New(const Class& parameterized_class, | 5842 static RawTypeParameter* New(const Class& parameterized_class, |
5833 intptr_t index, | 5843 intptr_t index, |
5834 const String& name, | 5844 const String& name, |
5835 const AbstractType& bound, | 5845 const AbstractType& bound, |
5836 TokenPosition token_pos); | 5846 TokenPosition token_pos); |
5837 | 5847 |
5838 private: | 5848 private: |
| 5849 intptr_t ComputeHash() const; |
| 5850 void SetHash(intptr_t value) const; |
| 5851 |
5839 void set_parameterized_class(const Class& value) const; | 5852 void set_parameterized_class(const Class& value) const; |
5840 void set_name(const String& value) const; | 5853 void set_name(const String& value) const; |
5841 void set_token_pos(TokenPosition token_pos) const; | 5854 void set_token_pos(TokenPosition token_pos) const; |
5842 void set_type_state(int8_t state) const; | 5855 void set_type_state(int8_t state) const; |
5843 | 5856 |
5844 static RawTypeParameter* New(); | 5857 static RawTypeParameter* New(); |
5845 | 5858 |
5846 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); | 5859 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); |
5847 friend class Class; | 5860 friend class Class; |
5848 }; | 5861 }; |
5849 | 5862 |
5850 | 5863 |
5851 // A BoundedType represents a type instantiated at compile time from a type | 5864 // A BoundedType represents a type instantiated at compile time from a type |
5852 // parameter specifying a bound that either cannot be checked at compile time | 5865 // parameter specifying a bound that either cannot be checked at compile time |
5853 // because the type or the bound are still uninstantiated or can be checked and | 5866 // because the type or the bound are still uninstantiated or can be checked and |
5854 // would trigger a bound error in checked mode. The bound must be checked at | 5867 // would trigger a bound error in checked mode. The bound must be checked at |
5855 // runtime once the type and its bound are instantiated and when the execution | 5868 // runtime once the type and its bound are instantiated and when the execution |
5856 // mode is known to be checked mode. | 5869 // mode is known to be checked mode. |
5857 class BoundedType : public AbstractType { | 5870 class BoundedType : public AbstractType { |
5858 public: | 5871 public: |
| 5872 // We use 30 bits for the hash code so that we consistently use a |
| 5873 // 32bit Smi representation for the hash code on all architectures. |
| 5874 static const intptr_t kHashBits = 30; |
| 5875 |
5859 virtual bool IsFinalized() const { | 5876 virtual bool IsFinalized() const { |
5860 return AbstractType::Handle(type()).IsFinalized(); | 5877 return AbstractType::Handle(type()).IsFinalized(); |
5861 } | 5878 } |
5862 virtual bool IsBeingFinalized() const { | 5879 virtual bool IsBeingFinalized() const { |
5863 return AbstractType::Handle(type()).IsBeingFinalized(); | 5880 return AbstractType::Handle(type()).IsBeingFinalized(); |
5864 } | 5881 } |
5865 virtual bool IsMalformed() const; | 5882 virtual bool IsMalformed() const; |
5866 virtual bool IsMalbounded() const; | 5883 virtual bool IsMalbounded() const; |
5867 virtual bool IsMalformedOrMalbounded() const; | 5884 virtual bool IsMalformedOrMalbounded() const; |
5868 virtual RawLanguageError* error() const; | 5885 virtual RawLanguageError* error() const; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5914 | 5931 |
5915 static intptr_t InstanceSize() { | 5932 static intptr_t InstanceSize() { |
5916 return RoundedAllocationSize(sizeof(RawBoundedType)); | 5933 return RoundedAllocationSize(sizeof(RawBoundedType)); |
5917 } | 5934 } |
5918 | 5935 |
5919 static RawBoundedType* New(const AbstractType& type, | 5936 static RawBoundedType* New(const AbstractType& type, |
5920 const AbstractType& bound, | 5937 const AbstractType& bound, |
5921 const TypeParameter& type_parameter); | 5938 const TypeParameter& type_parameter); |
5922 | 5939 |
5923 private: | 5940 private: |
| 5941 intptr_t ComputeHash() const; |
| 5942 void SetHash(intptr_t value) const; |
| 5943 |
5924 void set_type(const AbstractType& value) const; | 5944 void set_type(const AbstractType& value) const; |
5925 void set_bound(const AbstractType& value) const; | 5945 void set_bound(const AbstractType& value) const; |
5926 void set_type_parameter(const TypeParameter& value) const; | 5946 void set_type_parameter(const TypeParameter& value) const; |
5927 | 5947 |
5928 static RawBoundedType* New(); | 5948 static RawBoundedType* New(); |
5929 | 5949 |
5930 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); | 5950 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); |
5931 friend class Class; | 5951 friend class Class; |
5932 }; | 5952 }; |
5933 | 5953 |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7108 static RawBool* New(bool value); | 7128 static RawBool* New(bool value); |
7109 | 7129 |
7110 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance); | 7130 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance); |
7111 friend class Class; | 7131 friend class Class; |
7112 friend class Object; // To initialize the true and false values. | 7132 friend class Object; // To initialize the true and false values. |
7113 }; | 7133 }; |
7114 | 7134 |
7115 | 7135 |
7116 class Array : public Instance { | 7136 class Array : public Instance { |
7117 public: | 7137 public: |
| 7138 // We use 30 bits for the hash code so that we consistently use a |
| 7139 // 32bit Smi representation for the hash code on all architectures. |
| 7140 static const intptr_t kHashBits = 30; |
| 7141 |
7118 intptr_t Length() const { | 7142 intptr_t Length() const { |
7119 ASSERT(!IsNull()); | 7143 ASSERT(!IsNull()); |
7120 return Smi::Value(raw_ptr()->length_); | 7144 return Smi::Value(raw_ptr()->length_); |
7121 } | 7145 } |
7122 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); } | 7146 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); } |
7123 static intptr_t data_offset() { | 7147 static intptr_t data_offset() { |
7124 return OFFSET_OF_RETURNED_VALUE(RawArray, data); | 7148 return OFFSET_OF_RETURNED_VALUE(RawArray, data); |
7125 } | 7149 } |
7126 static intptr_t element_offset(intptr_t index) { | 7150 static intptr_t element_offset(intptr_t index) { |
7127 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index; | 7151 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7475 } | 7499 } |
7476 | 7500 |
7477 private: | 7501 private: |
7478 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance); | 7502 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance); |
7479 friend class Class; | 7503 friend class Class; |
7480 }; | 7504 }; |
7481 | 7505 |
7482 | 7506 |
7483 class TypedData : public Instance { | 7507 class TypedData : public Instance { |
7484 public: | 7508 public: |
| 7509 // We use 30 bits for the hash code so that we consistently use a |
| 7510 // 32bit Smi representation for the hash code on all architectures. |
| 7511 static const intptr_t kHashBits = 30; |
| 7512 |
7485 intptr_t Length() const { | 7513 intptr_t Length() const { |
7486 ASSERT(!IsNull()); | 7514 ASSERT(!IsNull()); |
7487 return Smi::Value(raw_ptr()->length_); | 7515 return Smi::Value(raw_ptr()->length_); |
7488 } | 7516 } |
7489 | 7517 |
7490 intptr_t ElementSizeInBytes() const { | 7518 intptr_t ElementSizeInBytes() const { |
7491 intptr_t cid = raw()->GetClassId(); | 7519 intptr_t cid = raw()->GetClassId(); |
7492 return ElementSizeInBytes(cid); | 7520 return ElementSizeInBytes(cid); |
7493 } | 7521 } |
7494 | 7522 |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8521 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { | 8549 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { |
8522 return array.At((index * kEntryLength) + kClassIdIndex); | 8550 return array.At((index * kEntryLength) + kClassIdIndex); |
8523 } | 8551 } |
8524 | 8552 |
8525 | 8553 |
8526 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 8554 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
8527 intptr_t index) { | 8555 intptr_t index) { |
8528 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 8556 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
8529 } | 8557 } |
8530 | 8558 |
| 8559 |
| 8560 inline intptr_t Type::Hash() const { |
| 8561 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8562 if (result != 0) { |
| 8563 return result; |
| 8564 } |
| 8565 return ComputeHash(); |
| 8566 } |
| 8567 |
| 8568 |
| 8569 inline void Type::SetHash(intptr_t value) const { |
| 8570 // This is only safe because we create a new Smi, which does not cause |
| 8571 // heap allocation. |
| 8572 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8573 } |
| 8574 |
| 8575 |
| 8576 inline intptr_t TypeParameter::Hash() const { |
| 8577 ASSERT(IsFinalized()); |
| 8578 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8579 if (result != 0) { |
| 8580 return result; |
| 8581 } |
| 8582 return ComputeHash(); |
| 8583 } |
| 8584 |
| 8585 |
| 8586 inline void TypeParameter::SetHash(intptr_t value) const { |
| 8587 // This is only safe because we create a new Smi, which does not cause |
| 8588 // heap allocation. |
| 8589 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8590 } |
| 8591 |
| 8592 |
| 8593 inline intptr_t BoundedType::Hash() const { |
| 8594 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8595 if (result != 0) { |
| 8596 return result; |
| 8597 } |
| 8598 return ComputeHash(); |
| 8599 } |
| 8600 |
| 8601 |
| 8602 inline void BoundedType::SetHash(intptr_t value) const { |
| 8603 // This is only safe because we create a new Smi, which does not cause |
| 8604 // heap allocation. |
| 8605 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8606 } |
| 8607 |
| 8608 |
| 8609 inline intptr_t TypeArguments::Hash() const { |
| 8610 if (IsNull()) return 0; |
| 8611 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8612 if (result != 0) { |
| 8613 return result; |
| 8614 } |
| 8615 return ComputeHash(); |
| 8616 } |
| 8617 |
| 8618 |
| 8619 inline void TypeArguments::SetHash(intptr_t value) const { |
| 8620 // This is only safe because we create a new Smi, which does not cause |
| 8621 // heap allocation. |
| 8622 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8623 } |
| 8624 |
8531 } // namespace dart | 8625 } // namespace dart |
8532 | 8626 |
8533 #endif // VM_OBJECT_H_ | 8627 #endif // VM_OBJECT_H_ |
OLD | NEW |