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 3638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3649 ASSERT(UsesSeed); | 3649 ASSERT(UsesSeed); |
3650 return Hash(key); | 3650 return Hash(key); |
3651 } | 3651 } |
3652 static uint32_t HashForObject(Key key, Object* object) { return 0; } | 3652 static uint32_t HashForObject(Key key, Object* object) { return 0; } |
3653 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { | 3653 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
3654 ASSERT(UsesSeed); | 3654 ASSERT(UsesSeed); |
3655 return HashForObject(key, object); | 3655 return HashForObject(key, object); |
3656 } | 3656 } |
3657 }; | 3657 }; |
3658 | 3658 |
3659 template<typename Derived, typename Shape, typename Key> | 3659 template<typename Shape, typename Key> |
3660 class HashTable: public FixedArray { | 3660 class HashTable: public FixedArray { |
3661 public: | 3661 public: |
3662 // Wrapper methods | 3662 // Wrapper methods |
3663 inline uint32_t Hash(Key key) { | 3663 inline uint32_t Hash(Key key) { |
3664 if (Shape::UsesSeed) { | 3664 if (Shape::UsesSeed) { |
3665 return Shape::SeededHash(key, | 3665 return Shape::SeededHash(key, |
3666 GetHeap()->HashSeed()); | 3666 GetHeap()->HashSeed()); |
3667 } else { | 3667 } else { |
3668 return Shape::Hash(key); | 3668 return Shape::Hash(key); |
3669 } | 3669 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3702 void ElementRemoved() { | 3702 void ElementRemoved() { |
3703 SetNumberOfElements(NumberOfElements() - 1); | 3703 SetNumberOfElements(NumberOfElements() - 1); |
3704 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); | 3704 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
3705 } | 3705 } |
3706 void ElementsRemoved(int n) { | 3706 void ElementsRemoved(int n) { |
3707 SetNumberOfElements(NumberOfElements() - n); | 3707 SetNumberOfElements(NumberOfElements() - n); |
3708 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); | 3708 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
3709 } | 3709 } |
3710 | 3710 |
3711 // Returns a new HashTable object. Might return Failure. | 3711 // Returns a new HashTable object. Might return Failure. |
3712 // TODO(ishell): this will be eventually replaced by New(). | |
3713 MUST_USE_RESULT static MaybeObject* Allocate( | 3712 MUST_USE_RESULT static MaybeObject* Allocate( |
3714 Heap* heap, | 3713 Heap* heap, |
3715 int at_least_space_for, | 3714 int at_least_space_for, |
3716 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, | 3715 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, |
3717 PretenureFlag pretenure = NOT_TENURED); | 3716 PretenureFlag pretenure = NOT_TENURED); |
3718 | 3717 |
3719 // Returns a new HashTable object. | |
3720 static Handle<Derived> New( | |
3721 Isolate* isolate, | |
3722 int at_least_space_for, | |
3723 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, | |
3724 PretenureFlag pretenure = NOT_TENURED); | |
3725 | |
3726 // Computes the required capacity for a table holding the given | 3718 // Computes the required capacity for a table holding the given |
3727 // number of elements. May be more than HashTable::kMaxCapacity. | 3719 // number of elements. May be more than HashTable::kMaxCapacity. |
3728 static int ComputeCapacity(int at_least_space_for); | 3720 static int ComputeCapacity(int at_least_space_for); |
3729 | 3721 |
3730 // Returns the key at entry. | 3722 // Returns the key at entry. |
3731 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3723 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
3732 | 3724 |
3733 // Tells whether k is a real key. The hole and undefined are not allowed | 3725 // Tells whether k is a real key. The hole and undefined are not allowed |
3734 // as keys and can be used to indicate missing or deleted elements. | 3726 // as keys and can be used to indicate missing or deleted elements. |
3735 bool IsKey(Object* k) { | 3727 bool IsKey(Object* k) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3825 } | 3817 } |
3826 | 3818 |
3827 // Returns _expected_ if one of entries given by the first _probe_ probes is | 3819 // Returns _expected_ if one of entries given by the first _probe_ probes is |
3828 // equal to _expected_. Otherwise, returns the entry given by the probe | 3820 // equal to _expected_. Otherwise, returns the entry given by the probe |
3829 // number _probe_. | 3821 // number _probe_. |
3830 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); | 3822 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); |
3831 | 3823 |
3832 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); | 3824 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); |
3833 | 3825 |
3834 // Rehashes this hash-table into the new table. | 3826 // Rehashes this hash-table into the new table. |
3835 void Rehash(Derived* new_table, Key key); | 3827 MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
3836 | 3828 |
3837 // Attempt to shrink hash table after removal of key. | 3829 // Attempt to shrink hash table after removal of key. |
3838 static Handle<Derived> Shrink(Handle<Derived> table, Key key); | 3830 MUST_USE_RESULT MaybeObject* Shrink(Key key); |
3839 | 3831 |
3840 // Ensure enough space for n additional elements. | 3832 // Ensure enough space for n additional elements. |
3841 MUST_USE_RESULT MaybeObject* EnsureCapacity( | 3833 MUST_USE_RESULT MaybeObject* EnsureCapacity( |
3842 int n, | 3834 int n, |
3843 Key key, | 3835 Key key, |
3844 PretenureFlag pretenure = NOT_TENURED); | 3836 PretenureFlag pretenure = NOT_TENURED); |
3845 }; | 3837 }; |
3846 | 3838 |
3847 | 3839 |
3848 // HashTableKey is an abstract superclass for virtual key behavior. | 3840 // HashTableKey is an abstract superclass for virtual key behavior. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3881 static const int kPrefixSize = 0; | 3873 static const int kPrefixSize = 0; |
3882 static const int kEntrySize = 1; | 3874 static const int kEntrySize = 1; |
3883 }; | 3875 }; |
3884 | 3876 |
3885 class SeqOneByteString; | 3877 class SeqOneByteString; |
3886 | 3878 |
3887 // StringTable. | 3879 // StringTable. |
3888 // | 3880 // |
3889 // No special elements in the prefix and the element size is 1 | 3881 // No special elements in the prefix and the element size is 1 |
3890 // because only the string itself (the key) needs to be stored. | 3882 // because only the string itself (the key) needs to be stored. |
3891 class StringTable: public HashTable<StringTable, | 3883 class StringTable: public HashTable<StringTableShape, HashTableKey*> { |
3892 StringTableShape, | |
3893 HashTableKey*> { | |
3894 public: | 3884 public: |
3895 // 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 |
3896 // added. The return value is the string table which might have | 3886 // added. The return value is the string table which might have |
3897 // 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 |
3898 // pointer *s is set to the string found. | 3888 // pointer *s is set to the string found. |
3899 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); | 3889 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
3900 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); | 3890 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
3901 | 3891 |
3902 // 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 |
3903 // 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... |
3935 | 3925 |
3936 static const int kPrefixSize = 0; | 3926 static const int kPrefixSize = 0; |
3937 static const int kEntrySize = 2; | 3927 static const int kEntrySize = 2; |
3938 }; | 3928 }; |
3939 | 3929 |
3940 | 3930 |
3941 // MapCache. | 3931 // MapCache. |
3942 // | 3932 // |
3943 // 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. |
3944 // Used for canonicalize maps for object literals. | 3934 // Used for canonicalize maps for object literals. |
3945 class MapCache: public HashTable<MapCache, MapCacheShape, HashTableKey*> { | 3935 class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
3946 public: | 3936 public: |
3947 // Find cached value for a name key, otherwise return null. | 3937 // Find cached value for a name key, otherwise return null. |
3948 Object* Lookup(FixedArray* key); | 3938 Object* Lookup(FixedArray* key); |
3949 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); | 3939 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
3950 static inline MapCache* cast(Object* obj); | 3940 static inline MapCache* cast(Object* obj); |
3951 | 3941 |
3952 private: | 3942 private: |
3953 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); | 3943 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
3954 }; | 3944 }; |
3955 | 3945 |
3956 | 3946 |
3957 template <typename Derived, typename Shape, typename Key> | 3947 template <typename Shape, typename Key> |
3958 class Dictionary: public HashTable<Derived, Shape, Key> { | 3948 class Dictionary: public HashTable<Shape, Key> { |
3959 protected: | |
3960 typedef HashTable<Derived, Shape, Key> DerivedHashTable; | |
3961 | |
3962 public: | 3949 public: |
3963 static inline Dictionary* cast(Object* obj) { | 3950 static inline Dictionary<Shape, Key>* cast(Object* obj) { |
3964 return reinterpret_cast<Dictionary*>(obj); | 3951 return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
3965 } | 3952 } |
3966 | 3953 |
3967 // Returns the value at entry. | 3954 // Returns the value at entry. |
3968 Object* ValueAt(int entry) { | 3955 Object* ValueAt(int entry) { |
3969 return this->get(DerivedHashTable::EntryToIndex(entry) + 1); | 3956 return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1); |
3970 } | 3957 } |
3971 | 3958 |
3972 // Set the value for entry. | 3959 // Set the value for entry. |
3973 void ValueAtPut(int entry, Object* value) { | 3960 void ValueAtPut(int entry, Object* value) { |
3974 this->set(DerivedHashTable::EntryToIndex(entry) + 1, value); | 3961 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
3975 } | 3962 } |
3976 | 3963 |
3977 // Returns the property details for the property at entry. | 3964 // Returns the property details for the property at entry. |
3978 PropertyDetails DetailsAt(int entry) { | 3965 PropertyDetails DetailsAt(int entry) { |
3979 ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). | 3966 ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
3980 return PropertyDetails( | 3967 return PropertyDetails( |
3981 Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2))); | 3968 Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
3982 } | 3969 } |
3983 | 3970 |
3984 // Set the details for entry. | 3971 // Set the details for entry. |
3985 void DetailsAtPut(int entry, PropertyDetails value) { | 3972 void DetailsAtPut(int entry, PropertyDetails value) { |
3986 this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi()); | 3973 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
3987 } | 3974 } |
3988 | 3975 |
3989 // Sorting support | 3976 // Sorting support |
3990 void CopyValuesTo(FixedArray* elements); | 3977 void CopyValuesTo(FixedArray* elements); |
3991 | 3978 |
3992 // Delete a property from the dictionary. | 3979 // Delete a property from the dictionary. |
3993 Object* DeleteProperty(int entry, JSObject::DeleteMode mode); | 3980 Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
3994 // TODO(ishell): Temporary wrapper until handlified. | 3981 // TODO(ishell): Temporary wrapper until handlified. |
3995 static Handle<Object> DeleteProperty( | 3982 static Handle<Object> DeleteProperty( |
3996 Handle<Dictionary> dictionary, | 3983 Handle<Dictionary<Shape, Key> > dictionary, |
3997 int entry, | 3984 int entry, |
3998 JSObject::DeleteMode mode); | 3985 JSObject::DeleteMode mode); |
3999 | 3986 |
4000 // Attempt to shrink the dictionary after deletion of key. | 3987 // Attempt to shrink the dictionary after deletion of key. |
4001 static inline Handle<Derived> Shrink(Handle<Derived> dictionary, Key key) { | 3988 MUST_USE_RESULT MaybeObject* Shrink(Key key); |
4002 return DerivedHashTable::Shrink(dictionary, key); | 3989 // TODO(ishell): Temporary wrapper until handlified. |
4003 } | 3990 MUST_USE_RESULT static Handle<FixedArray> Shrink( |
| 3991 Handle<Dictionary<Shape, Key> > dictionary, |
| 3992 Key key); |
4004 | 3993 |
4005 // Returns the number of elements in the dictionary filtering out properties | 3994 // Returns the number of elements in the dictionary filtering out properties |
4006 // with the specified attributes. | 3995 // with the specified attributes. |
4007 int NumberOfElementsFilterAttributes(PropertyAttributes filter); | 3996 int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
4008 | 3997 |
4009 // Returns the number of enumerable elements in the dictionary. | 3998 // Returns the number of enumerable elements in the dictionary. |
4010 int NumberOfEnumElements(); | 3999 int NumberOfEnumElements(); |
4011 | 4000 |
4012 enum SortMode { UNSORTED, SORTED }; | 4001 enum SortMode { UNSORTED, SORTED }; |
4013 // Copies keys to preallocated fixed array. | 4002 // Copies keys to preallocated fixed array. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4063 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); | 4052 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
4064 | 4053 |
4065 // Add entry to dictionary. | 4054 // Add entry to dictionary. |
4066 MUST_USE_RESULT MaybeObject* AddEntry(Key key, | 4055 MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
4067 Object* value, | 4056 Object* value, |
4068 PropertyDetails details, | 4057 PropertyDetails details, |
4069 uint32_t hash); | 4058 uint32_t hash); |
4070 | 4059 |
4071 // Generate new enumeration indices to avoid enumeration index overflow. | 4060 // Generate new enumeration indices to avoid enumeration index overflow. |
4072 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); | 4061 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
4073 static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; | 4062 static const int kMaxNumberKeyIndex = |
| 4063 HashTable<Shape, Key>::kPrefixStartIndex; |
4074 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; | 4064 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
4075 }; | 4065 }; |
4076 | 4066 |
4077 | 4067 |
4078 class NameDictionaryShape : public BaseShape<Name*> { | 4068 class NameDictionaryShape : public BaseShape<Name*> { |
4079 public: | 4069 public: |
4080 static inline bool IsMatch(Name* key, Object* other); | 4070 static inline bool IsMatch(Name* key, Object* other); |
4081 static inline uint32_t Hash(Name* key); | 4071 static inline uint32_t Hash(Name* key); |
4082 static inline uint32_t HashForObject(Name* key, Object* object); | 4072 static inline uint32_t HashForObject(Name* key, Object* object); |
4083 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4073 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4084 Name* key); | 4074 Name* key); |
4085 static const int kPrefixSize = 2; | 4075 static const int kPrefixSize = 2; |
4086 static const int kEntrySize = 3; | 4076 static const int kEntrySize = 3; |
4087 static const bool kIsEnumerable = true; | 4077 static const bool kIsEnumerable = true; |
4088 }; | 4078 }; |
4089 | 4079 |
4090 | 4080 |
4091 class NameDictionary: public Dictionary<NameDictionary, | 4081 class NameDictionary: public Dictionary<NameDictionaryShape, Name*> { |
4092 NameDictionaryShape, | |
4093 Name*> { | |
4094 public: | 4082 public: |
4095 static inline NameDictionary* cast(Object* obj) { | 4083 static inline NameDictionary* cast(Object* obj) { |
4096 ASSERT(obj->IsDictionary()); | 4084 ASSERT(obj->IsDictionary()); |
4097 return reinterpret_cast<NameDictionary*>(obj); | 4085 return reinterpret_cast<NameDictionary*>(obj); |
4098 } | 4086 } |
4099 | 4087 |
4100 // Copies enumerable keys to preallocated fixed array. | 4088 // Copies enumerable keys to preallocated fixed array. |
4101 void CopyEnumKeysTo(FixedArray* storage); | 4089 void CopyEnumKeysTo(FixedArray* storage); |
4102 static void DoGenerateNewEnumerationIndices( | 4090 static void DoGenerateNewEnumerationIndices( |
4103 Handle<NameDictionary> dictionary); | 4091 Handle<NameDictionary> dictionary); |
(...skipping 29 matching lines...) Expand all Loading... |
4133 class UnseededNumberDictionaryShape : public NumberDictionaryShape { | 4121 class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
4134 public: | 4122 public: |
4135 static const int kPrefixSize = 0; | 4123 static const int kPrefixSize = 0; |
4136 | 4124 |
4137 static inline uint32_t Hash(uint32_t key); | 4125 static inline uint32_t Hash(uint32_t key); |
4138 static inline uint32_t HashForObject(uint32_t key, Object* object); | 4126 static inline uint32_t HashForObject(uint32_t key, Object* object); |
4139 }; | 4127 }; |
4140 | 4128 |
4141 | 4129 |
4142 class SeededNumberDictionary | 4130 class SeededNumberDictionary |
4143 : public Dictionary<SeededNumberDictionary, | 4131 : public Dictionary<SeededNumberDictionaryShape, uint32_t> { |
4144 SeededNumberDictionaryShape, | |
4145 uint32_t> { | |
4146 public: | 4132 public: |
4147 static SeededNumberDictionary* cast(Object* obj) { | 4133 static SeededNumberDictionary* cast(Object* obj) { |
4148 ASSERT(obj->IsDictionary()); | 4134 ASSERT(obj->IsDictionary()); |
4149 return reinterpret_cast<SeededNumberDictionary*>(obj); | 4135 return reinterpret_cast<SeededNumberDictionary*>(obj); |
4150 } | 4136 } |
4151 | 4137 |
4152 // Type specific at put (default NONE attributes is used when adding). | 4138 // Type specific at put (default NONE attributes is used when adding). |
4153 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); | 4139 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
4154 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( | 4140 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( |
4155 Handle<SeededNumberDictionary> dictionary, | 4141 Handle<SeededNumberDictionary> dictionary, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4188 inline uint32_t max_number_key(); | 4174 inline uint32_t max_number_key(); |
4189 | 4175 |
4190 // Bit masks. | 4176 // Bit masks. |
4191 static const int kRequiresSlowElementsMask = 1; | 4177 static const int kRequiresSlowElementsMask = 1; |
4192 static const int kRequiresSlowElementsTagSize = 1; | 4178 static const int kRequiresSlowElementsTagSize = 1; |
4193 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; | 4179 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
4194 }; | 4180 }; |
4195 | 4181 |
4196 | 4182 |
4197 class UnseededNumberDictionary | 4183 class UnseededNumberDictionary |
4198 : public Dictionary<UnseededNumberDictionary, | 4184 : public Dictionary<UnseededNumberDictionaryShape, uint32_t> { |
4199 UnseededNumberDictionaryShape, | |
4200 uint32_t> { | |
4201 public: | 4185 public: |
4202 static UnseededNumberDictionary* cast(Object* obj) { | 4186 static UnseededNumberDictionary* cast(Object* obj) { |
4203 ASSERT(obj->IsDictionary()); | 4187 ASSERT(obj->IsDictionary()); |
4204 return reinterpret_cast<UnseededNumberDictionary*>(obj); | 4188 return reinterpret_cast<UnseededNumberDictionary*>(obj); |
4205 } | 4189 } |
4206 | 4190 |
4207 // Type specific at put (default NONE attributes is used when adding). | 4191 // Type specific at put (default NONE attributes is used when adding). |
4208 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); | 4192 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
4209 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); | 4193 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); |
4210 | 4194 |
(...skipping 15 matching lines...) Expand all Loading... |
4226 static inline uint32_t HashForObject(Object* key, Object* object); | 4210 static inline uint32_t HashForObject(Object* key, Object* object); |
4227 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4211 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4228 Object* key); | 4212 Object* key); |
4229 static const int kPrefixSize = 0; | 4213 static const int kPrefixSize = 0; |
4230 static const int kEntrySize = 2; | 4214 static const int kEntrySize = 2; |
4231 }; | 4215 }; |
4232 | 4216 |
4233 | 4217 |
4234 // ObjectHashTable maps keys that are arbitrary objects to object values by | 4218 // ObjectHashTable maps keys that are arbitrary objects to object values by |
4235 // using the identity hash of the key for hashing purposes. | 4219 // using the identity hash of the key for hashing purposes. |
4236 class ObjectHashTable: public HashTable<ObjectHashTable, | 4220 class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> { |
4237 ObjectHashTableShape, | |
4238 Object*> { | |
4239 typedef HashTable<ObjectHashTable, ObjectHashTableShape, Object*> HashTable_; | |
4240 public: | 4221 public: |
4241 static inline ObjectHashTable* cast(Object* obj) { | 4222 static inline ObjectHashTable* cast(Object* obj) { |
4242 ASSERT(obj->IsHashTable()); | 4223 ASSERT(obj->IsHashTable()); |
4243 return reinterpret_cast<ObjectHashTable*>(obj); | 4224 return reinterpret_cast<ObjectHashTable*>(obj); |
4244 } | 4225 } |
4245 | 4226 |
4246 static Handle<ObjectHashTable> EnsureCapacity( | 4227 static Handle<ObjectHashTable> EnsureCapacity( |
4247 Handle<ObjectHashTable> table, | 4228 Handle<ObjectHashTable> table, |
4248 int n, | 4229 int n, |
4249 Handle<Object> key, | 4230 Handle<Object> key, |
4250 PretenureFlag pretenure = NOT_TENURED); | 4231 PretenureFlag pretenure = NOT_TENURED); |
4251 | 4232 |
4252 // Attempt to shrink hash table after removal of key. | 4233 // Attempt to shrink hash table after removal of key. |
4253 static inline Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table, | 4234 static Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table, |
4254 Handle<Object> key); | 4235 Handle<Object> key); |
4255 | 4236 |
4256 // Looks up the value associated with the given key. The hole value is | 4237 // Looks up the value associated with the given key. The hole value is |
4257 // returned in case the key is not present. | 4238 // returned in case the key is not present. |
4258 Object* Lookup(Object* key); | 4239 Object* Lookup(Object* key); |
4259 | 4240 |
4260 // Adds (or overwrites) the value associated with the given key. Mapping a | 4241 // Adds (or overwrites) the value associated with the given key. Mapping a |
4261 // key to the hole value causes removal of the whole entry. | 4242 // key to the hole value causes removal of the whole entry. |
4262 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, | 4243 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
4263 Handle<Object> key, | 4244 Handle<Object> key, |
4264 Handle<Object> value); | 4245 Handle<Object> value); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4442 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4423 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4443 Object* key); | 4424 Object* key); |
4444 static const int kPrefixSize = 0; | 4425 static const int kPrefixSize = 0; |
4445 static const int kEntrySize = entrysize; | 4426 static const int kEntrySize = entrysize; |
4446 }; | 4427 }; |
4447 | 4428 |
4448 | 4429 |
4449 // WeakHashTable maps keys that are arbitrary objects to object values. | 4430 // WeakHashTable maps keys that are arbitrary objects to object values. |
4450 // It is used for the global weak hash table that maps objects | 4431 // It is used for the global weak hash table that maps objects |
4451 // embedded in optimized code to dependent code lists. | 4432 // embedded in optimized code to dependent code lists. |
4452 class WeakHashTable: public HashTable<WeakHashTable, | 4433 class WeakHashTable: public HashTable<WeakHashTableShape<2>, Object*> { |
4453 WeakHashTableShape<2>, | |
4454 Object*> { | |
4455 public: | 4434 public: |
4456 static inline WeakHashTable* cast(Object* obj) { | 4435 static inline WeakHashTable* cast(Object* obj) { |
4457 ASSERT(obj->IsHashTable()); | 4436 ASSERT(obj->IsHashTable()); |
4458 return reinterpret_cast<WeakHashTable*>(obj); | 4437 return reinterpret_cast<WeakHashTable*>(obj); |
4459 } | 4438 } |
4460 | 4439 |
4461 // Looks up the value associated with the given key. The hole value is | 4440 // Looks up the value associated with the given key. The hole value is |
4462 // returned in case the key is not present. | 4441 // returned in case the key is not present. |
4463 Object* Lookup(Object* key); | 4442 Object* Lookup(Object* key); |
4464 | 4443 |
(...skipping 3749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8214 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, | 8193 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, |
8215 HashTableKey* key) { | 8194 HashTableKey* key) { |
8216 return key->AsObject(heap); | 8195 return key->AsObject(heap); |
8217 } | 8196 } |
8218 | 8197 |
8219 static const int kPrefixSize = 0; | 8198 static const int kPrefixSize = 0; |
8220 static const int kEntrySize = 2; | 8199 static const int kEntrySize = 2; |
8221 }; | 8200 }; |
8222 | 8201 |
8223 | 8202 |
8224 class CompilationCacheTable: public HashTable<CompilationCacheTable, | 8203 class CompilationCacheTable: public HashTable<CompilationCacheShape, |
8225 CompilationCacheShape, | |
8226 HashTableKey*> { | 8204 HashTableKey*> { |
8227 public: | 8205 public: |
8228 // Find cached value for a string key, otherwise return null. | 8206 // Find cached value for a string key, otherwise return null. |
8229 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); | 8207 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); |
8230 Handle<Object> LookupEval(Handle<String> src, Handle<Context> context, | 8208 Handle<Object> LookupEval(Handle<String> src, Handle<Context> context, |
8231 StrictMode strict_mode, int scope_position); | 8209 StrictMode strict_mode, int scope_position); |
8232 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); | 8210 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
8233 static Handle<CompilationCacheTable> Put( | 8211 static Handle<CompilationCacheTable> Put( |
8234 Handle<CompilationCacheTable> cache, Handle<String> src, | 8212 Handle<CompilationCacheTable> cache, Handle<String> src, |
8235 Handle<Context> context, Handle<Object> value); | 8213 Handle<Context> context, Handle<Object> value); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8316 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, | 8294 MUST_USE_RESULT static MaybeObject* AsObject(Heap* heap, |
8317 HashTableKey* key) { | 8295 HashTableKey* key) { |
8318 return key->AsObject(heap); | 8296 return key->AsObject(heap); |
8319 } | 8297 } |
8320 | 8298 |
8321 static const int kPrefixSize = 0; | 8299 static const int kPrefixSize = 0; |
8322 static const int kEntrySize = 2; | 8300 static const int kEntrySize = 2; |
8323 }; | 8301 }; |
8324 | 8302 |
8325 | 8303 |
8326 class CodeCacheHashTable: public HashTable<CodeCacheHashTable, | 8304 class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
8327 CodeCacheHashTableShape, | |
8328 HashTableKey*> { | 8305 HashTableKey*> { |
8329 public: | 8306 public: |
8330 Object* Lookup(Name* name, Code::Flags flags); | 8307 Object* Lookup(Name* name, Code::Flags flags); |
8331 MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code); | 8308 MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code); |
8332 | 8309 |
8333 int GetIndex(Name* name, Code::Flags flags); | 8310 int GetIndex(Name* name, Code::Flags flags); |
8334 void RemoveByIndex(int index); | 8311 void RemoveByIndex(int index); |
8335 | 8312 |
8336 static inline CodeCacheHashTable* cast(Object* obj); | 8313 static inline CodeCacheHashTable* cast(Object* obj); |
8337 | 8314 |
(...skipping 29 matching lines...) Expand all Loading... |
8367 | 8344 |
8368 static const int kCacheOffset = HeapObject::kHeaderSize; | 8345 static const int kCacheOffset = HeapObject::kHeaderSize; |
8369 static const int kSize = kCacheOffset + kPointerSize; | 8346 static const int kSize = kCacheOffset + kPointerSize; |
8370 | 8347 |
8371 private: | 8348 private: |
8372 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); | 8349 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
8373 }; | 8350 }; |
8374 | 8351 |
8375 | 8352 |
8376 class PolymorphicCodeCacheHashTable | 8353 class PolymorphicCodeCacheHashTable |
8377 : public HashTable<PolymorphicCodeCacheHashTable, | 8354 : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
8378 CodeCacheHashTableShape, | |
8379 HashTableKey*> { | |
8380 public: | 8355 public: |
8381 Object* Lookup(MapHandleList* maps, int code_kind); | 8356 Object* Lookup(MapHandleList* maps, int code_kind); |
8382 | 8357 |
8383 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, | 8358 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, |
8384 int code_kind, | 8359 int code_kind, |
8385 Code* code); | 8360 Code* code); |
8386 | 8361 |
8387 static inline PolymorphicCodeCacheHashTable* cast(Object* obj); | 8362 static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
8388 | 8363 |
8389 static const int kInitialSize = 64; | 8364 static const int kInitialSize = 64; |
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11049 } else { | 11024 } else { |
11050 value &= ~(1 << bit_position); | 11025 value &= ~(1 << bit_position); |
11051 } | 11026 } |
11052 return value; | 11027 return value; |
11053 } | 11028 } |
11054 }; | 11029 }; |
11055 | 11030 |
11056 } } // namespace v8::internal | 11031 } } // namespace v8::internal |
11057 | 11032 |
11058 #endif // V8_OBJECTS_H_ | 11033 #endif // V8_OBJECTS_H_ |
OLD | NEW |