Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: runtime/vm/object.h

Issue 1965493004: Canonicalize generic types in an isolate specific hash table (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync-tot Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {}; 1447 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {};
1448 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {}; 1448 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {};
1449 1449
1450 void set_name(const String& value) const; 1450 void set_name(const String& value) const;
1451 void set_user_name(const String& value) const; 1451 void set_user_name(const String& value) const;
1452 RawString* GenerateUserVisibleName() const; 1452 RawString* GenerateUserVisibleName() const;
1453 void set_state_bits(intptr_t bits) const; 1453 void set_state_bits(intptr_t bits) const;
1454 1454
1455 void set_constants(const Array& value) const; 1455 void set_constants(const Array& value) const;
1456 1456
1457 void set_canonical_types(const Object& value) const; 1457 void set_canonical_type(const Type& value) const;
1458 RawObject* canonical_types() const; 1458 RawType* canonical_type() const;
1459 1459
1460 RawArray* invocation_dispatcher_cache() const; 1460 RawArray* invocation_dispatcher_cache() const;
1461 void set_invocation_dispatcher_cache(const Array& cache) const; 1461 void set_invocation_dispatcher_cache(const Array& cache) const;
1462 RawFunction* CreateInvocationDispatcher(const String& target_name, 1462 RawFunction* CreateInvocationDispatcher(const String& target_name,
1463 const Array& args_desc, 1463 const Array& args_desc,
1464 RawFunction::Kind kind) const; 1464 RawFunction::Kind kind) const;
1465 1465
1466 void CalculateFieldOffsets() const; 1466 void CalculateFieldOffsets() const;
1467 1467
1468 // functions_hash_table is in use iff there are at least this many functions. 1468 // 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
1512 static bool TypeTestNonRecursive( 1512 static bool TypeTestNonRecursive(
1513 const Class& cls, 1513 const Class& cls,
1514 TypeTestKind test_kind, 1514 TypeTestKind test_kind,
1515 const TypeArguments& type_arguments, 1515 const TypeArguments& type_arguments,
1516 const Class& other, 1516 const Class& other,
1517 const TypeArguments& other_type_arguments, 1517 const TypeArguments& other_type_arguments,
1518 Error* bound_error, 1518 Error* bound_error,
1519 TrailPtr bound_trail, 1519 TrailPtr bound_trail,
1520 Heap::Space space); 1520 Heap::Space space);
1521 1521
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); 1522 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object);
1532 friend class AbstractType; 1523 friend class AbstractType;
1533 friend class Instance; 1524 friend class Instance;
1534 friend class Object; 1525 friend class Object;
1535 friend class Type; 1526 friend class Type;
1536 friend class Intrinsifier; 1527 friend class Intrinsifier;
1537 friend class Precompiler; 1528 friend class Precompiler;
1538 }; 1529 };
1539 1530
1540 1531
(...skipping 25 matching lines...) Expand all
1566 static RawUnresolvedClass* New(); 1557 static RawUnresolvedClass* New();
1567 1558
1568 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); 1559 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object);
1569 friend class Class; 1560 friend class Class;
1570 }; 1561 };
1571 1562
1572 1563
1573 // A TypeArguments is an array of AbstractType. 1564 // A TypeArguments is an array of AbstractType.
1574 class TypeArguments : public Object { 1565 class TypeArguments : public Object {
1575 public: 1566 public:
1567 // We use 30 bits for the hash code so that we consistently use a
1568 // 32bit Smi representation for the hash code on all architectures.
1569 static const intptr_t kHashBits = 30;
Cutch 2016/05/16 17:01:57 should this constant `kHashBits` sit somewhere hig
rmacnak 2016/05/16 19:37:02 "so that we consistently use a 32bit Smi represent
siva 2016/05/16 23:24:25 Done.
siva 2016/05/16 23:24:25 I am thinking it is specific to hashes in classes
1570
1576 intptr_t Length() const; 1571 intptr_t Length() const;
1577 RawAbstractType* TypeAt(intptr_t index) const; 1572 RawAbstractType* TypeAt(intptr_t index) const;
1578 static intptr_t type_at_offset(intptr_t index) { 1573 static intptr_t type_at_offset(intptr_t index) {
1579 return OFFSET_OF_RETURNED_VALUE( 1574 return OFFSET_OF_RETURNED_VALUE(
1580 RawTypeArguments, types) + index * kWordSize; 1575 RawTypeArguments, types) + index * kWordSize;
1581 } 1576 }
1582 void SetTypeAt(intptr_t index, const AbstractType& value) const; 1577 void SetTypeAt(intptr_t index, const AbstractType& value) const;
1583 1578
1584 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". 1579 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>".
1585 RawString* Name() const { 1580 RawString* Name() const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; 1705 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
1711 1706
1712 static intptr_t InstanceSize() { 1707 static intptr_t InstanceSize() {
1713 ASSERT(sizeof(RawTypeArguments) == 1708 ASSERT(sizeof(RawTypeArguments) ==
1714 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); 1709 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types));
1715 return 0; 1710 return 0;
1716 } 1711 }
1717 1712
1718 static intptr_t InstanceSize(intptr_t len) { 1713 static intptr_t InstanceSize(intptr_t len) {
1719 // Ensure that the types() is not adding to the object size, which includes 1714 // Ensure that the types() is not adding to the object size, which includes
1720 // 2 fields: instantiations_ and length_. 1715 // 3 fields: instantiations_, length_ and hash_.
1721 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); 1716 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (3 * kWordSize)));
Cutch 2016/05/16 17:01:57 Should this "3" be a named constant with an ASSERT
siva 2016/05/16 23:24:25 made a named constant, the ASSERT captures any iss
1722 ASSERT(0 <= len && len <= kMaxElements); 1717 ASSERT(0 <= len && len <= kMaxElements);
1723 return RoundedAllocationSize( 1718 return RoundedAllocationSize(
1724 sizeof(RawTypeArguments) + (len * kBytesPerElement)); 1719 sizeof(RawTypeArguments) + (len * kBytesPerElement));
1725 } 1720 }
1726 1721
1727 intptr_t Hash() const; 1722 intptr_t Hash() const;
1728 1723
1729 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); 1724 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld);
1730 1725
1731 private: 1726 private:
1727 intptr_t ComputeHash() const;
1728 void SetHash(intptr_t value) const;
1729
1732 // Check if the subvector of length 'len' starting at 'from_index' of this 1730 // Check if the subvector of length 'len' starting at 'from_index' of this
1733 // type argument vector consists solely of DynamicType. 1731 // type argument vector consists solely of DynamicType.
1734 // If raw_instantiated is true, consider each type parameter to be first 1732 // If raw_instantiated is true, consider each type parameter to be first
1735 // instantiated from a vector of dynamic types. 1733 // instantiated from a vector of dynamic types.
1736 bool IsDynamicTypes(bool raw_instantiated, 1734 bool IsDynamicTypes(bool raw_instantiated,
1737 intptr_t from_index, 1735 intptr_t from_index,
1738 intptr_t len) const; 1736 intptr_t len) const;
1739 1737
1740 // Check the subtype or 'more specific' relationship, considering only a 1738 // Check the subtype or 'more specific' relationship, considering only a
1741 // subvector of length 'len' starting at 'from_index'. 1739 // subvector of length 'len' starting at 'from_index'.
(...skipping 3821 matching lines...) Expand 10 before | Expand all | Expand 10 after
5563 5561
5564 // A Type consists of a class, possibly parameterized with type 5562 // A Type consists of a class, possibly parameterized with type
5565 // arguments. Example: C<T1, T2>. 5563 // arguments. Example: C<T1, T2>.
5566 // An unresolved class is a String specifying the class name. 5564 // An unresolved class is a String specifying the class name.
5567 // 5565 //
5568 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as 5566 // 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 5567 // 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'. 5568 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'.
5571 class Type : public AbstractType { 5569 class Type : public AbstractType {
5572 public: 5570 public:
5571 // We use 30 bits for the hash code so that we consistently use a
5572 // 32bit Smi representation for the hash code on all architectures.
5573 static const intptr_t kHashBits = 30;
5574
5573 static intptr_t type_class_offset() { 5575 static intptr_t type_class_offset() {
5574 return OFFSET_OF(RawType, type_class_); 5576 return OFFSET_OF(RawType, type_class_);
5575 } 5577 }
5576 virtual bool IsFinalized() const { 5578 virtual bool IsFinalized() const {
5577 return 5579 return
5578 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || 5580 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) ||
5579 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); 5581 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated);
5580 } 5582 }
5581 virtual void SetIsFinalized() const; 5583 virtual void SetIsFinalized() const;
5582 void ResetIsFinalized() const; // Ignore current state and set again. 5584 void ResetIsFinalized() const; // Ignore current state and set again.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
5678 5680
5679 // The finalized type of the given non-parameterized class. 5681 // The finalized type of the given non-parameterized class.
5680 static RawType* NewNonParameterizedType(const Class& type_class); 5682 static RawType* NewNonParameterizedType(const Class& type_class);
5681 5683
5682 static RawType* New(const Object& clazz, 5684 static RawType* New(const Object& clazz,
5683 const TypeArguments& arguments, 5685 const TypeArguments& arguments,
5684 TokenPosition token_pos, 5686 TokenPosition token_pos,
5685 Heap::Space space = Heap::kOld); 5687 Heap::Space space = Heap::kOld);
5686 5688
5687 private: 5689 private:
5690 intptr_t ComputeHash() const;
5691 void SetHash(intptr_t value) const;
5692
5688 void set_token_pos(TokenPosition token_pos) const; 5693 void set_token_pos(TokenPosition token_pos) const;
5689 void set_type_state(int8_t state) const; 5694 void set_type_state(int8_t state) const;
5690 5695
5691 static RawType* New(Heap::Space space = Heap::kOld); 5696 static RawType* New(Heap::Space space = Heap::kOld);
5692 5697
5693 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); 5698 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType);
5694 friend class Class; 5699 friend class Class;
5695 friend class TypeArguments; 5700 friend class TypeArguments;
5696 }; 5701 };
5697 5702
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5768 // upper bound. 5773 // upper bound.
5769 // For example, the type parameter 'V' is specified as index 1 in the context of 5774 // 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 5775 // the class HashMap<K, V>. At compile time, the TypeParameter is not
5771 // instantiated yet, i.e. it is only a place holder. 5776 // instantiated yet, i.e. it is only a place holder.
5772 // Upon finalization, the TypeParameter index is changed to reflect its position 5777 // Upon finalization, the TypeParameter index is changed to reflect its position
5773 // as type argument (rather than type parameter) of the parameterized class. 5778 // 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 5779 // If the type parameter is declared without an extends clause, its bound is set
5775 // to the ObjectType. 5780 // to the ObjectType.
5776 class TypeParameter : public AbstractType { 5781 class TypeParameter : public AbstractType {
5777 public: 5782 public:
5783 // We use 30 bits for the hash code so that we consistently use a
5784 // 32bit Smi representation for the hash code on all architectures.
5785 static const intptr_t kHashBits = 30;
5786
5778 virtual bool IsFinalized() const { 5787 virtual bool IsFinalized() const {
5779 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); 5788 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated);
5780 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; 5789 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated;
5781 } 5790 }
5782 virtual void SetIsFinalized() const; 5791 virtual void SetIsFinalized() const;
5783 virtual bool IsBeingFinalized() const { return false; } 5792 virtual bool IsBeingFinalized() const { return false; }
5784 virtual bool IsMalformed() const { return false; } 5793 virtual bool IsMalformed() const { return false; }
5785 virtual bool IsMalbounded() const { return false; } 5794 virtual bool IsMalbounded() const { return false; }
5786 virtual bool IsMalformedOrMalbounded() const { return false; } 5795 virtual bool IsMalformedOrMalbounded() const { return false; }
5787 virtual bool IsResolved() const { return true; } 5796 virtual bool IsResolved() const { return true; }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5829 return RoundedAllocationSize(sizeof(RawTypeParameter)); 5838 return RoundedAllocationSize(sizeof(RawTypeParameter));
5830 } 5839 }
5831 5840
5832 static RawTypeParameter* New(const Class& parameterized_class, 5841 static RawTypeParameter* New(const Class& parameterized_class,
5833 intptr_t index, 5842 intptr_t index,
5834 const String& name, 5843 const String& name,
5835 const AbstractType& bound, 5844 const AbstractType& bound,
5836 TokenPosition token_pos); 5845 TokenPosition token_pos);
5837 5846
5838 private: 5847 private:
5848 intptr_t ComputeHash() const;
5849 void SetHash(intptr_t value) const;
5850
5839 void set_parameterized_class(const Class& value) const; 5851 void set_parameterized_class(const Class& value) const;
5840 void set_name(const String& value) const; 5852 void set_name(const String& value) const;
5841 void set_token_pos(TokenPosition token_pos) const; 5853 void set_token_pos(TokenPosition token_pos) const;
5842 void set_type_state(int8_t state) const; 5854 void set_type_state(int8_t state) const;
5843 5855
5844 static RawTypeParameter* New(); 5856 static RawTypeParameter* New();
5845 5857
5846 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); 5858 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType);
5847 friend class Class; 5859 friend class Class;
5848 }; 5860 };
5849 5861
5850 5862
5851 // A BoundedType represents a type instantiated at compile time from a type 5863 // 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 5864 // 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 5865 // 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 5866 // 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 5867 // runtime once the type and its bound are instantiated and when the execution
5856 // mode is known to be checked mode. 5868 // mode is known to be checked mode.
5857 class BoundedType : public AbstractType { 5869 class BoundedType : public AbstractType {
5858 public: 5870 public:
5871 // We use 30 bits for the hash code so that we consistently use a
5872 // 32bit Smi representation for the hash code on all architectures.
5873 static const intptr_t kHashBits = 30;
5874
5859 virtual bool IsFinalized() const { 5875 virtual bool IsFinalized() const {
5860 return AbstractType::Handle(type()).IsFinalized(); 5876 return AbstractType::Handle(type()).IsFinalized();
5861 } 5877 }
5862 virtual bool IsBeingFinalized() const { 5878 virtual bool IsBeingFinalized() const {
5863 return AbstractType::Handle(type()).IsBeingFinalized(); 5879 return AbstractType::Handle(type()).IsBeingFinalized();
5864 } 5880 }
5865 virtual bool IsMalformed() const; 5881 virtual bool IsMalformed() const;
5866 virtual bool IsMalbounded() const; 5882 virtual bool IsMalbounded() const;
5867 virtual bool IsMalformedOrMalbounded() const; 5883 virtual bool IsMalformedOrMalbounded() const;
5868 virtual RawLanguageError* error() const; 5884 virtual RawLanguageError* error() const;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5914 5930
5915 static intptr_t InstanceSize() { 5931 static intptr_t InstanceSize() {
5916 return RoundedAllocationSize(sizeof(RawBoundedType)); 5932 return RoundedAllocationSize(sizeof(RawBoundedType));
5917 } 5933 }
5918 5934
5919 static RawBoundedType* New(const AbstractType& type, 5935 static RawBoundedType* New(const AbstractType& type,
5920 const AbstractType& bound, 5936 const AbstractType& bound,
5921 const TypeParameter& type_parameter); 5937 const TypeParameter& type_parameter);
5922 5938
5923 private: 5939 private:
5940 intptr_t ComputeHash() const;
5941 void SetHash(intptr_t value) const;
5942
5924 void set_type(const AbstractType& value) const; 5943 void set_type(const AbstractType& value) const;
5925 void set_bound(const AbstractType& value) const; 5944 void set_bound(const AbstractType& value) const;
5926 void set_type_parameter(const TypeParameter& value) const; 5945 void set_type_parameter(const TypeParameter& value) const;
5927 5946
5928 static RawBoundedType* New(); 5947 static RawBoundedType* New();
5929 5948
5930 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); 5949 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType);
5931 friend class Class; 5950 friend class Class;
5932 }; 5951 };
5933 5952
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
7108 static RawBool* New(bool value); 7127 static RawBool* New(bool value);
7109 7128
7110 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance); 7129 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance);
7111 friend class Class; 7130 friend class Class;
7112 friend class Object; // To initialize the true and false values. 7131 friend class Object; // To initialize the true and false values.
7113 }; 7132 };
7114 7133
7115 7134
7116 class Array : public Instance { 7135 class Array : public Instance {
7117 public: 7136 public:
7137 // We use 30 bits for the hash code so that we consistently use a
7138 // 32bit Smi representation for the hash code on all architectures.
7139 static const intptr_t kHashBits = 30;
7140
7118 intptr_t Length() const { 7141 intptr_t Length() const {
7119 ASSERT(!IsNull()); 7142 ASSERT(!IsNull());
7120 return Smi::Value(raw_ptr()->length_); 7143 return Smi::Value(raw_ptr()->length_);
7121 } 7144 }
7122 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); } 7145 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); }
7123 static intptr_t data_offset() { 7146 static intptr_t data_offset() {
7124 return OFFSET_OF_RETURNED_VALUE(RawArray, data); 7147 return OFFSET_OF_RETURNED_VALUE(RawArray, data);
7125 } 7148 }
7126 static intptr_t element_offset(intptr_t index) { 7149 static intptr_t element_offset(intptr_t index) {
7127 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index; 7150 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
7475 } 7498 }
7476 7499
7477 private: 7500 private:
7478 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance); 7501 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance);
7479 friend class Class; 7502 friend class Class;
7480 }; 7503 };
7481 7504
7482 7505
7483 class TypedData : public Instance { 7506 class TypedData : public Instance {
7484 public: 7507 public:
7508 // We use 30 bits for the hash code so that we consistently use a
7509 // 32bit Smi representation for the hash code on all architectures.
7510 static const intptr_t kHashBits = 30;
7511
7485 intptr_t Length() const { 7512 intptr_t Length() const {
7486 ASSERT(!IsNull()); 7513 ASSERT(!IsNull());
7487 return Smi::Value(raw_ptr()->length_); 7514 return Smi::Value(raw_ptr()->length_);
7488 } 7515 }
7489 7516
7490 intptr_t ElementSizeInBytes() const { 7517 intptr_t ElementSizeInBytes() const {
7491 intptr_t cid = raw()->GetClassId(); 7518 intptr_t cid = raw()->GetClassId();
7492 return ElementSizeInBytes(cid); 7519 return ElementSizeInBytes(cid);
7493 } 7520 }
7494 7521
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
8521 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { 8548 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) {
8522 return array.At((index * kEntryLength) + kClassIdIndex); 8549 return array.At((index * kEntryLength) + kClassIdIndex);
8523 } 8550 }
8524 8551
8525 8552
8526 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8553 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8527 intptr_t index) { 8554 intptr_t index) {
8528 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8555 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8529 } 8556 }
8530 8557
8558
8559 inline intptr_t Type::Hash() const {
8560 intptr_t result = Smi::Value(raw_ptr()->hash_);
8561 if (result != 0) {
8562 return result;
8563 }
8564 return ComputeHash();
8565 }
8566
8567
8568 inline void Type::SetHash(intptr_t value) const {
8569 // This is only safe because we create a new Smi, which does not cause
8570 // heap allocation.
8571 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8572 }
8573
8574
8575 inline intptr_t TypeParameter::Hash() const {
8576 ASSERT(IsFinalized());
8577 intptr_t result = Smi::Value(raw_ptr()->hash_);
8578 if (result != 0) {
8579 return result;
8580 }
8581 return ComputeHash();
8582 }
8583
8584
8585 inline void TypeParameter::SetHash(intptr_t value) const {
8586 // This is only safe because we create a new Smi, which does not cause
8587 // heap allocation.
8588 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8589 }
8590
8591
8592 inline intptr_t BoundedType::Hash() const {
8593 intptr_t result = Smi::Value(raw_ptr()->hash_);
8594 if (result != 0) {
8595 return result;
8596 }
8597 return ComputeHash();
8598 }
8599
8600
8601 inline void BoundedType::SetHash(intptr_t value) const {
8602 // This is only safe because we create a new Smi, which does not cause
8603 // heap allocation.
8604 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8605 }
8606
8607
8608 inline intptr_t TypeArguments::Hash() const {
8609 if (IsNull()) return 0;
regis 2016/05/16 20:17:48 Thinking aloud here. Is it OK to return 0? 0 means
siva 2016/05/16 23:24:25 Acknowledged.
8610 intptr_t result = Smi::Value(raw_ptr()->hash_);
8611 if (result != 0) {
8612 return result;
8613 }
8614 return ComputeHash();
8615 }
8616
8617
8618 inline void TypeArguments::SetHash(intptr_t value) const {
8619 // This is only safe because we create a new Smi, which does not cause
8620 // heap allocation.
8621 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8622 }
8623
8531 } // namespace dart 8624 } // namespace dart
8532 8625
8533 #endif // VM_OBJECT_H_ 8626 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698