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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
| 6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 2454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2465 // Gives access to raw memory which stores the array's data. | 2465 // Gives access to raw memory which stores the array's data. |
| 2466 inline Object** data_start(); | 2466 inline Object** data_start(); |
| 2467 | 2467 |
| 2468 inline void FillWithHoles(int from, int to); | 2468 inline void FillWithHoles(int from, int to); |
| 2469 | 2469 |
| 2470 // Shrink length and insert filler objects. | 2470 // Shrink length and insert filler objects. |
| 2471 void Shrink(int length); | 2471 void Shrink(int length); |
| 2472 | 2472 |
| 2473 enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS }; | 2473 enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS }; |
| 2474 | 2474 |
| 2475 // Add the elements of a JSArray to this FixedArray. | |
| 2476 MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromArrayLike( | |
| 2477 Handle<FixedArray> content, Handle<JSObject> array, | |
| 2478 KeyFilter filter = ALL_KEYS); | |
| 2479 | |
| 2480 // Computes the union of keys and return the result. | |
| 2481 // Used for implementing "for (n in object) { }" | |
| 2482 MUST_USE_RESULT static MaybeHandle<FixedArray> UnionOfKeys( | |
| 2483 Handle<FixedArray> first, | |
| 2484 Handle<FixedArray> second); | |
| 2485 | |
| 2486 // Copy a sub array from the receiver to dest. | 2475 // Copy a sub array from the receiver to dest. |
| 2487 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); | 2476 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2488 | 2477 |
| 2489 // Garbage collection support. | 2478 // Garbage collection support. |
| 2490 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } | 2479 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2491 | 2480 |
| 2492 // Code Generation support. | 2481 // Code Generation support. |
| 2493 static int OffsetOfElementAt(int index) { return SizeFor(index); } | 2482 static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2494 | 2483 |
| 2495 // Garbage collection support. | 2484 // Garbage collection support. |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3654 static Handle<Derived> EnsureGrowable(Handle<Derived> table); | 3643 static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
| 3655 | 3644 |
| 3656 // Returns an OrderedHashTable (possibly |table|) that's shrunken | 3645 // Returns an OrderedHashTable (possibly |table|) that's shrunken |
| 3657 // if possible. | 3646 // if possible. |
| 3658 static Handle<Derived> Shrink(Handle<Derived> table); | 3647 static Handle<Derived> Shrink(Handle<Derived> table); |
| 3659 | 3648 |
| 3660 // Returns a new empty OrderedHashTable and records the clearing so that | 3649 // Returns a new empty OrderedHashTable and records the clearing so that |
| 3661 // exisiting iterators can be updated. | 3650 // exisiting iterators can be updated. |
| 3662 static Handle<Derived> Clear(Handle<Derived> table); | 3651 static Handle<Derived> Clear(Handle<Derived> table); |
| 3663 | 3652 |
| 3653 // Returns a true if the OrderedHashTable contains the key | |
| 3654 static bool HasKey(Handle<Derived> table, Handle<Object> key); | |
| 3655 | |
| 3664 int NumberOfElements() { | 3656 int NumberOfElements() { |
| 3665 return Smi::cast(get(kNumberOfElementsIndex))->value(); | 3657 return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 3666 } | 3658 } |
| 3667 | 3659 |
| 3668 int NumberOfDeletedElements() { | 3660 int NumberOfDeletedElements() { |
| 3669 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); | 3661 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 3670 } | 3662 } |
| 3671 | 3663 |
| 3672 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } | 3664 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 3673 | 3665 |
| 3674 int NumberOfBuckets() { | 3666 int NumberOfBuckets() { |
| 3675 return Smi::cast(get(kNumberOfBucketsIndex))->value(); | 3667 return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 3676 } | 3668 } |
| 3677 | 3669 |
| 3678 // Returns an index into |this| for the given entry. | 3670 // Returns an index into |this| for the given entry. |
| 3679 int EntryToIndex(int entry) { | 3671 int EntryToIndex(int entry) { |
| 3680 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); | 3672 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
| 3681 } | 3673 } |
| 3682 | 3674 |
| 3675 int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); } | |
| 3676 | |
| 3677 int HashToEntry(int hash) { | |
| 3678 int bucket = HashToBucket(hash); | |
| 3679 Object* entry = this->get(kHashTableStartIndex + bucket); | |
| 3680 return Smi::cast(entry)->value(); | |
| 3681 } | |
| 3682 | |
| 3683 int KeyToFirstEntry(Object* key) { | |
| 3684 Object* hash = key->GetHash(); | |
| 3685 // If the object does not have an identity hash, it was never used as a key | |
| 3686 if (hash->IsUndefined()) return kNotFound; | |
| 3687 return HashToEntry(Smi::cast(hash)->value()); | |
| 3688 } | |
| 3689 | |
| 3690 int NextChainEntry(int entry) { | |
| 3691 Object* next_entry = get(EntryToIndex(entry) + entrysize); | |
|
Igor Sheludko
2015/09/17 09:55:12
s/entrysize/kChainOffset/g (for readability).
| |
| 3692 return Smi::cast(next_entry)->value(); | |
| 3693 } | |
|
Igor Sheludko
2015/09/17 09:55:12
Please add a blank line here.
| |
| 3683 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3694 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3684 | 3695 |
| 3685 bool IsObsolete() { | 3696 bool IsObsolete() { |
| 3686 return !get(kNextTableIndex)->IsSmi(); | 3697 return !get(kNextTableIndex)->IsSmi(); |
| 3687 } | 3698 } |
| 3688 | 3699 |
| 3689 // The next newer table. This is only valid if the table is obsolete. | 3700 // The next newer table. This is only valid if the table is obsolete. |
| 3690 Derived* NextTable() { | 3701 Derived* NextTable() { |
| 3691 return Derived::cast(get(kNextTableIndex)); | 3702 return Derived::cast(get(kNextTableIndex)); |
| 3692 } | 3703 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 3719 static const int kEntrySize = entrysize + 1; | 3730 static const int kEntrySize = entrysize + 1; |
| 3720 static const int kChainOffset = entrysize; | 3731 static const int kChainOffset = entrysize; |
| 3721 | 3732 |
| 3722 static const int kLoadFactor = 2; | 3733 static const int kLoadFactor = 2; |
| 3723 | 3734 |
| 3724 // NumberOfDeletedElements is set to kClearedTableSentinel when | 3735 // NumberOfDeletedElements is set to kClearedTableSentinel when |
| 3725 // the table is cleared, which allows iterator transitions to | 3736 // the table is cleared, which allows iterator transitions to |
| 3726 // optimize that case. | 3737 // optimize that case. |
| 3727 static const int kClearedTableSentinel = -1; | 3738 static const int kClearedTableSentinel = -1; |
| 3728 | 3739 |
| 3729 private: | 3740 protected: |
| 3730 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); | 3741 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
| 3731 | 3742 |
| 3732 void SetNumberOfBuckets(int num) { | 3743 void SetNumberOfBuckets(int num) { |
| 3733 set(kNumberOfBucketsIndex, Smi::FromInt(num)); | 3744 set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
| 3734 } | 3745 } |
| 3735 | 3746 |
| 3736 void SetNumberOfElements(int num) { | 3747 void SetNumberOfElements(int num) { |
| 3737 set(kNumberOfElementsIndex, Smi::FromInt(num)); | 3748 set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 3738 } | 3749 } |
| 3739 | 3750 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 3761 }; | 3772 }; |
| 3762 | 3773 |
| 3763 | 3774 |
| 3764 class JSSetIterator; | 3775 class JSSetIterator; |
| 3765 | 3776 |
| 3766 | 3777 |
| 3767 class OrderedHashSet: public OrderedHashTable< | 3778 class OrderedHashSet: public OrderedHashTable< |
| 3768 OrderedHashSet, JSSetIterator, 1> { | 3779 OrderedHashSet, JSSetIterator, 1> { |
| 3769 public: | 3780 public: |
| 3770 DECLARE_CAST(OrderedHashSet) | 3781 DECLARE_CAST(OrderedHashSet) |
| 3782 | |
| 3783 static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table, | |
| 3784 Handle<Object> value); | |
| 3771 }; | 3785 }; |
| 3772 | 3786 |
| 3773 | 3787 |
| 3774 class JSMapIterator; | 3788 class JSMapIterator; |
| 3775 | 3789 |
| 3776 | 3790 |
| 3777 class OrderedHashMap | 3791 class OrderedHashMap |
| 3778 : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> { | 3792 : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> { |
| 3779 public: | 3793 public: |
| 3780 DECLARE_CAST(OrderedHashMap) | 3794 DECLARE_CAST(OrderedHashMap) |
| (...skipping 6689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10470 static inline int set(int value, int bit_position, bool v) { | 10484 static inline int set(int value, int bit_position, bool v) { |
| 10471 if (v) { | 10485 if (v) { |
| 10472 value |= (1 << bit_position); | 10486 value |= (1 << bit_position); |
| 10473 } else { | 10487 } else { |
| 10474 value &= ~(1 << bit_position); | 10488 value &= ~(1 << bit_position); |
| 10475 } | 10489 } |
| 10476 return value; | 10490 return value; |
| 10477 } | 10491 } |
| 10478 }; | 10492 }; |
| 10479 | 10493 |
| 10494 | |
| 10495 class KeyAccumulator final BASE_EMBEDDED { | |
| 10496 public: | |
| 10497 explicit KeyAccumulator(Isolate* isolate) | |
| 10498 : isolate_(isolate), keys_(), set_(), length_(0) {} | |
| 10499 | |
| 10500 void AddKey(Handle<Object> key, int check_limit); | |
| 10501 void AddKeys(Handle<FixedArray> array, FixedArray::KeyFilter filter); | |
| 10502 void AddKeys(Handle<JSObject> array, FixedArray::KeyFilter filter); | |
| 10503 void PrepareForComparisons(int count); | |
| 10504 int GetLength(); | |
| 10505 Handle<FixedArray> GetKeys(); | |
| 10506 | |
| 10507 private: | |
| 10508 void EnsureCapacity(int capacity); | |
| 10509 void Grow(); | |
| 10510 | |
| 10511 Isolate* isolate_; | |
| 10512 Handle<FixedArray> keys_; | |
| 10513 Handle<OrderedHashSet> set_; | |
| 10514 int length_; | |
| 10515 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | |
| 10516 }; | |
| 10480 } } // namespace v8::internal | 10517 } } // namespace v8::internal |
| 10481 | 10518 |
| 10482 #endif // V8_OBJECTS_H_ | 10519 #endif // V8_OBJECTS_H_ |
| OLD | NEW |