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