OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3639 ASSERT(UsesSeed); | 3639 ASSERT(UsesSeed); |
3640 return Hash(key); | 3640 return Hash(key); |
3641 } | 3641 } |
3642 static uint32_t HashForObject(Key key, Object* object) { return 0; } | 3642 static uint32_t HashForObject(Key key, Object* object) { return 0; } |
3643 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { | 3643 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
3644 ASSERT(UsesSeed); | 3644 ASSERT(UsesSeed); |
3645 return HashForObject(key, object); | 3645 return HashForObject(key, object); |
3646 } | 3646 } |
3647 }; | 3647 }; |
3648 | 3648 |
3649 template<typename Shape, typename Key> | 3649 template<typename Derived, typename Shape, typename Key> |
3650 class HashTable: public FixedArray { | 3650 class HashTable: public FixedArray { |
3651 public: | 3651 public: |
3652 // Wrapper methods | 3652 // Wrapper methods |
3653 inline uint32_t Hash(Key key) { | 3653 inline uint32_t Hash(Key key) { |
3654 if (Shape::UsesSeed) { | 3654 if (Shape::UsesSeed) { |
3655 return Shape::SeededHash(key, | 3655 return Shape::SeededHash(key, |
3656 GetHeap()->HashSeed()); | 3656 GetHeap()->HashSeed()); |
3657 } else { | 3657 } else { |
3658 return Shape::Hash(key); | 3658 return Shape::Hash(key); |
3659 } | 3659 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3692 void ElementRemoved() { | 3692 void ElementRemoved() { |
3693 SetNumberOfElements(NumberOfElements() - 1); | 3693 SetNumberOfElements(NumberOfElements() - 1); |
3694 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); | 3694 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
3695 } | 3695 } |
3696 void ElementsRemoved(int n) { | 3696 void ElementsRemoved(int n) { |
3697 SetNumberOfElements(NumberOfElements() - n); | 3697 SetNumberOfElements(NumberOfElements() - n); |
3698 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); | 3698 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
3699 } | 3699 } |
3700 | 3700 |
3701 // Returns a new HashTable object. Might return Failure. | 3701 // Returns a new HashTable object. Might return Failure. |
3702 // TODO(ishell): this will be eventually replaced by New(). | |
3702 MUST_USE_RESULT static MaybeObject* Allocate( | 3703 MUST_USE_RESULT static MaybeObject* Allocate( |
3703 Heap* heap, | 3704 Heap* heap, |
3704 int at_least_space_for, | 3705 int at_least_space_for, |
3705 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, | 3706 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, |
3706 PretenureFlag pretenure = NOT_TENURED); | 3707 PretenureFlag pretenure = NOT_TENURED); |
3707 | 3708 |
3709 // Returns a new HashTable object. | |
3710 static Handle<Derived> New( | |
3711 Isolate* isolate, | |
3712 int at_least_space_for, | |
3713 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, | |
3714 PretenureFlag pretenure = NOT_TENURED); | |
3715 | |
3708 // Computes the required capacity for a table holding the given | 3716 // Computes the required capacity for a table holding the given |
3709 // number of elements. May be more than HashTable::kMaxCapacity. | 3717 // number of elements. May be more than HashTable::kMaxCapacity. |
3710 static int ComputeCapacity(int at_least_space_for); | 3718 static int ComputeCapacity(int at_least_space_for); |
3711 | 3719 |
3712 // Returns the key at entry. | 3720 // Returns the key at entry. |
3713 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3721 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
3714 | 3722 |
3715 // Tells whether k is a real key. The hole and undefined are not allowed | 3723 // Tells whether k is a real key. The hole and undefined are not allowed |
3716 // as keys and can be used to indicate missing or deleted elements. | 3724 // as keys and can be used to indicate missing or deleted elements. |
3717 bool IsKey(Object* k) { | 3725 bool IsKey(Object* k) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3807 } | 3815 } |
3808 | 3816 |
3809 // Returns _expected_ if one of entries given by the first _probe_ probes is | 3817 // Returns _expected_ if one of entries given by the first _probe_ probes is |
3810 // equal to _expected_. Otherwise, returns the entry given by the probe | 3818 // equal to _expected_. Otherwise, returns the entry given by the probe |
3811 // number _probe_. | 3819 // number _probe_. |
3812 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); | 3820 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); |
3813 | 3821 |
3814 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); | 3822 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); |
3815 | 3823 |
3816 // Rehashes this hash-table into the new table. | 3824 // Rehashes this hash-table into the new table. |
3817 MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); | 3825 void Rehash(Derived* new_table, Key key); |
3818 | 3826 |
3819 // Attempt to shrink hash table after removal of key. | 3827 // Attempt to shrink hash table after removal of key. |
3820 MUST_USE_RESULT MaybeObject* Shrink(Key key); | 3828 static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
3821 | 3829 |
3822 // Ensure enough space for n additional elements. | 3830 // Ensure enough space for n additional elements. |
3823 MUST_USE_RESULT MaybeObject* EnsureCapacity( | 3831 MUST_USE_RESULT MaybeObject* EnsureCapacity( |
3824 int n, | 3832 int n, |
3825 Key key, | 3833 Key key, |
3826 PretenureFlag pretenure = NOT_TENURED); | 3834 PretenureFlag pretenure = NOT_TENURED); |
3827 }; | 3835 }; |
3828 | 3836 |
3829 | 3837 |
3830 // HashTableKey is an abstract superclass for virtual key behavior. | 3838 // HashTableKey is an abstract superclass for virtual key behavior. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3863 static const int kPrefixSize = 0; | 3871 static const int kPrefixSize = 0; |
3864 static const int kEntrySize = 1; | 3872 static const int kEntrySize = 1; |
3865 }; | 3873 }; |
3866 | 3874 |
3867 class SeqOneByteString; | 3875 class SeqOneByteString; |
3868 | 3876 |
3869 // StringTable. | 3877 // StringTable. |
3870 // | 3878 // |
3871 // No special elements in the prefix and the element size is 1 | 3879 // No special elements in the prefix and the element size is 1 |
3872 // because only the string itself (the key) needs to be stored. | 3880 // because only the string itself (the key) needs to be stored. |
3873 class StringTable: public HashTable<StringTableShape, HashTableKey*> { | 3881 class StringTable: public HashTable<StringTable, |
3882 StringTableShape, | |
3883 HashTableKey*> { | |
3874 public: | 3884 public: |
3875 // Find string in the string table. If it is not there yet, it is | 3885 // Find string in the string table. If it is not there yet, it is |
3876 // added. The return value is the string table which might have | 3886 // added. The return value is the string table which might have |
3877 // been enlarged. If the return value is not a failure, the string | 3887 // been enlarged. If the return value is not a failure, the string |
3878 // pointer *s is set to the string found. | 3888 // pointer *s is set to the string found. |
3879 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); | 3889 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
3880 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); | 3890 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
3881 | 3891 |
3882 // Looks up a string that is equal to the given string and returns | 3892 // Looks up a string that is equal to the given string and returns |
3883 // true if it is found, assigning the string to the given output | 3893 // true if it is found, assigning the string to the given output |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3915 | 3925 |
3916 static const int kPrefixSize = 0; | 3926 static const int kPrefixSize = 0; |
3917 static const int kEntrySize = 2; | 3927 static const int kEntrySize = 2; |
3918 }; | 3928 }; |
3919 | 3929 |
3920 | 3930 |
3921 // MapCache. | 3931 // MapCache. |
3922 // | 3932 // |
3923 // Maps keys that are a fixed array of unique names to a map. | 3933 // Maps keys that are a fixed array of unique names to a map. |
3924 // Used for canonicalize maps for object literals. | 3934 // Used for canonicalize maps for object literals. |
3925 class MapCache: public HashTable<MapCacheShape, HashTableKey*> { | 3935 class MapCache: public HashTable<MapCache, MapCacheShape, HashTableKey*> { |
3926 public: | 3936 public: |
3927 // Find cached value for a name key, otherwise return null. | 3937 // Find cached value for a name key, otherwise return null. |
3928 Object* Lookup(FixedArray* key); | 3938 Object* Lookup(FixedArray* key); |
3929 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); | 3939 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
3930 static inline MapCache* cast(Object* obj); | 3940 static inline MapCache* cast(Object* obj); |
3931 | 3941 |
3932 private: | 3942 private: |
3933 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); | 3943 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
3934 }; | 3944 }; |
3935 | 3945 |
3936 | 3946 |
3937 template <typename Shape, typename Key> | 3947 template <typename Derived, typename Shape, typename Key> |
3938 class Dictionary: public HashTable<Shape, Key> { | 3948 class Dictionary: public HashTable<Derived, Shape, Key> { |
3949 protected: | |
3950 typedef HashTable<Derived, Shape, Key> HashTable_; | |
Yang
2014/04/11 14:12:22
Probably less confusing if you call this something
Igor Sheludko
2014/04/11 17:44:40
Good point! Done.
| |
3951 | |
3939 public: | 3952 public: |
3940 static inline Dictionary<Shape, Key>* cast(Object* obj) { | 3953 static inline Dictionary* cast(Object* obj) { |
3941 return reinterpret_cast<Dictionary<Shape, Key>*>(obj); | 3954 return reinterpret_cast<Dictionary*>(obj); |
3942 } | 3955 } |
3943 | 3956 |
3944 // Returns the value at entry. | 3957 // Returns the value at entry. |
3945 Object* ValueAt(int entry) { | 3958 Object* ValueAt(int entry) { |
3946 return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1); | 3959 return this->get(HashTable_::EntryToIndex(entry) + 1); |
3947 } | 3960 } |
3948 | 3961 |
3949 // Set the value for entry. | 3962 // Set the value for entry. |
3950 void ValueAtPut(int entry, Object* value) { | 3963 void ValueAtPut(int entry, Object* value) { |
3951 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); | 3964 this->set(HashTable_::EntryToIndex(entry) + 1, value); |
3952 } | 3965 } |
3953 | 3966 |
3954 // Returns the property details for the property at entry. | 3967 // Returns the property details for the property at entry. |
3955 PropertyDetails DetailsAt(int entry) { | 3968 PropertyDetails DetailsAt(int entry) { |
3956 ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). | 3969 ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
3957 return PropertyDetails( | 3970 return PropertyDetails( |
3958 Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); | 3971 Smi::cast(this->get(HashTable_::EntryToIndex(entry) + 2))); |
3959 } | 3972 } |
3960 | 3973 |
3961 // Set the details for entry. | 3974 // Set the details for entry. |
3962 void DetailsAtPut(int entry, PropertyDetails value) { | 3975 void DetailsAtPut(int entry, PropertyDetails value) { |
3963 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); | 3976 this->set(HashTable_::EntryToIndex(entry) + 2, value.AsSmi()); |
3964 } | 3977 } |
3965 | 3978 |
3966 // Sorting support | 3979 // Sorting support |
3967 void CopyValuesTo(FixedArray* elements); | 3980 void CopyValuesTo(FixedArray* elements); |
3968 | 3981 |
3969 // Delete a property from the dictionary. | 3982 // Delete a property from the dictionary. |
3970 Object* DeleteProperty(int entry, JSObject::DeleteMode mode); | 3983 Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
3971 // TODO(ishell): Temporary wrapper until handlified. | 3984 // TODO(ishell): Temporary wrapper until handlified. |
3972 static Handle<Object> DeleteProperty( | 3985 static Handle<Object> DeleteProperty( |
3973 Handle<Dictionary<Shape, Key> > dictionary, | 3986 Handle<Dictionary> dictionary, |
3974 int entry, | 3987 int entry, |
3975 JSObject::DeleteMode mode); | 3988 JSObject::DeleteMode mode); |
3976 | 3989 |
3977 // Attempt to shrink the dictionary after deletion of key. | 3990 // Attempt to shrink the dictionary after deletion of key. |
3978 MUST_USE_RESULT MaybeObject* Shrink(Key key); | 3991 static inline Handle<Derived> Shrink(Handle<Derived> dictionary, Key key) { |
3979 // TODO(ishell): Temporary wrapper until handlified. | 3992 return HashTable_::Shrink(dictionary, key); |
3980 MUST_USE_RESULT static Handle<FixedArray> Shrink( | 3993 } |
3981 Handle<Dictionary<Shape, Key> > dictionary, | |
3982 Key key); | |
3983 | 3994 |
3984 // Returns the number of elements in the dictionary filtering out properties | 3995 // Returns the number of elements in the dictionary filtering out properties |
3985 // with the specified attributes. | 3996 // with the specified attributes. |
3986 int NumberOfElementsFilterAttributes(PropertyAttributes filter); | 3997 int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
3987 | 3998 |
3988 // Returns the number of enumerable elements in the dictionary. | 3999 // Returns the number of enumerable elements in the dictionary. |
3989 int NumberOfEnumElements(); | 4000 int NumberOfEnumElements(); |
3990 | 4001 |
3991 enum SortMode { UNSORTED, SORTED }; | 4002 enum SortMode { UNSORTED, SORTED }; |
3992 // Copies keys to preallocated fixed array. | 4003 // Copies keys to preallocated fixed array. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4042 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); | 4053 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
4043 | 4054 |
4044 // Add entry to dictionary. | 4055 // Add entry to dictionary. |
4045 MUST_USE_RESULT MaybeObject* AddEntry(Key key, | 4056 MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
4046 Object* value, | 4057 Object* value, |
4047 PropertyDetails details, | 4058 PropertyDetails details, |
4048 uint32_t hash); | 4059 uint32_t hash); |
4049 | 4060 |
4050 // Generate new enumeration indices to avoid enumeration index overflow. | 4061 // Generate new enumeration indices to avoid enumeration index overflow. |
4051 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); | 4062 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
4052 static const int kMaxNumberKeyIndex = | 4063 static const int kMaxNumberKeyIndex = HashTable_::kPrefixStartIndex; |
4053 HashTable<Shape, Key>::kPrefixStartIndex; | |
4054 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; | 4064 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
4055 }; | 4065 }; |
4056 | 4066 |
4057 | 4067 |
4058 class NameDictionaryShape : public BaseShape<Name*> { | 4068 class NameDictionaryShape : public BaseShape<Name*> { |
4059 public: | 4069 public: |
4060 static inline bool IsMatch(Name* key, Object* other); | 4070 static inline bool IsMatch(Name* key, Object* other); |
4061 static inline uint32_t Hash(Name* key); | 4071 static inline uint32_t Hash(Name* key); |
4062 static inline uint32_t HashForObject(Name* key, Object* object); | 4072 static inline uint32_t HashForObject(Name* key, Object* object); |
4063 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4073 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4064 Name* key); | 4074 Name* key); |
4065 static const int kPrefixSize = 2; | 4075 static const int kPrefixSize = 2; |
4066 static const int kEntrySize = 3; | 4076 static const int kEntrySize = 3; |
4067 static const bool kIsEnumerable = true; | 4077 static const bool kIsEnumerable = true; |
4068 }; | 4078 }; |
4069 | 4079 |
4070 | 4080 |
4071 class NameDictionary: public Dictionary<NameDictionaryShape, Name*> { | 4081 class NameDictionary: public Dictionary<NameDictionary, |
4082 NameDictionaryShape, | |
4083 Name*> { | |
4072 public: | 4084 public: |
4073 static inline NameDictionary* cast(Object* obj) { | 4085 static inline NameDictionary* cast(Object* obj) { |
4074 ASSERT(obj->IsDictionary()); | 4086 ASSERT(obj->IsDictionary()); |
4075 return reinterpret_cast<NameDictionary*>(obj); | 4087 return reinterpret_cast<NameDictionary*>(obj); |
4076 } | 4088 } |
4077 | 4089 |
4078 // Copies enumerable keys to preallocated fixed array. | 4090 // Copies enumerable keys to preallocated fixed array. |
4079 void CopyEnumKeysTo(FixedArray* storage); | 4091 void CopyEnumKeysTo(FixedArray* storage); |
4080 static void DoGenerateNewEnumerationIndices( | 4092 static void DoGenerateNewEnumerationIndices( |
4081 Handle<NameDictionary> dictionary); | 4093 Handle<NameDictionary> dictionary); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4116 class UnseededNumberDictionaryShape : public NumberDictionaryShape { | 4128 class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
4117 public: | 4129 public: |
4118 static const int kPrefixSize = 0; | 4130 static const int kPrefixSize = 0; |
4119 | 4131 |
4120 static inline uint32_t Hash(uint32_t key); | 4132 static inline uint32_t Hash(uint32_t key); |
4121 static inline uint32_t HashForObject(uint32_t key, Object* object); | 4133 static inline uint32_t HashForObject(uint32_t key, Object* object); |
4122 }; | 4134 }; |
4123 | 4135 |
4124 | 4136 |
4125 class SeededNumberDictionary | 4137 class SeededNumberDictionary |
4126 : public Dictionary<SeededNumberDictionaryShape, uint32_t> { | 4138 : public Dictionary<SeededNumberDictionary, |
4139 SeededNumberDictionaryShape, | |
4140 uint32_t> { | |
4127 public: | 4141 public: |
4128 static SeededNumberDictionary* cast(Object* obj) { | 4142 static SeededNumberDictionary* cast(Object* obj) { |
4129 ASSERT(obj->IsDictionary()); | 4143 ASSERT(obj->IsDictionary()); |
4130 return reinterpret_cast<SeededNumberDictionary*>(obj); | 4144 return reinterpret_cast<SeededNumberDictionary*>(obj); |
4131 } | 4145 } |
4132 | 4146 |
4133 // Type specific at put (default NONE attributes is used when adding). | 4147 // Type specific at put (default NONE attributes is used when adding). |
4134 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); | 4148 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
4135 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( | 4149 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( |
4136 Handle<SeededNumberDictionary> dictionary, | 4150 Handle<SeededNumberDictionary> dictionary, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4169 inline uint32_t max_number_key(); | 4183 inline uint32_t max_number_key(); |
4170 | 4184 |
4171 // Bit masks. | 4185 // Bit masks. |
4172 static const int kRequiresSlowElementsMask = 1; | 4186 static const int kRequiresSlowElementsMask = 1; |
4173 static const int kRequiresSlowElementsTagSize = 1; | 4187 static const int kRequiresSlowElementsTagSize = 1; |
4174 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; | 4188 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
4175 }; | 4189 }; |
4176 | 4190 |
4177 | 4191 |
4178 class UnseededNumberDictionary | 4192 class UnseededNumberDictionary |
4179 : public Dictionary<UnseededNumberDictionaryShape, uint32_t> { | 4193 : public Dictionary<UnseededNumberDictionary, |
4194 UnseededNumberDictionaryShape, | |
4195 uint32_t> { | |
4180 public: | 4196 public: |
4181 static UnseededNumberDictionary* cast(Object* obj) { | 4197 static UnseededNumberDictionary* cast(Object* obj) { |
4182 ASSERT(obj->IsDictionary()); | 4198 ASSERT(obj->IsDictionary()); |
4183 return reinterpret_cast<UnseededNumberDictionary*>(obj); | 4199 return reinterpret_cast<UnseededNumberDictionary*>(obj); |
4184 } | 4200 } |
4185 | 4201 |
4186 // Type specific at put (default NONE attributes is used when adding). | 4202 // Type specific at put (default NONE attributes is used when adding). |
4187 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); | 4203 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
4188 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); | 4204 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); |
4189 | 4205 |
(...skipping 15 matching lines...) Expand all Loading... | |
4205 static inline uint32_t HashForObject(Object* key, Object* object); | 4221 static inline uint32_t HashForObject(Object* key, Object* object); |
4206 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4222 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4207 Object* key); | 4223 Object* key); |
4208 static const int kPrefixSize = 0; | 4224 static const int kPrefixSize = 0; |
4209 static const int kEntrySize = 2; | 4225 static const int kEntrySize = 2; |
4210 }; | 4226 }; |
4211 | 4227 |
4212 | 4228 |
4213 // ObjectHashTable maps keys that are arbitrary objects to object values by | 4229 // ObjectHashTable maps keys that are arbitrary objects to object values by |
4214 // using the identity hash of the key for hashing purposes. | 4230 // using the identity hash of the key for hashing purposes. |
4215 class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> { | 4231 class ObjectHashTable: public HashTable<ObjectHashTable, |
4232 ObjectHashTableShape, | |
4233 Object*> { | |
4234 typedef HashTable<ObjectHashTable, ObjectHashTableShape, Object*> HashTable_; | |
4216 public: | 4235 public: |
4217 static inline ObjectHashTable* cast(Object* obj) { | 4236 static inline ObjectHashTable* cast(Object* obj) { |
4218 ASSERT(obj->IsHashTable()); | 4237 ASSERT(obj->IsHashTable()); |
4219 return reinterpret_cast<ObjectHashTable*>(obj); | 4238 return reinterpret_cast<ObjectHashTable*>(obj); |
4220 } | 4239 } |
4221 | 4240 |
4222 static Handle<ObjectHashTable> EnsureCapacity( | 4241 static Handle<ObjectHashTable> EnsureCapacity( |
4223 Handle<ObjectHashTable> table, | 4242 Handle<ObjectHashTable> table, |
4224 int n, | 4243 int n, |
4225 Handle<Object> key, | 4244 Handle<Object> key, |
4226 PretenureFlag pretenure = NOT_TENURED); | 4245 PretenureFlag pretenure = NOT_TENURED); |
4227 | 4246 |
4228 // Attempt to shrink hash table after removal of key. | 4247 // Attempt to shrink hash table after removal of key. |
4229 static Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table, | 4248 static inline Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table, |
4230 Handle<Object> key); | 4249 Handle<Object> key); |
4231 | 4250 |
4232 // Looks up the value associated with the given key. The hole value is | 4251 // Looks up the value associated with the given key. The hole value is |
4233 // returned in case the key is not present. | 4252 // returned in case the key is not present. |
4234 Object* Lookup(Object* key); | 4253 Object* Lookup(Object* key); |
4235 | 4254 |
4236 // Adds (or overwrites) the value associated with the given key. Mapping a | 4255 // Adds (or overwrites) the value associated with the given key. Mapping a |
4237 // key to the hole value causes removal of the whole entry. | 4256 // key to the hole value causes removal of the whole entry. |
4238 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, | 4257 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
4239 Handle<Object> key, | 4258 Handle<Object> key, |
4240 Handle<Object> value); | 4259 Handle<Object> value); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4418 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4437 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4419 Object* key); | 4438 Object* key); |
4420 static const int kPrefixSize = 0; | 4439 static const int kPrefixSize = 0; |
4421 static const int kEntrySize = entrysize; | 4440 static const int kEntrySize = entrysize; |
4422 }; | 4441 }; |
4423 | 4442 |
4424 | 4443 |
4425 // WeakHashTable maps keys that are arbitrary objects to object values. | 4444 // WeakHashTable maps keys that are arbitrary objects to object values. |
4426 // It is used for the global weak hash table that maps objects | 4445 // It is used for the global weak hash table that maps objects |
4427 // embedded in optimized code to dependent code lists. | 4446 // embedded in optimized code to dependent code lists. |
4428 class WeakHashTable: public HashTable<WeakHashTableShape<2>, Object*> { | 4447 class WeakHashTable: public HashTable<WeakHashTable, |
4448 WeakHashTableShape<2>, | |
4449 Object*> { | |
4429 public: | 4450 public: |
4430 static inline WeakHashTable* cast(Object* obj) { | 4451 static inline WeakHashTable* cast(Object* obj) { |
4431 ASSERT(obj->IsHashTable()); | 4452 ASSERT(obj->IsHashTable()); |
4432 return reinterpret_cast<WeakHashTable*>(obj); | 4453 return reinterpret_cast<WeakHashTable*>(obj); |
4433 } | 4454 } |
4434 | 4455 |
4435 // Looks up the value associated with the given key. The hole value is | 4456 // Looks up the value associated with the given key. The hole value is |
4436 // returned in case the key is not present. | 4457 // returned in case the key is not present. |
4437 Object* Lookup(Object* key); | 4458 Object* Lookup(Object* key); |
4438 | 4459 |
(...skipping 3754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8193 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, | 8214 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, |
8194 HashTableKey* key) { | 8215 HashTableKey* key) { |
8195 return key->AsObject(heap); | 8216 return key->AsObject(heap); |
8196 } | 8217 } |
8197 | 8218 |
8198 static const int kPrefixSize = 0; | 8219 static const int kPrefixSize = 0; |
8199 static const int kEntrySize = 2; | 8220 static const int kEntrySize = 2; |
8200 }; | 8221 }; |
8201 | 8222 |
8202 | 8223 |
8203 class CompilationCacheTable: public HashTable<CompilationCacheShape, | 8224 class CompilationCacheTable: public HashTable<CompilationCacheTable, |
8225 CompilationCacheShape, | |
8204 HashTableKey*> { | 8226 HashTableKey*> { |
8205 public: | 8227 public: |
8206 // Find cached value for a string key, otherwise return null. | 8228 // Find cached value for a string key, otherwise return null. |
8207 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); | 8229 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); |
8208 Handle<Object> LookupEval(Handle<String> src, Handle<Context> context, | 8230 Handle<Object> LookupEval(Handle<String> src, Handle<Context> context, |
8209 StrictMode strict_mode, int scope_position); | 8231 StrictMode strict_mode, int scope_position); |
8210 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); | 8232 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
8211 static Handle<CompilationCacheTable> Put( | 8233 static Handle<CompilationCacheTable> Put( |
8212 Handle<CompilationCacheTable> cache, Handle<String> src, | 8234 Handle<CompilationCacheTable> cache, Handle<String> src, |
8213 Handle<Context> context, Handle<Object> value); | 8235 Handle<Context> context, Handle<Object> value); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8294 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, | 8316 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, |
8295 HashTableKey* key) { | 8317 HashTableKey* key) { |
8296 return key->AsObject(heap); | 8318 return key->AsObject(heap); |
8297 } | 8319 } |
8298 | 8320 |
8299 static const int kPrefixSize = 0; | 8321 static const int kPrefixSize = 0; |
8300 static const int kEntrySize = 2; | 8322 static const int kEntrySize = 2; |
8301 }; | 8323 }; |
8302 | 8324 |
8303 | 8325 |
8304 class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, | 8326 class CodeCacheHashTable: public HashTable<CodeCacheHashTable, |
8327 CodeCacheHashTableShape, | |
8305 HashTableKey*> { | 8328 HashTableKey*> { |
8306 public: | 8329 public: |
8307 Object* Lookup(Name* name, Code::Flags flags); | 8330 Object* Lookup(Name* name, Code::Flags flags); |
8308 MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code); | 8331 MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code); |
8309 | 8332 |
8310 int GetIndex(Name* name, Code::Flags flags); | 8333 int GetIndex(Name* name, Code::Flags flags); |
8311 void RemoveByIndex(int index); | 8334 void RemoveByIndex(int index); |
8312 | 8335 |
8313 static inline CodeCacheHashTable* cast(Object* obj); | 8336 static inline CodeCacheHashTable* cast(Object* obj); |
8314 | 8337 |
(...skipping 29 matching lines...) Expand all Loading... | |
8344 | 8367 |
8345 static const int kCacheOffset = HeapObject::kHeaderSize; | 8368 static const int kCacheOffset = HeapObject::kHeaderSize; |
8346 static const int kSize = kCacheOffset + kPointerSize; | 8369 static const int kSize = kCacheOffset + kPointerSize; |
8347 | 8370 |
8348 private: | 8371 private: |
8349 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); | 8372 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
8350 }; | 8373 }; |
8351 | 8374 |
8352 | 8375 |
8353 class PolymorphicCodeCacheHashTable | 8376 class PolymorphicCodeCacheHashTable |
8354 : public HashTable<CodeCacheHashTableShape, HashTableKey*> { | 8377 : public HashTable<PolymorphicCodeCacheHashTable, |
8378 CodeCacheHashTableShape, | |
8379 HashTableKey*> { | |
8355 public: | 8380 public: |
8356 Object* Lookup(MapHandleList* maps, int code_kind); | 8381 Object* Lookup(MapHandleList* maps, int code_kind); |
8357 | 8382 |
8358 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, | 8383 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, |
8359 int code_kind, | 8384 int code_kind, |
8360 Code* code); | 8385 Code* code); |
8361 | 8386 |
8362 static inline PolymorphicCodeCacheHashTable* cast(Object* obj); | 8387 static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
8363 | 8388 |
8364 static const int kInitialSize = 64; | 8389 static const int kInitialSize = 64; |
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11024 } else { | 11049 } else { |
11025 value &= ~(1 << bit_position); | 11050 value &= ~(1 << bit_position); |
11026 } | 11051 } |
11027 return value; | 11052 return value; |
11028 } | 11053 } |
11029 }; | 11054 }; |
11030 | 11055 |
11031 } } // namespace v8::internal | 11056 } } // namespace v8::internal |
11032 | 11057 |
11033 #endif // V8_OBJECTS_H_ | 11058 #endif // V8_OBJECTS_H_ |
OLD | NEW |