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