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

Side by Side Diff: src/objects.h

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

Powered by Google App Engine
This is Rietveld 408576698