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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // - HeapObject (superclass for everything allocated in the heap) | 59 // - HeapObject (superclass for everything allocated in the heap) |
60 // - JSReceiver (suitable for property access) | 60 // - JSReceiver (suitable for property access) |
61 // - JSObject | 61 // - JSObject |
62 // - JSArray | 62 // - JSArray |
63 // - JSArrayBuffer | 63 // - JSArrayBuffer |
64 // - JSArrayBufferView | 64 // - JSArrayBufferView |
65 // - JSTypedArray | 65 // - JSTypedArray |
66 // - JSDataView | 66 // - JSDataView |
67 // - JSSet | 67 // - JSSet |
68 // - JSMap | 68 // - JSMap |
| 69 // - JSSetIterator |
| 70 // - JSMapIterator |
69 // - JSWeakCollection | 71 // - JSWeakCollection |
70 // - JSWeakMap | 72 // - JSWeakMap |
71 // - JSWeakSet | 73 // - JSWeakSet |
72 // - JSRegExp | 74 // - JSRegExp |
73 // - JSFunction | 75 // - JSFunction |
74 // - JSGeneratorObject | 76 // - JSGeneratorObject |
75 // - JSModule | 77 // - JSModule |
76 // - GlobalObject | 78 // - GlobalObject |
77 // - JSGlobalObject | 79 // - JSGlobalObject |
78 // - JSBuiltinsObject | 80 // - JSBuiltinsObject |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 V(JS_GLOBAL_OBJECT_TYPE) \ | 440 V(JS_GLOBAL_OBJECT_TYPE) \ |
439 V(JS_BUILTINS_OBJECT_TYPE) \ | 441 V(JS_BUILTINS_OBJECT_TYPE) \ |
440 V(JS_GLOBAL_PROXY_TYPE) \ | 442 V(JS_GLOBAL_PROXY_TYPE) \ |
441 V(JS_ARRAY_TYPE) \ | 443 V(JS_ARRAY_TYPE) \ |
442 V(JS_ARRAY_BUFFER_TYPE) \ | 444 V(JS_ARRAY_BUFFER_TYPE) \ |
443 V(JS_TYPED_ARRAY_TYPE) \ | 445 V(JS_TYPED_ARRAY_TYPE) \ |
444 V(JS_DATA_VIEW_TYPE) \ | 446 V(JS_DATA_VIEW_TYPE) \ |
445 V(JS_PROXY_TYPE) \ | 447 V(JS_PROXY_TYPE) \ |
446 V(JS_SET_TYPE) \ | 448 V(JS_SET_TYPE) \ |
447 V(JS_MAP_TYPE) \ | 449 V(JS_MAP_TYPE) \ |
| 450 V(JS_SET_ITERATOR_TYPE) \ |
| 451 V(JS_MAP_ITERATOR_TYPE) \ |
448 V(JS_WEAK_MAP_TYPE) \ | 452 V(JS_WEAK_MAP_TYPE) \ |
449 V(JS_WEAK_SET_TYPE) \ | 453 V(JS_WEAK_SET_TYPE) \ |
450 V(JS_REGEXP_TYPE) \ | 454 V(JS_REGEXP_TYPE) \ |
451 \ | 455 \ |
452 V(JS_FUNCTION_TYPE) \ | 456 V(JS_FUNCTION_TYPE) \ |
453 V(JS_FUNCTION_PROXY_TYPE) \ | 457 V(JS_FUNCTION_PROXY_TYPE) \ |
454 V(DEBUG_INFO_TYPE) \ | 458 V(DEBUG_INFO_TYPE) \ |
455 V(BREAK_POINT_INFO_TYPE) | 459 V(BREAK_POINT_INFO_TYPE) |
456 | 460 |
457 | 461 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 JS_MODULE_TYPE, | 790 JS_MODULE_TYPE, |
787 JS_GLOBAL_OBJECT_TYPE, | 791 JS_GLOBAL_OBJECT_TYPE, |
788 JS_BUILTINS_OBJECT_TYPE, | 792 JS_BUILTINS_OBJECT_TYPE, |
789 JS_GLOBAL_PROXY_TYPE, | 793 JS_GLOBAL_PROXY_TYPE, |
790 JS_ARRAY_TYPE, | 794 JS_ARRAY_TYPE, |
791 JS_ARRAY_BUFFER_TYPE, | 795 JS_ARRAY_BUFFER_TYPE, |
792 JS_TYPED_ARRAY_TYPE, | 796 JS_TYPED_ARRAY_TYPE, |
793 JS_DATA_VIEW_TYPE, | 797 JS_DATA_VIEW_TYPE, |
794 JS_SET_TYPE, | 798 JS_SET_TYPE, |
795 JS_MAP_TYPE, | 799 JS_MAP_TYPE, |
| 800 JS_SET_ITERATOR_TYPE, |
| 801 JS_MAP_ITERATOR_TYPE, |
796 JS_WEAK_MAP_TYPE, | 802 JS_WEAK_MAP_TYPE, |
797 JS_WEAK_SET_TYPE, | 803 JS_WEAK_SET_TYPE, |
798 | 804 |
799 JS_REGEXP_TYPE, | 805 JS_REGEXP_TYPE, |
800 | 806 |
801 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE | 807 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
802 | 808 |
803 // Pseudo-types | 809 // Pseudo-types |
804 FIRST_TYPE = 0x0, | 810 FIRST_TYPE = 0x0, |
805 LAST_TYPE = JS_FUNCTION_TYPE, | 811 LAST_TYPE = JS_FUNCTION_TYPE, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 V(Boolean) \ | 1052 V(Boolean) \ |
1047 V(JSArray) \ | 1053 V(JSArray) \ |
1048 V(JSArrayBuffer) \ | 1054 V(JSArrayBuffer) \ |
1049 V(JSArrayBufferView) \ | 1055 V(JSArrayBufferView) \ |
1050 V(JSTypedArray) \ | 1056 V(JSTypedArray) \ |
1051 V(JSDataView) \ | 1057 V(JSDataView) \ |
1052 V(JSProxy) \ | 1058 V(JSProxy) \ |
1053 V(JSFunctionProxy) \ | 1059 V(JSFunctionProxy) \ |
1054 V(JSSet) \ | 1060 V(JSSet) \ |
1055 V(JSMap) \ | 1061 V(JSMap) \ |
| 1062 V(JSSetIterator) \ |
| 1063 V(JSMapIterator) \ |
1056 V(JSWeakCollection) \ | 1064 V(JSWeakCollection) \ |
1057 V(JSWeakMap) \ | 1065 V(JSWeakMap) \ |
1058 V(JSWeakSet) \ | 1066 V(JSWeakSet) \ |
1059 V(JSRegExp) \ | 1067 V(JSRegExp) \ |
1060 V(HashTable) \ | 1068 V(HashTable) \ |
1061 V(Dictionary) \ | 1069 V(Dictionary) \ |
1062 V(StringTable) \ | 1070 V(StringTable) \ |
1063 V(JSFunctionResultCache) \ | 1071 V(JSFunctionResultCache) \ |
1064 V(NormalizedMapCache) \ | 1072 V(NormalizedMapCache) \ |
1065 V(CompilationCacheTable) \ | 1073 V(CompilationCacheTable) \ |
(...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4261 // equality operator and Object::GetHash() for the hash function. | 4269 // equality operator and Object::GetHash() for the hash function. |
4262 // | 4270 // |
4263 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at | 4271 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at |
4264 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables | 4272 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables |
4265 // Originally attributed to Tyler Close. | 4273 // Originally attributed to Tyler Close. |
4266 // | 4274 // |
4267 // Memory layout: | 4275 // Memory layout: |
4268 // [0]: bucket count | 4276 // [0]: bucket count |
4269 // [1]: element count | 4277 // [1]: element count |
4270 // [2]: deleted element count | 4278 // [2]: deleted element count |
4271 // [3..(NumberOfBuckets() - 1)]: "hash table", where each item is an offset | 4279 // [3]: live iterators (doubly-linked list) |
| 4280 // [4..(NumberOfBuckets() - 1)]: "hash table", where each item is an offset |
4272 // into the data table (see below) where the | 4281 // into the data table (see below) where the |
4273 // first item in this bucket is stored. | 4282 // first item in this bucket is stored. |
4274 // [3 + NumberOfBuckets()..length]: "data table", an array of length | 4283 // [4 + NumberOfBuckets()..length]: "data table", an array of length |
4275 // Capacity() * kEntrySize, where the first entrysize | 4284 // Capacity() * kEntrySize, where the first entrysize |
4276 // items are handled by the derived class and the | 4285 // items are handled by the derived class and the |
4277 // item at kChainOffset is another entry into the | 4286 // item at kChainOffset is another entry into the |
4278 // data table indicating the next entry in this hash | 4287 // data table indicating the next entry in this hash |
4279 // bucket. | 4288 // bucket. |
4280 template<class Derived, int entrysize> | 4289 template<class Derived, class Iterator, int entrysize> |
4281 class OrderedHashTable: public FixedArray { | 4290 class OrderedHashTable: public FixedArray { |
4282 public: | 4291 public: |
4283 // Returns an OrderedHashTable with a capacity of at least |capacity|. | 4292 // Returns an OrderedHashTable with a capacity of at least |capacity|. |
4284 static Handle<Derived> Allocate( | 4293 static Handle<Derived> Allocate( |
4285 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); | 4294 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); |
4286 | 4295 |
4287 // Returns an OrderedHashTable (possibly |table|) with enough space | 4296 // Returns an OrderedHashTable (possibly |table|) with enough space |
4288 // to add at least one new element. | 4297 // to add at least one new element. |
4289 static Handle<Derived> EnsureGrowable(Handle<Derived> table); | 4298 static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
4290 | 4299 |
4291 // Returns an OrderedHashTable (possibly |table|) that's shrunken | 4300 // Returns an OrderedHashTable (possibly |table|) that's shrunken |
4292 // if possible. | 4301 // if possible. |
4293 static Handle<Derived> Shrink(Handle<Derived> table); | 4302 static Handle<Derived> Shrink(Handle<Derived> table); |
4294 | 4303 |
| 4304 // Returns a new empty OrderedHashTable and updates all the iterators to |
| 4305 // point to the new table. |
| 4306 static Handle<Derived> Clear(Handle<Derived> table); |
| 4307 |
4295 // Returns kNotFound if the key isn't present. | 4308 // Returns kNotFound if the key isn't present. |
4296 int FindEntry(Object* key); | 4309 int FindEntry(Object* key); |
4297 | 4310 |
4298 int NumberOfElements() { | 4311 int NumberOfElements() { |
4299 return Smi::cast(get(kNumberOfElementsIndex))->value(); | 4312 return Smi::cast(get(kNumberOfElementsIndex))->value(); |
4300 } | 4313 } |
4301 | 4314 |
4302 int NumberOfDeletedElements() { | 4315 int NumberOfDeletedElements() { |
4303 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); | 4316 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
4304 } | 4317 } |
4305 | 4318 |
| 4319 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 4320 |
4306 int NumberOfBuckets() { | 4321 int NumberOfBuckets() { |
4307 return Smi::cast(get(kNumberOfBucketsIndex))->value(); | 4322 return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
4308 } | 4323 } |
4309 | 4324 |
| 4325 // Creates a new iterator associated with this hash table. |
| 4326 // [kind] needs to be one of the OrderedHashTableIterator Kind enum values. |
| 4327 static Handle<Iterator> CreateIterator(Handle<Derived> table, int kind); |
| 4328 |
| 4329 Object* iterators() { return get(kIteratorsIndex); } |
| 4330 |
| 4331 void set_iterators(Object* value) { set(kIteratorsIndex, value); } |
| 4332 |
4310 // Returns the index into the data table where the new entry | 4333 // Returns the index into the data table where the new entry |
4311 // should be placed. The table is assumed to have enough space | 4334 // should be placed. The table is assumed to have enough space |
4312 // for a new entry. | 4335 // for a new entry. |
4313 int AddEntry(int hash); | 4336 int AddEntry(int hash); |
4314 | 4337 |
4315 // Removes the entry, and puts the_hole in entrysize pointers | 4338 // Removes the entry, and puts the_hole in entrysize pointers |
4316 // (leaving the hash table chain intact). | 4339 // (leaving the hash table chain intact). |
4317 void RemoveEntry(int entry); | 4340 void RemoveEntry(int entry); |
4318 | 4341 |
4319 // Returns an index into |this| for the given entry. | 4342 // Returns an index into |this| for the given entry. |
4320 int EntryToIndex(int entry) { | 4343 int EntryToIndex(int entry) { |
4321 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); | 4344 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
4322 } | 4345 } |
4323 | 4346 |
| 4347 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 4348 |
4324 static const int kNotFound = -1; | 4349 static const int kNotFound = -1; |
| 4350 static const int kMinCapacity = 4; |
4325 | 4351 |
4326 private: | 4352 private: |
4327 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); | 4353 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
4328 | 4354 |
4329 void SetNumberOfBuckets(int num) { | 4355 void SetNumberOfBuckets(int num) { |
4330 set(kNumberOfBucketsIndex, Smi::FromInt(num)); | 4356 set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
4331 } | 4357 } |
4332 | 4358 |
4333 void SetNumberOfElements(int num) { | 4359 void SetNumberOfElements(int num) { |
4334 set(kNumberOfElementsIndex, Smi::FromInt(num)); | 4360 set(kNumberOfElementsIndex, Smi::FromInt(num)); |
4335 } | 4361 } |
4336 | 4362 |
4337 void SetNumberOfDeletedElements(int num) { | 4363 void SetNumberOfDeletedElements(int num) { |
4338 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); | 4364 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
4339 } | 4365 } |
4340 | 4366 |
4341 int Capacity() { | 4367 int Capacity() { |
4342 return NumberOfBuckets() * kLoadFactor; | 4368 return NumberOfBuckets() * kLoadFactor; |
4343 } | 4369 } |
4344 | 4370 |
4345 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | |
4346 | |
4347 // Returns the next entry for the given entry. | 4371 // Returns the next entry for the given entry. |
4348 int ChainAt(int entry) { | 4372 int ChainAt(int entry) { |
4349 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value(); | 4373 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value(); |
4350 } | 4374 } |
4351 | 4375 |
4352 int HashToBucket(int hash) { | 4376 int HashToBucket(int hash) { |
4353 return hash & (NumberOfBuckets() - 1); | 4377 return hash & (NumberOfBuckets() - 1); |
4354 } | 4378 } |
4355 | 4379 |
4356 int HashToEntry(int hash) { | 4380 int HashToEntry(int hash) { |
4357 int bucket = HashToBucket(hash); | 4381 int bucket = HashToBucket(hash); |
4358 return Smi::cast(get(kHashTableStartIndex + bucket))->value(); | 4382 return Smi::cast(get(kHashTableStartIndex + bucket))->value(); |
4359 } | 4383 } |
4360 | 4384 |
4361 static const int kNumberOfBucketsIndex = 0; | 4385 static const int kNumberOfBucketsIndex = 0; |
4362 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; | 4386 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; |
4363 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; | 4387 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; |
4364 static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; | 4388 static const int kIteratorsIndex = kNumberOfDeletedElementsIndex + 1; |
| 4389 static const int kHashTableStartIndex = kIteratorsIndex + 1; |
4365 | 4390 |
4366 static const int kEntrySize = entrysize + 1; | 4391 static const int kEntrySize = entrysize + 1; |
4367 static const int kChainOffset = entrysize; | 4392 static const int kChainOffset = entrysize; |
4368 | 4393 |
4369 static const int kLoadFactor = 2; | 4394 static const int kLoadFactor = 2; |
4370 static const int kMaxCapacity = | 4395 static const int kMaxCapacity = |
4371 (FixedArray::kMaxLength - kHashTableStartIndex) | 4396 (FixedArray::kMaxLength - kHashTableStartIndex) |
4372 / (1 + (kEntrySize * kLoadFactor)); | 4397 / (1 + (kEntrySize * kLoadFactor)); |
4373 }; | 4398 }; |
4374 | 4399 |
4375 | 4400 |
4376 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { | 4401 class JSSetIterator; |
| 4402 |
| 4403 |
| 4404 class OrderedHashSet: public OrderedHashTable< |
| 4405 OrderedHashSet, JSSetIterator, 1> { |
4377 public: | 4406 public: |
4378 static OrderedHashSet* cast(Object* obj) { | 4407 static OrderedHashSet* cast(Object* obj) { |
4379 ASSERT(obj->IsOrderedHashTable()); | 4408 ASSERT(obj->IsOrderedHashTable()); |
4380 return reinterpret_cast<OrderedHashSet*>(obj); | 4409 return reinterpret_cast<OrderedHashSet*>(obj); |
4381 } | 4410 } |
4382 | 4411 |
4383 bool Contains(Object* key); | 4412 bool Contains(Object* key); |
4384 static Handle<OrderedHashSet> Add( | 4413 static Handle<OrderedHashSet> Add( |
4385 Handle<OrderedHashSet> table, Handle<Object> key); | 4414 Handle<OrderedHashSet> table, Handle<Object> key); |
4386 static Handle<OrderedHashSet> Remove( | 4415 static Handle<OrderedHashSet> Remove( |
4387 Handle<OrderedHashSet> table, Handle<Object> key); | 4416 Handle<OrderedHashSet> table, Handle<Object> key); |
4388 }; | 4417 }; |
4389 | 4418 |
4390 | 4419 |
4391 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { | 4420 class JSMapIterator; |
| 4421 |
| 4422 |
| 4423 class OrderedHashMap:public OrderedHashTable< |
| 4424 OrderedHashMap, JSMapIterator, 2> { |
4392 public: | 4425 public: |
4393 static OrderedHashMap* cast(Object* obj) { | 4426 static OrderedHashMap* cast(Object* obj) { |
4394 ASSERT(obj->IsOrderedHashTable()); | 4427 ASSERT(obj->IsOrderedHashTable()); |
4395 return reinterpret_cast<OrderedHashMap*>(obj); | 4428 return reinterpret_cast<OrderedHashMap*>(obj); |
4396 } | 4429 } |
4397 | 4430 |
4398 Object* Lookup(Object* key); | 4431 Object* Lookup(Object* key); |
4399 static Handle<OrderedHashMap> Put( | 4432 static Handle<OrderedHashMap> Put( |
4400 Handle<OrderedHashMap> table, | 4433 Handle<OrderedHashMap> table, |
4401 Handle<Object> key, | 4434 Handle<Object> key, |
(...skipping 3119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7521 static const int kContinuationOffset = kReceiverOffset + kPointerSize; | 7554 static const int kContinuationOffset = kReceiverOffset + kPointerSize; |
7522 static const int kOperandStackOffset = kContinuationOffset + kPointerSize; | 7555 static const int kOperandStackOffset = kContinuationOffset + kPointerSize; |
7523 static const int kStackHandlerIndexOffset = | 7556 static const int kStackHandlerIndexOffset = |
7524 kOperandStackOffset + kPointerSize; | 7557 kOperandStackOffset + kPointerSize; |
7525 static const int kSize = kStackHandlerIndexOffset + kPointerSize; | 7558 static const int kSize = kStackHandlerIndexOffset + kPointerSize; |
7526 | 7559 |
7527 // Resume mode, for use by runtime functions. | 7560 // Resume mode, for use by runtime functions. |
7528 enum ResumeMode { NEXT, THROW }; | 7561 enum ResumeMode { NEXT, THROW }; |
7529 | 7562 |
7530 // Yielding from a generator returns an object with the following inobject | 7563 // Yielding from a generator returns an object with the following inobject |
7531 // properties. See Context::generator_result_map() for the map. | 7564 // properties. See Context::iterator_result_map() for the map. |
7532 static const int kResultValuePropertyIndex = 0; | 7565 static const int kResultValuePropertyIndex = 0; |
7533 static const int kResultDonePropertyIndex = 1; | 7566 static const int kResultDonePropertyIndex = 1; |
7534 static const int kResultPropertyCount = 2; | 7567 static const int kResultPropertyCount = 2; |
7535 | 7568 |
7536 static const int kResultValuePropertyOffset = JSObject::kHeaderSize; | 7569 static const int kResultValuePropertyOffset = JSObject::kHeaderSize; |
7537 static const int kResultDonePropertyOffset = | 7570 static const int kResultDonePropertyOffset = |
7538 kResultValuePropertyOffset + kPointerSize; | 7571 kResultValuePropertyOffset + kPointerSize; |
7539 static const int kResultSize = kResultDonePropertyOffset + kPointerSize; | 7572 static const int kResultSize = kResultDonePropertyOffset + kPointerSize; |
7540 | 7573 |
7541 private: | 7574 private: |
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9989 DECLARE_VERIFIER(JSMap) | 10022 DECLARE_VERIFIER(JSMap) |
9990 | 10023 |
9991 static const int kTableOffset = JSObject::kHeaderSize; | 10024 static const int kTableOffset = JSObject::kHeaderSize; |
9992 static const int kSize = kTableOffset + kPointerSize; | 10025 static const int kSize = kTableOffset + kPointerSize; |
9993 | 10026 |
9994 private: | 10027 private: |
9995 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); | 10028 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
9996 }; | 10029 }; |
9997 | 10030 |
9998 | 10031 |
| 10032 // OrderedHashTableIterator is an iterator that iterates over the keys and |
| 10033 // values of an OrderedHashTable. |
| 10034 // |
| 10035 // The hash table has a reference to the iterator and the iterators themselves |
| 10036 // have references to the [next_iterator] and [previous_iterator], thus creating |
| 10037 // a double linked list. |
| 10038 // |
| 10039 // When the hash table changes the iterators are called to update their [index] |
| 10040 // and [count]. The hash table calls [EntryRemoved], [TableCompacted] as well |
| 10041 // as [TableCleared]. |
| 10042 // |
| 10043 // When an iterator is done it closes itself. It removes itself from the double |
| 10044 // linked list and it sets its [table] to undefined, no longer keeping the |
| 10045 // [table] alive. |
| 10046 template<class Derived, class TableType> |
| 10047 class OrderedHashTableIterator: public JSObject { |
| 10048 public: |
| 10049 // [table]: the backing hash table mapping keys to values. |
| 10050 DECL_ACCESSORS(table, Object) |
| 10051 |
| 10052 // [index]: The index into the data table. |
| 10053 DECL_ACCESSORS(index, Smi) |
| 10054 |
| 10055 // [count]: The logical index into the data table, ignoring the holes. |
| 10056 DECL_ACCESSORS(count, Smi) |
| 10057 |
| 10058 // [kind]: The kind of iteration this is. One of the [Kind] enum values. |
| 10059 DECL_ACCESSORS(kind, Smi) |
| 10060 |
| 10061 // [next_iterator]: Used as a double linked list for the live iterators. |
| 10062 DECL_ACCESSORS(next_iterator, Object) |
| 10063 |
| 10064 // [previous_iterator]: Used as a double linked list for the live iterators. |
| 10065 DECL_ACCESSORS(previous_iterator, Object) |
| 10066 |
| 10067 void OrderedHashTableIteratorPrint(FILE* out); |
| 10068 |
| 10069 static const int kTableOffset = JSObject::kHeaderSize; |
| 10070 static const int kIndexOffset = kTableOffset + kPointerSize; |
| 10071 static const int kCountOffset = kIndexOffset + kPointerSize; |
| 10072 static const int kKindOffset = kCountOffset + kPointerSize; |
| 10073 static const int kNextIteratorOffset = kKindOffset + kPointerSize; |
| 10074 static const int kPreviousIteratorOffset = kNextIteratorOffset + kPointerSize; |
| 10075 static const int kSize = kPreviousIteratorOffset + kPointerSize; |
| 10076 |
| 10077 enum Kind { |
| 10078 kKindKeys = 1, |
| 10079 kKindValues = 2, |
| 10080 kKindEntries = 3 |
| 10081 }; |
| 10082 |
| 10083 // Called by the underlying [table] when an entry is removed. |
| 10084 void EntryRemoved(int index); |
| 10085 |
| 10086 // Called by the underlying [table] when it is compacted/rehashed. |
| 10087 void TableCompacted() { |
| 10088 // All holes have been removed so index is now same as count. |
| 10089 set_index(count()); |
| 10090 } |
| 10091 |
| 10092 // Called by the underlying [table] when it is cleared. |
| 10093 void TableCleared() { |
| 10094 set_index(Smi::FromInt(0)); |
| 10095 set_count(Smi::FromInt(0)); |
| 10096 } |
| 10097 |
| 10098 // Removes the iterator from the double linked list and removes its reference |
| 10099 // back to the [table]. |
| 10100 void Close(); |
| 10101 |
| 10102 // Returns an iterator result object: {value: any, done: boolean} and moves |
| 10103 // the index to the next valid entry. Closes the iterator if moving past the |
| 10104 // end. |
| 10105 static Handle<JSObject> Next(Handle<Derived> iterator); |
| 10106 |
| 10107 private: |
| 10108 // Ensures [index] is not pointing to a hole. |
| 10109 void Seek(); |
| 10110 |
| 10111 // Moves [index] to next valid entry. Closes the iterator if moving past the |
| 10112 // end. |
| 10113 void MoveNext(); |
| 10114 |
| 10115 bool Closed() { |
| 10116 return table()->IsUndefined(); |
| 10117 } |
| 10118 |
| 10119 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); |
| 10120 }; |
| 10121 |
| 10122 |
| 10123 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, |
| 10124 OrderedHashSet> { |
| 10125 public: |
| 10126 static Handle<JSSetIterator> Create(Isolate* isolate); |
| 10127 |
| 10128 // Dispatched behavior. |
| 10129 DECLARE_PRINTER(JSSetIterator) |
| 10130 DECLARE_VERIFIER(JSSetIterator) |
| 10131 |
| 10132 // Casting. |
| 10133 static inline JSSetIterator* cast(Object* obj); |
| 10134 |
| 10135 static Handle<Object> ValueForKind( |
| 10136 Handle<JSSetIterator> iterator, int entry_index); |
| 10137 |
| 10138 private: |
| 10139 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); |
| 10140 }; |
| 10141 |
| 10142 |
| 10143 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, |
| 10144 OrderedHashMap> { |
| 10145 public: |
| 10146 static Handle<JSMapIterator> Create(Isolate* isolate); |
| 10147 |
| 10148 // Dispatched behavior. |
| 10149 DECLARE_PRINTER(JSMapIterator) |
| 10150 DECLARE_VERIFIER(JSMapIterator) |
| 10151 |
| 10152 // Casting. |
| 10153 static inline JSMapIterator* cast(Object* obj); |
| 10154 |
| 10155 static Handle<Object> ValueForKind( |
| 10156 Handle<JSMapIterator> iterator, int entry_index); |
| 10157 |
| 10158 private: |
| 10159 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); |
| 10160 }; |
| 10161 |
| 10162 |
9999 // Base class for both JSWeakMap and JSWeakSet | 10163 // Base class for both JSWeakMap and JSWeakSet |
10000 class JSWeakCollection: public JSObject { | 10164 class JSWeakCollection: public JSObject { |
10001 public: | 10165 public: |
10002 // [table]: the backing hash table mapping keys to values. | 10166 // [table]: the backing hash table mapping keys to values. |
10003 DECL_ACCESSORS(table, Object) | 10167 DECL_ACCESSORS(table, Object) |
10004 | 10168 |
10005 // [next]: linked list of encountered weak maps during GC. | 10169 // [next]: linked list of encountered weak maps during GC. |
10006 DECL_ACCESSORS(next, Object) | 10170 DECL_ACCESSORS(next, Object) |
10007 | 10171 |
10008 static const int kTableOffset = JSObject::kHeaderSize; | 10172 static const int kTableOffset = JSObject::kHeaderSize; |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11022 } else { | 11186 } else { |
11023 value &= ~(1 << bit_position); | 11187 value &= ~(1 << bit_position); |
11024 } | 11188 } |
11025 return value; | 11189 return value; |
11026 } | 11190 } |
11027 }; | 11191 }; |
11028 | 11192 |
11029 } } // namespace v8::internal | 11193 } } // namespace v8::internal |
11030 | 11194 |
11031 #endif // V8_OBJECTS_H_ | 11195 #endif // V8_OBJECTS_H_ |
OLD | NEW |