Chromium Code Reviews| 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 (double linked list) |
|
adamk
2014/04/14 19:15:42
Nit: s/double linked/doubly-linked/
arv (Not doing code reviews)
2014/04/14 19:51:49
Done.
| |
| 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 |
| 4306 int NumberOfBuckets() { | 4319 int NumberOfBuckets() { |
| 4307 return Smi::cast(get(kNumberOfBucketsIndex))->value(); | 4320 return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 4308 } | 4321 } |
| 4309 | 4322 |
| 4323 Handle<Iterator> CreateIterator(int kind); | |
|
adamk
2014/04/14 19:15:42
This should at least have a comment referring to t
arv (Not doing code reviews)
2014/04/14 19:51:49
This is an instance method. The iterator depends o
| |
| 4324 | |
| 4325 Object* iterators() { | |
| 4326 return get(kIteratorsIndex); | |
|
adamk
2014/04/14 19:15:42
Nit: if you can fit these on one line, please do s
arv (Not doing code reviews)
2014/04/14 19:51:49
Done.
| |
| 4327 } | |
| 4328 | |
| 4329 void set_iterators(Object* value) { | |
| 4330 set(kIteratorsIndex, value); | |
| 4331 } | |
| 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; |
| 4325 | 4350 |
| 4326 private: | 4351 private: |
| 4327 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); | 4352 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
| 4328 | 4353 |
| 4329 void SetNumberOfBuckets(int num) { | 4354 void SetNumberOfBuckets(int num) { |
| 4330 set(kNumberOfBucketsIndex, Smi::FromInt(num)); | 4355 set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
| 4331 } | 4356 } |
| 4332 | 4357 |
| 4333 void SetNumberOfElements(int num) { | 4358 void SetNumberOfElements(int num) { |
| 4334 set(kNumberOfElementsIndex, Smi::FromInt(num)); | 4359 set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 4335 } | 4360 } |
| 4336 | 4361 |
| 4337 void SetNumberOfDeletedElements(int num) { | 4362 void SetNumberOfDeletedElements(int num) { |
| 4338 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); | 4363 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
| 4339 } | 4364 } |
| 4340 | 4365 |
| 4341 int Capacity() { | 4366 int Capacity() { |
| 4342 return NumberOfBuckets() * kLoadFactor; | 4367 return NumberOfBuckets() * kLoadFactor; |
| 4343 } | 4368 } |
| 4344 | 4369 |
| 4345 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | |
| 4346 | |
| 4347 // Returns the next entry for the given entry. | 4370 // Returns the next entry for the given entry. |
| 4348 int ChainAt(int entry) { | 4371 int ChainAt(int entry) { |
| 4349 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value(); | 4372 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value(); |
| 4350 } | 4373 } |
| 4351 | 4374 |
| 4352 int HashToBucket(int hash) { | 4375 int HashToBucket(int hash) { |
| 4353 return hash & (NumberOfBuckets() - 1); | 4376 return hash & (NumberOfBuckets() - 1); |
| 4354 } | 4377 } |
| 4355 | 4378 |
| 4356 int HashToEntry(int hash) { | 4379 int HashToEntry(int hash) { |
| 4357 int bucket = HashToBucket(hash); | 4380 int bucket = HashToBucket(hash); |
| 4358 return Smi::cast(get(kHashTableStartIndex + bucket))->value(); | 4381 return Smi::cast(get(kHashTableStartIndex + bucket))->value(); |
| 4359 } | 4382 } |
| 4360 | 4383 |
| 4361 static const int kNumberOfBucketsIndex = 0; | 4384 static const int kNumberOfBucketsIndex = 0; |
| 4362 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; | 4385 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; |
| 4363 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; | 4386 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; |
| 4364 static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; | 4387 static const int kIteratorsIndex = kNumberOfDeletedElementsIndex + 1; |
| 4388 static const int kHashTableStartIndex = kIteratorsIndex + 1; | |
| 4365 | 4389 |
| 4366 static const int kEntrySize = entrysize + 1; | 4390 static const int kEntrySize = entrysize + 1; |
| 4367 static const int kChainOffset = entrysize; | 4391 static const int kChainOffset = entrysize; |
| 4368 | 4392 |
| 4369 static const int kLoadFactor = 2; | 4393 static const int kLoadFactor = 2; |
| 4370 static const int kMaxCapacity = | 4394 static const int kMaxCapacity = |
| 4371 (FixedArray::kMaxLength - kHashTableStartIndex) | 4395 (FixedArray::kMaxLength - kHashTableStartIndex) |
| 4372 / (1 + (kEntrySize * kLoadFactor)); | 4396 / (1 + (kEntrySize * kLoadFactor)); |
| 4373 }; | 4397 }; |
| 4374 | 4398 |
| 4375 | 4399 |
| 4376 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { | 4400 class JSSetIterator; |
| 4401 | |
| 4402 | |
| 4403 class OrderedHashSet: public OrderedHashTable< | |
| 4404 OrderedHashSet, JSSetIterator, 1> { | |
| 4377 public: | 4405 public: |
| 4378 static OrderedHashSet* cast(Object* obj) { | 4406 static OrderedHashSet* cast(Object* obj) { |
| 4379 ASSERT(obj->IsOrderedHashTable()); | 4407 ASSERT(obj->IsOrderedHashTable()); |
| 4380 return reinterpret_cast<OrderedHashSet*>(obj); | 4408 return reinterpret_cast<OrderedHashSet*>(obj); |
| 4381 } | 4409 } |
| 4382 | 4410 |
| 4383 bool Contains(Object* key); | 4411 bool Contains(Object* key); |
| 4384 static Handle<OrderedHashSet> Add( | 4412 static Handle<OrderedHashSet> Add( |
| 4385 Handle<OrderedHashSet> table, Handle<Object> key); | 4413 Handle<OrderedHashSet> table, Handle<Object> key); |
| 4386 static Handle<OrderedHashSet> Remove( | 4414 static Handle<OrderedHashSet> Remove( |
| 4387 Handle<OrderedHashSet> table, Handle<Object> key); | 4415 Handle<OrderedHashSet> table, Handle<Object> key); |
| 4388 }; | 4416 }; |
| 4389 | 4417 |
| 4390 | 4418 |
| 4391 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { | 4419 class JSMapIterator; |
| 4420 | |
| 4421 | |
| 4422 class OrderedHashMap:public OrderedHashTable< | |
| 4423 OrderedHashMap, JSMapIterator, 2> { | |
| 4392 public: | 4424 public: |
| 4393 static OrderedHashMap* cast(Object* obj) { | 4425 static OrderedHashMap* cast(Object* obj) { |
| 4394 ASSERT(obj->IsOrderedHashTable()); | 4426 ASSERT(obj->IsOrderedHashTable()); |
| 4395 return reinterpret_cast<OrderedHashMap*>(obj); | 4427 return reinterpret_cast<OrderedHashMap*>(obj); |
| 4396 } | 4428 } |
| 4397 | 4429 |
| 4398 Object* Lookup(Object* key); | 4430 Object* Lookup(Object* key); |
| 4399 static Handle<OrderedHashMap> Put( | 4431 static Handle<OrderedHashMap> Put( |
| 4400 Handle<OrderedHashMap> table, | 4432 Handle<OrderedHashMap> table, |
| 4401 Handle<Object> key, | 4433 Handle<Object> key, |
| (...skipping 3119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7521 static const int kContinuationOffset = kReceiverOffset + kPointerSize; | 7553 static const int kContinuationOffset = kReceiverOffset + kPointerSize; |
| 7522 static const int kOperandStackOffset = kContinuationOffset + kPointerSize; | 7554 static const int kOperandStackOffset = kContinuationOffset + kPointerSize; |
| 7523 static const int kStackHandlerIndexOffset = | 7555 static const int kStackHandlerIndexOffset = |
| 7524 kOperandStackOffset + kPointerSize; | 7556 kOperandStackOffset + kPointerSize; |
| 7525 static const int kSize = kStackHandlerIndexOffset + kPointerSize; | 7557 static const int kSize = kStackHandlerIndexOffset + kPointerSize; |
| 7526 | 7558 |
| 7527 // Resume mode, for use by runtime functions. | 7559 // Resume mode, for use by runtime functions. |
| 7528 enum ResumeMode { NEXT, THROW }; | 7560 enum ResumeMode { NEXT, THROW }; |
| 7529 | 7561 |
| 7530 // Yielding from a generator returns an object with the following inobject | 7562 // Yielding from a generator returns an object with the following inobject |
| 7531 // properties. See Context::generator_result_map() for the map. | 7563 // properties. See Context::iterator_result_map() for the map. |
| 7532 static const int kResultValuePropertyIndex = 0; | 7564 static const int kResultValuePropertyIndex = 0; |
| 7533 static const int kResultDonePropertyIndex = 1; | 7565 static const int kResultDonePropertyIndex = 1; |
| 7534 static const int kResultPropertyCount = 2; | 7566 static const int kResultPropertyCount = 2; |
| 7535 | 7567 |
| 7536 static const int kResultValuePropertyOffset = JSObject::kHeaderSize; | 7568 static const int kResultValuePropertyOffset = JSObject::kHeaderSize; |
| 7537 static const int kResultDonePropertyOffset = | 7569 static const int kResultDonePropertyOffset = |
| 7538 kResultValuePropertyOffset + kPointerSize; | 7570 kResultValuePropertyOffset + kPointerSize; |
| 7539 static const int kResultSize = kResultDonePropertyOffset + kPointerSize; | 7571 static const int kResultSize = kResultDonePropertyOffset + kPointerSize; |
| 7540 | 7572 |
| 7541 private: | 7573 private: |
| (...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9989 DECLARE_VERIFIER(JSMap) | 10021 DECLARE_VERIFIER(JSMap) |
| 9990 | 10022 |
| 9991 static const int kTableOffset = JSObject::kHeaderSize; | 10023 static const int kTableOffset = JSObject::kHeaderSize; |
| 9992 static const int kSize = kTableOffset + kPointerSize; | 10024 static const int kSize = kTableOffset + kPointerSize; |
| 9993 | 10025 |
| 9994 private: | 10026 private: |
| 9995 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); | 10027 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 9996 }; | 10028 }; |
| 9997 | 10029 |
| 9998 | 10030 |
| 10031 // OrderedHashTableIterator is an iterator that iterates over the keys and | |
| 10032 // values of an OrderedHashTable. | |
| 10033 // | |
| 10034 // The hash table has a reference to the iterator and the iterators themselves | |
| 10035 // have references to the [next_iterator] and [previous_iterator], thus creating | |
| 10036 // a double linked list. | |
| 10037 // | |
| 10038 // When the hash table changes the iterators are called to update their [index] | |
| 10039 // and [count]. The hash table calls [EntryRemoved], [TableCompacted] as well | |
| 10040 // as [TableCleared]. | |
| 10041 // | |
| 10042 // When an iterator is done it closes itself. It removes itself from the double | |
| 10043 // linked list and it sets its [table] to undefined, no longer keeping the | |
| 10044 // [table] alive. | |
| 10045 template<class Derived, class TableType> | |
| 10046 class OrderedHashTableIterator: public JSObject { | |
| 10047 public: | |
| 10048 // [table]: the backing hash table mapping keys to values. | |
| 10049 DECL_ACCESSORS(table, Object) | |
| 10050 | |
| 10051 // [index]: The index into the data table. | |
| 10052 DECL_ACCESSORS(index, Smi) | |
| 10053 | |
| 10054 // [count]: The logical index into the data table, ignoring the holes. | |
| 10055 DECL_ACCESSORS(count, Smi) | |
| 10056 | |
| 10057 // [kind]: The kind of iteration this is. One of the [Kind] enum values. | |
| 10058 DECL_ACCESSORS(kind, Smi) | |
| 10059 | |
| 10060 // [next_iterator]: Used as a double linked list for the live iterators. | |
| 10061 DECL_ACCESSORS(next_iterator, Object) | |
| 10062 | |
| 10063 // [previous_iterator]: Used as a double linked list for the live iterators. | |
| 10064 DECL_ACCESSORS(previous_iterator, Object) | |
| 10065 | |
| 10066 void OrderedHashTableIteratorPrint(FILE* out); | |
| 10067 | |
| 10068 static const int kTableOffset = JSObject::kHeaderSize; | |
| 10069 static const int kIndexOffset = kTableOffset + kPointerSize; | |
| 10070 static const int kCountOffset = kIndexOffset + kPointerSize; | |
| 10071 static const int kKindOffset = kCountOffset + kPointerSize; | |
| 10072 static const int kNextIteratorOffset = kKindOffset + kPointerSize; | |
| 10073 static const int kPreviousIteratorOffset = kNextIteratorOffset + kPointerSize; | |
| 10074 static const int kSize = kPreviousIteratorOffset + kPointerSize; | |
| 10075 | |
| 10076 enum Kind { | |
| 10077 kKindKeys = 1, | |
| 10078 kKindValues = 2, | |
| 10079 kKindEntries = 3 | |
| 10080 }; | |
| 10081 | |
| 10082 // Called by the underlying [table] when an entry is removed. | |
| 10083 void EntryRemoved(int index); | |
| 10084 | |
| 10085 // Called by the underlying [table] when it is compacted/rehashed. | |
| 10086 void TableCompacted() { | |
| 10087 // All holes have been removed so index is now same as count. | |
| 10088 set_index(count()); | |
| 10089 } | |
| 10090 | |
| 10091 // Called by the underlying [table] when it is cleared. | |
| 10092 void TableCleared() { | |
| 10093 set_index(Smi::FromInt(0)); | |
| 10094 set_count(Smi::FromInt(0)); | |
| 10095 } | |
| 10096 | |
| 10097 // Removes the iterator from the double linked list and removes its reference | |
| 10098 // back to the [table]. | |
| 10099 void Close(); | |
| 10100 | |
| 10101 // Returns an iterator result object: {value: any, done: boolean} and moves | |
| 10102 // the index to the next valid entry. Closes the iterator if moving past the | |
| 10103 // end. | |
| 10104 Handle<JSObject> Next(); | |
| 10105 | |
| 10106 private: | |
| 10107 // Ensures [index] is not pointing to a hole. | |
| 10108 void Seek(); | |
| 10109 | |
| 10110 // Moves [index] to next valid entry. Closes the iterator if moving past the | |
| 10111 // end. | |
| 10112 void MoveNext(); | |
| 10113 | |
| 10114 bool Closed() { | |
| 10115 return table()->IsUndefined(); | |
| 10116 } | |
| 10117 | |
| 10118 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); | |
| 10119 }; | |
| 10120 | |
| 10121 | |
| 10122 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, | |
| 10123 OrderedHashSet> { | |
| 10124 public: | |
| 10125 static Handle<JSSetIterator> Create(Isolate* isolate); | |
| 10126 | |
| 10127 // Dispatched behavior. | |
| 10128 DECLARE_PRINTER(JSSetIterator) | |
| 10129 DECLARE_VERIFIER(JSSetIterator) | |
| 10130 | |
| 10131 // Casting. | |
| 10132 static inline JSSetIterator* cast(Object* obj); | |
| 10133 | |
| 10134 Handle<Object> ValueForKind(int entry_index); | |
| 10135 | |
| 10136 private: | |
| 10137 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); | |
| 10138 }; | |
| 10139 | |
| 10140 | |
| 10141 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, | |
| 10142 OrderedHashMap> { | |
| 10143 public: | |
| 10144 static Handle<JSMapIterator> Create(Isolate* isolate); | |
| 10145 | |
| 10146 // Dispatched behavior. | |
| 10147 DECLARE_PRINTER(JSMapIterator) | |
| 10148 DECLARE_VERIFIER(JSMapIterator) | |
| 10149 | |
| 10150 // Casting. | |
| 10151 static inline JSMapIterator* cast(Object* obj); | |
| 10152 | |
| 10153 Handle<Object> ValueForKind(int entry_index); | |
| 10154 | |
| 10155 private: | |
| 10156 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); | |
| 10157 }; | |
| 10158 | |
| 10159 | |
| 9999 // Base class for both JSWeakMap and JSWeakSet | 10160 // Base class for both JSWeakMap and JSWeakSet |
| 10000 class JSWeakCollection: public JSObject { | 10161 class JSWeakCollection: public JSObject { |
| 10001 public: | 10162 public: |
| 10002 // [table]: the backing hash table mapping keys to values. | 10163 // [table]: the backing hash table mapping keys to values. |
| 10003 DECL_ACCESSORS(table, Object) | 10164 DECL_ACCESSORS(table, Object) |
| 10004 | 10165 |
| 10005 // [next]: linked list of encountered weak maps during GC. | 10166 // [next]: linked list of encountered weak maps during GC. |
| 10006 DECL_ACCESSORS(next, Object) | 10167 DECL_ACCESSORS(next, Object) |
| 10007 | 10168 |
| 10008 static const int kTableOffset = JSObject::kHeaderSize; | 10169 static const int kTableOffset = JSObject::kHeaderSize; |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11022 } else { | 11183 } else { |
| 11023 value &= ~(1 << bit_position); | 11184 value &= ~(1 << bit_position); |
| 11024 } | 11185 } |
| 11025 return value; | 11186 return value; |
| 11026 } | 11187 } |
| 11027 }; | 11188 }; |
| 11028 | 11189 |
| 11029 } } // namespace v8::internal | 11190 } } // namespace v8::internal |
| 11030 | 11191 |
| 11031 #endif // V8_OBJECTS_H_ | 11192 #endif // V8_OBJECTS_H_ |
| OLD | NEW |