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

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: 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
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; 1710 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
1711 1711
1712 static intptr_t InstanceSize() { 1712 static intptr_t InstanceSize() {
1713 ASSERT(sizeof(RawTypeArguments) == 1713 ASSERT(sizeof(RawTypeArguments) ==
1714 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); 1714 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types));
1715 return 0; 1715 return 0;
1716 } 1716 }
1717 1717
1718 static intptr_t InstanceSize(intptr_t len) { 1718 static intptr_t InstanceSize(intptr_t len) {
1719 // Ensure that the types() is not adding to the object size, which includes 1719 // Ensure that the types() is not adding to the object size, which includes
1720 // 2 fields: instantiations_ and length_. 1720 // 3 fields: instantiations_, length_ and hash_.
1721 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); 1721 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (3 * kWordSize)));
1722 ASSERT(0 <= len && len <= kMaxElements); 1722 ASSERT(0 <= len && len <= kMaxElements);
1723 return RoundedAllocationSize( 1723 return RoundedAllocationSize(
1724 sizeof(RawTypeArguments) + (len * kBytesPerElement)); 1724 sizeof(RawTypeArguments) + (len * kBytesPerElement));
1725 } 1725 }
1726 1726
1727 intptr_t Hash() const; 1727 intptr_t Hash() const;
1728 1728
1729 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); 1729 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld);
1730 1730
1731 private: 1731 private:
1732 intptr_t ComputeHash() const;
1733 void SetHash(intptr_t value) const;
1734
1732 // Check if the subvector of length 'len' starting at 'from_index' of this 1735 // Check if the subvector of length 'len' starting at 'from_index' of this
1733 // type argument vector consists solely of DynamicType. 1736 // type argument vector consists solely of DynamicType.
1734 // If raw_instantiated is true, consider each type parameter to be first 1737 // If raw_instantiated is true, consider each type parameter to be first
1735 // instantiated from a vector of dynamic types. 1738 // instantiated from a vector of dynamic types.
1736 bool IsDynamicTypes(bool raw_instantiated, 1739 bool IsDynamicTypes(bool raw_instantiated,
1737 intptr_t from_index, 1740 intptr_t from_index,
1738 intptr_t len) const; 1741 intptr_t len) const;
1739 1742
1740 // Check the subtype or 'more specific' relationship, considering only a 1743 // Check the subtype or 'more specific' relationship, considering only a
1741 // subvector of length 'len' starting at 'from_index'. 1744 // subvector of length 'len' starting at 'from_index'.
(...skipping 3936 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
5829 return RoundedAllocationSize(sizeof(RawTypeParameter)); 5835 return RoundedAllocationSize(sizeof(RawTypeParameter));
5830 } 5836 }
5831 5837
5832 static RawTypeParameter* New(const Class& parameterized_class, 5838 static RawTypeParameter* New(const Class& parameterized_class,
5833 intptr_t index, 5839 intptr_t index,
5834 const String& name, 5840 const String& name,
5835 const AbstractType& bound, 5841 const AbstractType& bound,
5836 TokenPosition token_pos); 5842 TokenPosition token_pos);
5837 5843
5838 private: 5844 private:
5845 intptr_t ComputeHash() const;
5846 void SetHash(intptr_t value) const;
5847
5839 void set_parameterized_class(const Class& value) const; 5848 void set_parameterized_class(const Class& value) const;
5840 void set_name(const String& value) const; 5849 void set_name(const String& value) const;
5841 void set_token_pos(TokenPosition token_pos) const; 5850 void set_token_pos(TokenPosition token_pos) const;
5842 void set_type_state(int8_t state) const; 5851 void set_type_state(int8_t state) const;
5843 5852
5844 static RawTypeParameter* New(); 5853 static RawTypeParameter* New();
5845 5854
5846 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); 5855 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType);
5847 friend class Class; 5856 friend class Class;
5848 }; 5857 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5914 5923
5915 static intptr_t InstanceSize() { 5924 static intptr_t InstanceSize() {
5916 return RoundedAllocationSize(sizeof(RawBoundedType)); 5925 return RoundedAllocationSize(sizeof(RawBoundedType));
5917 } 5926 }
5918 5927
5919 static RawBoundedType* New(const AbstractType& type, 5928 static RawBoundedType* New(const AbstractType& type,
5920 const AbstractType& bound, 5929 const AbstractType& bound,
5921 const TypeParameter& type_parameter); 5930 const TypeParameter& type_parameter);
5922 5931
5923 private: 5932 private:
5933 intptr_t ComputeHash() const;
5934 void SetHash(intptr_t value) const;
5935
5924 void set_type(const AbstractType& value) const; 5936 void set_type(const AbstractType& value) const;
5925 void set_bound(const AbstractType& value) const; 5937 void set_bound(const AbstractType& value) const;
5926 void set_type_parameter(const TypeParameter& value) const; 5938 void set_type_parameter(const TypeParameter& value) const;
5927 5939
5928 static RawBoundedType* New(); 5940 static RawBoundedType* New();
5929 5941
5930 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); 5942 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType);
5931 friend class Class; 5943 friend class Class;
5932 }; 5944 };
5933 5945
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after
8521 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { 8533 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) {
8522 return array.At((index * kEntryLength) + kClassIdIndex); 8534 return array.At((index * kEntryLength) + kClassIdIndex);
8523 } 8535 }
8524 8536
8525 8537
8526 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8538 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8527 intptr_t index) { 8539 intptr_t index) {
8528 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8540 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8529 } 8541 }
8530 8542
8543
8544 inline intptr_t Type::Hash() const {
8545 intptr_t result = Smi::Value(raw_ptr()->hash_);
8546 if (result != 0) {
regis 2016/05/10 18:14:26 What if the hash is 0?
siva 2016/05/13 23:16:13 I have fixed this similar to the StringHasher to r
8547 return result;
8548 }
8549 return ComputeHash();
8550 }
8551
8552
8553 inline void Type::SetHash(intptr_t value) const {
8554 // This is only safe because we create a new Smi, which does not cause
8555 // heap allocation.
8556 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8557 }
8558
8559
8560 inline intptr_t TypeParameter::Hash() const {
8561 ASSERT(IsFinalized());
8562 intptr_t result = Smi::Value(raw_ptr()->hash_);
8563 if (result != 0) {
8564 return result;
8565 }
8566 return ComputeHash();
8567 }
8568
8569
8570 inline void TypeParameter::SetHash(intptr_t value) const {
8571 // This is only safe because we create a new Smi, which does not cause
8572 // heap allocation.
8573 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
regis 2016/05/10 18:14:26 What if the value does not fit in a Smi?
siva 2016/05/13 23:16:13 I have fixed this similar to the StringHasher by h
8574 }
8575
8576
8577 inline intptr_t BoundedType::Hash() const {
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 BoundedType::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 TypeArguments::Hash() const {
8594 if (IsNull()) return 0;
8595 intptr_t result = Smi::Value(raw_ptr()->hash_);
8596 if (result != 0) {
8597 return result;
8598 }
8599 return ComputeHash();
8600 }
8601
8602
8603 inline void TypeArguments::SetHash(intptr_t value) const {
8604 // This is only safe because we create a new Smi, which does not cause
8605 // heap allocation.
8606 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8607 }
8608
8531 } // namespace dart 8609 } // namespace dart
8532 8610
8533 #endif // VM_OBJECT_H_ 8611 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698