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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 V(Primitive) \ | 1069 V(Primitive) \ |
1070 V(GlobalObject) \ | 1070 V(GlobalObject) \ |
1071 V(JSGlobalObject) \ | 1071 V(JSGlobalObject) \ |
1072 V(JSBuiltinsObject) \ | 1072 V(JSBuiltinsObject) \ |
1073 V(JSGlobalProxy) \ | 1073 V(JSGlobalProxy) \ |
1074 V(UndetectableObject) \ | 1074 V(UndetectableObject) \ |
1075 V(AccessCheckNeeded) \ | 1075 V(AccessCheckNeeded) \ |
1076 V(Cell) \ | 1076 V(Cell) \ |
1077 V(PropertyCell) \ | 1077 V(PropertyCell) \ |
1078 V(ObjectHashTable) \ | 1078 V(ObjectHashTable) \ |
1079 V(WeakHashTable) | 1079 V(WeakHashTable) \ |
1080 V(OrderedHashTable) \ | |
Michael Starzinger
2014/04/07 12:37:31
Since the OrderedHashTable is just the abstract su
adamk
2014/04/07 23:50:02
Okay, I switched back (only downside was that I ha
| |
1081 V(OrderedHashSet) \ | |
1082 V(OrderedHashMap) | |
1080 | 1083 |
1081 | 1084 |
1082 #define ERROR_MESSAGES_LIST(V) \ | 1085 #define ERROR_MESSAGES_LIST(V) \ |
1083 V(kNoReason, "no reason") \ | 1086 V(kNoReason, "no reason") \ |
1084 \ | 1087 \ |
1085 V(k32BitValueInRegisterIsNotZeroExtended, \ | 1088 V(k32BitValueInRegisterIsNotZeroExtended, \ |
1086 "32 bit value in register is not zero-extended") \ | 1089 "32 bit value in register is not zero-extended") \ |
1087 V(kAlignmentMarkerExpected, "Alignment marker expected") \ | 1090 V(kAlignmentMarkerExpected, "Alignment marker expected") \ |
1088 V(kAllocationIsNotDoubleAligned, "Allocation is not double aligned") \ | 1091 V(kAllocationIsNotDoubleAligned, "Allocation is not double aligned") \ |
1089 V(kAPICallReturnedInvalidObject, "API call returned invalid object") \ | 1092 V(kAPICallReturnedInvalidObject, "API call returned invalid object") \ |
(...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3744 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; | 3747 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
3745 | 3748 |
3746 // Find entry for key otherwise return kNotFound. | 3749 // Find entry for key otherwise return kNotFound. |
3747 inline int FindEntry(Key key); | 3750 inline int FindEntry(Key key); |
3748 int FindEntry(Isolate* isolate, Key key); | 3751 int FindEntry(Isolate* isolate, Key key); |
3749 | 3752 |
3750 // Rehashes the table in-place. | 3753 // Rehashes the table in-place. |
3751 void Rehash(Key key); | 3754 void Rehash(Key key); |
3752 | 3755 |
3753 protected: | 3756 protected: |
3754 friend class ObjectHashSet; | |
3755 friend class ObjectHashTable; | 3757 friend class ObjectHashTable; |
3756 | 3758 |
3757 // Find the entry at which to insert element with the given key that | 3759 // Find the entry at which to insert element with the given key that |
3758 // has the given hash value. | 3760 // has the given hash value. |
3759 uint32_t FindInsertionEntry(uint32_t hash); | 3761 uint32_t FindInsertionEntry(uint32_t hash); |
3760 | 3762 |
3761 // Returns the index for an entry (of the key) | 3763 // Returns the index for an entry (of the key) |
3762 static inline int EntryToIndex(int entry) { | 3764 static inline int EntryToIndex(int entry) { |
3763 return (entry * kEntrySize) + kElementsStartIndex; | 3765 return (entry * kEntrySize) + kElementsStartIndex; |
3764 } | 3766 } |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4175 // Return the updated dictionary. | 4177 // Return the updated dictionary. |
4176 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( | 4178 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
4177 Handle<UnseededNumberDictionary> dictionary, | 4179 Handle<UnseededNumberDictionary> dictionary, |
4178 uint32_t index, | 4180 uint32_t index, |
4179 Handle<Object> value); | 4181 Handle<Object> value); |
4180 | 4182 |
4181 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); | 4183 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); |
4182 }; | 4184 }; |
4183 | 4185 |
4184 | 4186 |
4185 template <int entrysize> | |
4186 class ObjectHashTableShape : public BaseShape<Object*> { | 4187 class ObjectHashTableShape : public BaseShape<Object*> { |
4187 public: | 4188 public: |
4188 static inline bool IsMatch(Object* key, Object* other); | 4189 static inline bool IsMatch(Object* key, Object* other); |
4189 static inline uint32_t Hash(Object* key); | 4190 static inline uint32_t Hash(Object* key); |
4190 static inline uint32_t HashForObject(Object* key, Object* object); | 4191 static inline uint32_t HashForObject(Object* key, Object* object); |
4191 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, | 4192 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, |
4192 Object* key); | 4193 Object* key); |
4193 static const int kPrefixSize = 0; | 4194 static const int kPrefixSize = 0; |
4194 static const int kEntrySize = entrysize; | 4195 static const int kEntrySize = 2; |
4195 }; | |
4196 | |
4197 | |
4198 // ObjectHashSet holds keys that are arbitrary objects by using the identity | |
4199 // hash of the key for hashing purposes. | |
4200 class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> { | |
4201 public: | |
4202 static inline ObjectHashSet* cast(Object* obj) { | |
4203 ASSERT(obj->IsHashTable()); | |
4204 return reinterpret_cast<ObjectHashSet*>(obj); | |
4205 } | |
4206 | |
4207 // Looks up whether the given key is part of this hash set. | |
4208 bool Contains(Object* key); | |
4209 | |
4210 static Handle<ObjectHashSet> EnsureCapacity( | |
4211 Handle<ObjectHashSet> table, | |
4212 int n, | |
4213 Handle<Object> key, | |
4214 PretenureFlag pretenure = NOT_TENURED); | |
4215 | |
4216 // Attempt to shrink hash table after removal of key. | |
4217 static Handle<ObjectHashSet> Shrink(Handle<ObjectHashSet> table, | |
4218 Handle<Object> key); | |
4219 | |
4220 // Adds the given key to this hash set. | |
4221 static Handle<ObjectHashSet> Add(Handle<ObjectHashSet> table, | |
4222 Handle<Object> key); | |
4223 | |
4224 // Removes the given key from this hash set. | |
4225 static Handle<ObjectHashSet> Remove(Handle<ObjectHashSet> table, | |
4226 Handle<Object> key); | |
4227 }; | 4196 }; |
4228 | 4197 |
4229 | 4198 |
4230 // ObjectHashTable maps keys that are arbitrary objects to object values by | 4199 // ObjectHashTable maps keys that are arbitrary objects to object values by |
4231 // using the identity hash of the key for hashing purposes. | 4200 // using the identity hash of the key for hashing purposes. |
4232 class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> { | 4201 class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> { |
4233 public: | 4202 public: |
4234 static inline ObjectHashTable* cast(Object* obj) { | 4203 static inline ObjectHashTable* cast(Object* obj) { |
4235 ASSERT(obj->IsHashTable()); | 4204 ASSERT(obj->IsHashTable()); |
4236 return reinterpret_cast<ObjectHashTable*>(obj); | 4205 return reinterpret_cast<ObjectHashTable*>(obj); |
4237 } | 4206 } |
4238 | 4207 |
4239 static Handle<ObjectHashTable> EnsureCapacity( | 4208 static Handle<ObjectHashTable> EnsureCapacity( |
4240 Handle<ObjectHashTable> table, | 4209 Handle<ObjectHashTable> table, |
4241 int n, | 4210 int n, |
4242 Handle<Object> key, | 4211 Handle<Object> key, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4294 // data table indicating the next entry in this hash | 4263 // data table indicating the next entry in this hash |
4295 // bucket. | 4264 // bucket. |
4296 template<class Derived, int entrysize> | 4265 template<class Derived, int entrysize> |
4297 class OrderedHashTable: public FixedArray { | 4266 class OrderedHashTable: public FixedArray { |
4298 public: | 4267 public: |
4299 // Returns an OrderedHashTable with a capacity of at least |capacity|. | 4268 // Returns an OrderedHashTable with a capacity of at least |capacity|. |
4300 static Handle<Derived> Allocate( | 4269 static Handle<Derived> Allocate( |
4301 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); | 4270 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); |
4302 | 4271 |
4303 // Returns an OrderedHashTable (possibly |table|) with enough space | 4272 // Returns an OrderedHashTable (possibly |table|) with enough space |
4304 // to add at least one new element, or returns a Failure if a GC occurs. | 4273 // to add at least one new element. |
4305 static Handle<Derived> EnsureGrowable(Handle<Derived> table); | 4274 static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
4306 | 4275 |
4307 // Returns an OrderedHashTable (possibly |table|) that's shrunken | 4276 // Returns an OrderedHashTable (possibly |table|) that's shrunken |
4308 // if possible. | 4277 // if possible. |
4309 static Handle<Derived> Shrink(Handle<Derived> table); | 4278 static Handle<Derived> Shrink(Handle<Derived> table); |
4310 | 4279 |
4311 // Returns kNotFound if the key isn't present. | 4280 // Returns kNotFound if the key isn't present. |
4312 int FindEntry(Object* key); | 4281 int FindEntry(Object* key); |
4313 | 4282 |
4314 int NumberOfElements() { | 4283 int NumberOfElements() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4384 | 4353 |
4385 static const int kLoadFactor = 2; | 4354 static const int kLoadFactor = 2; |
4386 static const int kMaxCapacity = | 4355 static const int kMaxCapacity = |
4387 (FixedArray::kMaxLength - kHashTableStartIndex) | 4356 (FixedArray::kMaxLength - kHashTableStartIndex) |
4388 / (1 + (kEntrySize * kLoadFactor)); | 4357 / (1 + (kEntrySize * kLoadFactor)); |
4389 }; | 4358 }; |
4390 | 4359 |
4391 | 4360 |
4392 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { | 4361 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { |
4393 public: | 4362 public: |
4394 static OrderedHashSet* cast(Object* obj) { | 4363 static inline OrderedHashSet* cast(Object* obj); |
4395 ASSERT(obj->IsFixedArray()); // TODO(adamk): Make a map for this | |
4396 return reinterpret_cast<OrderedHashSet*>(obj); | |
4397 } | |
4398 | 4364 |
4399 bool Contains(Object* key); | 4365 bool Contains(Object* key); |
4400 static Handle<OrderedHashSet> Add( | 4366 static Handle<OrderedHashSet> Add( |
4401 Handle<OrderedHashSet> table, Handle<Object> key); | 4367 Handle<OrderedHashSet> table, Handle<Object> key); |
4402 static Handle<OrderedHashSet> Remove( | 4368 static Handle<OrderedHashSet> Remove( |
4403 Handle<OrderedHashSet> table, Handle<Object> key); | 4369 Handle<OrderedHashSet> table, Handle<Object> key); |
4404 }; | 4370 }; |
4405 | 4371 |
4406 | 4372 |
4407 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { | 4373 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { |
4408 public: | 4374 public: |
4409 static OrderedHashMap* cast(Object* obj) { | 4375 static inline OrderedHashMap* cast(Object* obj); |
4410 ASSERT(obj->IsFixedArray()); // TODO(adamk): Make a map for this | |
4411 return reinterpret_cast<OrderedHashMap*>(obj); | |
4412 } | |
4413 | 4376 |
4414 Object* Lookup(Object* key); | 4377 Object* Lookup(Object* key); |
4415 static Handle<OrderedHashMap> Put( | 4378 static Handle<OrderedHashMap> Put( |
4416 Handle<OrderedHashMap> table, | 4379 Handle<OrderedHashMap> table, |
4417 Handle<Object> key, | 4380 Handle<Object> key, |
4418 Handle<Object> value); | 4381 Handle<Object> value); |
4419 | 4382 |
4420 private: | 4383 private: |
4421 Object* ValueAt(int entry) { | 4384 Object* ValueAt(int entry) { |
4422 return get(EntryToIndex(entry) + kValueOffset); | 4385 return get(EntryToIndex(entry) + kValueOffset); |
(...skipping 6563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10986 } else { | 10949 } else { |
10987 value &= ~(1 << bit_position); | 10950 value &= ~(1 << bit_position); |
10988 } | 10951 } |
10989 return value; | 10952 return value; |
10990 } | 10953 } |
10991 }; | 10954 }; |
10992 | 10955 |
10993 } } // namespace v8::internal | 10956 } } // namespace v8::internal |
10994 | 10957 |
10995 #endif // V8_OBJECTS_H_ | 10958 #endif // V8_OBJECTS_H_ |
OLD | NEW |