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

Side by Side Diff: src/objects.h

Issue 225183009: Use OrderedHashTables as the backing store of JSSet and JSMap (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Get rid of IsOrderedHashSet/Map methods 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 | « src/heap.cc ('k') | 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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
1080 1081
1081 1082
1082 #define ERROR_MESSAGES_LIST(V) \ 1083 #define ERROR_MESSAGES_LIST(V) \
1083 V(kNoReason, "no reason") \ 1084 V(kNoReason, "no reason") \
1084 \ 1085 \
1085 V(k32BitValueInRegisterIsNotZeroExtended, \ 1086 V(k32BitValueInRegisterIsNotZeroExtended, \
1086 "32 bit value in register is not zero-extended") \ 1087 "32 bit value in register is not zero-extended") \
1087 V(kAlignmentMarkerExpected, "Alignment marker expected") \ 1088 V(kAlignmentMarkerExpected, "Alignment marker expected") \
1088 V(kAllocationIsNotDoubleAligned, "Allocation is not double aligned") \ 1089 V(kAllocationIsNotDoubleAligned, "Allocation is not double aligned") \
1089 V(kAPICallReturnedInvalidObject, "API call returned invalid object") \ 1090 V(kAPICallReturnedInvalidObject, "API call returned invalid object") \
(...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3744 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; 3745 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
3745 3746
3746 // Find entry for key otherwise return kNotFound. 3747 // Find entry for key otherwise return kNotFound.
3747 inline int FindEntry(Key key); 3748 inline int FindEntry(Key key);
3748 int FindEntry(Isolate* isolate, Key key); 3749 int FindEntry(Isolate* isolate, Key key);
3749 3750
3750 // Rehashes the table in-place. 3751 // Rehashes the table in-place.
3751 void Rehash(Key key); 3752 void Rehash(Key key);
3752 3753
3753 protected: 3754 protected:
3754 friend class ObjectHashSet;
3755 friend class ObjectHashTable; 3755 friend class ObjectHashTable;
3756 3756
3757 // Find the entry at which to insert element with the given key that 3757 // Find the entry at which to insert element with the given key that
3758 // has the given hash value. 3758 // has the given hash value.
3759 uint32_t FindInsertionEntry(uint32_t hash); 3759 uint32_t FindInsertionEntry(uint32_t hash);
3760 3760
3761 // Returns the index for an entry (of the key) 3761 // Returns the index for an entry (of the key)
3762 static inline int EntryToIndex(int entry) { 3762 static inline int EntryToIndex(int entry) {
3763 return (entry * kEntrySize) + kElementsStartIndex; 3763 return (entry * kEntrySize) + kElementsStartIndex;
3764 } 3764 }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
4175 // Return the updated dictionary. 4175 // Return the updated dictionary.
4176 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( 4176 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
4177 Handle<UnseededNumberDictionary> dictionary, 4177 Handle<UnseededNumberDictionary> dictionary,
4178 uint32_t index, 4178 uint32_t index,
4179 Handle<Object> value); 4179 Handle<Object> value);
4180 4180
4181 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); 4181 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value);
4182 }; 4182 };
4183 4183
4184 4184
4185 template <int entrysize>
4186 class ObjectHashTableShape : public BaseShape<Object*> { 4185 class ObjectHashTableShape : public BaseShape<Object*> {
4187 public: 4186 public:
4188 static inline bool IsMatch(Object* key, Object* other); 4187 static inline bool IsMatch(Object* key, Object* other);
4189 static inline uint32_t Hash(Object* key); 4188 static inline uint32_t Hash(Object* key);
4190 static inline uint32_t HashForObject(Object* key, Object* object); 4189 static inline uint32_t HashForObject(Object* key, Object* object);
4191 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, 4190 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap,
4192 Object* key); 4191 Object* key);
4193 static const int kPrefixSize = 0; 4192 static const int kPrefixSize = 0;
4194 static const int kEntrySize = entrysize; 4193 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 }; 4194 };
4228 4195
4229 4196
4230 // ObjectHashTable maps keys that are arbitrary objects to object values by 4197 // ObjectHashTable maps keys that are arbitrary objects to object values by
4231 // using the identity hash of the key for hashing purposes. 4198 // using the identity hash of the key for hashing purposes.
4232 class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> { 4199 class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> {
4233 public: 4200 public:
4234 static inline ObjectHashTable* cast(Object* obj) { 4201 static inline ObjectHashTable* cast(Object* obj) {
4235 ASSERT(obj->IsHashTable()); 4202 ASSERT(obj->IsHashTable());
4236 return reinterpret_cast<ObjectHashTable*>(obj); 4203 return reinterpret_cast<ObjectHashTable*>(obj);
4237 } 4204 }
4238 4205
4239 static Handle<ObjectHashTable> EnsureCapacity( 4206 static Handle<ObjectHashTable> EnsureCapacity(
4240 Handle<ObjectHashTable> table, 4207 Handle<ObjectHashTable> table,
4241 int n, 4208 int n,
4242 Handle<Object> key, 4209 Handle<Object> key,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4294 // data table indicating the next entry in this hash 4261 // data table indicating the next entry in this hash
4295 // bucket. 4262 // bucket.
4296 template<class Derived, int entrysize> 4263 template<class Derived, int entrysize>
4297 class OrderedHashTable: public FixedArray { 4264 class OrderedHashTable: public FixedArray {
4298 public: 4265 public:
4299 // Returns an OrderedHashTable with a capacity of at least |capacity|. 4266 // Returns an OrderedHashTable with a capacity of at least |capacity|.
4300 static Handle<Derived> Allocate( 4267 static Handle<Derived> Allocate(
4301 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); 4268 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED);
4302 4269
4303 // Returns an OrderedHashTable (possibly |table|) with enough space 4270 // Returns an OrderedHashTable (possibly |table|) with enough space
4304 // to add at least one new element, or returns a Failure if a GC occurs. 4271 // to add at least one new element.
4305 static Handle<Derived> EnsureGrowable(Handle<Derived> table); 4272 static Handle<Derived> EnsureGrowable(Handle<Derived> table);
4306 4273
4307 // Returns an OrderedHashTable (possibly |table|) that's shrunken 4274 // Returns an OrderedHashTable (possibly |table|) that's shrunken
4308 // if possible. 4275 // if possible.
4309 static Handle<Derived> Shrink(Handle<Derived> table); 4276 static Handle<Derived> Shrink(Handle<Derived> table);
4310 4277
4311 // Returns kNotFound if the key isn't present. 4278 // Returns kNotFound if the key isn't present.
4312 int FindEntry(Object* key); 4279 int FindEntry(Object* key);
4313 4280
4314 int NumberOfElements() { 4281 int NumberOfElements() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
4385 static const int kLoadFactor = 2; 4352 static const int kLoadFactor = 2;
4386 static const int kMaxCapacity = 4353 static const int kMaxCapacity =
4387 (FixedArray::kMaxLength - kHashTableStartIndex) 4354 (FixedArray::kMaxLength - kHashTableStartIndex)
4388 / (1 + (kEntrySize * kLoadFactor)); 4355 / (1 + (kEntrySize * kLoadFactor));
4389 }; 4356 };
4390 4357
4391 4358
4392 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { 4359 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> {
4393 public: 4360 public:
4394 static OrderedHashSet* cast(Object* obj) { 4361 static OrderedHashSet* cast(Object* obj) {
4395 ASSERT(obj->IsFixedArray()); // TODO(adamk): Make a map for this 4362 ASSERT(obj->IsOrderedHashTable());
4396 return reinterpret_cast<OrderedHashSet*>(obj); 4363 return reinterpret_cast<OrderedHashSet*>(obj);
4397 } 4364 }
4398 4365
4399 bool Contains(Object* key); 4366 bool Contains(Object* key);
4400 static Handle<OrderedHashSet> Add( 4367 static Handle<OrderedHashSet> Add(
4401 Handle<OrderedHashSet> table, Handle<Object> key); 4368 Handle<OrderedHashSet> table, Handle<Object> key);
4402 static Handle<OrderedHashSet> Remove( 4369 static Handle<OrderedHashSet> Remove(
4403 Handle<OrderedHashSet> table, Handle<Object> key); 4370 Handle<OrderedHashSet> table, Handle<Object> key);
4404 }; 4371 };
4405 4372
4406 4373
4407 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { 4374 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> {
4408 public: 4375 public:
4409 static OrderedHashMap* cast(Object* obj) { 4376 static OrderedHashMap* cast(Object* obj) {
4410 ASSERT(obj->IsFixedArray()); // TODO(adamk): Make a map for this 4377 ASSERT(obj->IsOrderedHashTable());
4411 return reinterpret_cast<OrderedHashMap*>(obj); 4378 return reinterpret_cast<OrderedHashMap*>(obj);
4412 } 4379 }
4413 4380
4414 Object* Lookup(Object* key); 4381 Object* Lookup(Object* key);
4415 static Handle<OrderedHashMap> Put( 4382 static Handle<OrderedHashMap> Put(
4416 Handle<OrderedHashMap> table, 4383 Handle<OrderedHashMap> table,
4417 Handle<Object> key, 4384 Handle<Object> key,
4418 Handle<Object> value); 4385 Handle<Object> value);
4419 4386
4420 private: 4387 private:
(...skipping 6565 matching lines...) Expand 10 before | Expand all | Expand 10 after
10986 } else { 10953 } else {
10987 value &= ~(1 << bit_position); 10954 value &= ~(1 << bit_position);
10988 } 10955 }
10989 return value; 10956 return value;
10990 } 10957 }
10991 }; 10958 };
10992 10959
10993 } } // namespace v8::internal 10960 } } // namespace v8::internal
10994 10961
10995 #endif // V8_OBJECTS_H_ 10962 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698