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

Side by Side Diff: src/objects.h

Issue 2430273007: [runtime] Object.create(null) creates a slow object (Closed)
Patch Set: addressing comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #include <memory> 9 #include <memory>
10 10
(...skipping 3464 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 // as keys and can be used to indicate missing or deleted elements. 3475 // as keys and can be used to indicate missing or deleted elements.
3476 inline bool IsKey(Object* k); 3476 inline bool IsKey(Object* k);
3477 inline bool IsKey(Isolate* isolate, Object* k); 3477 inline bool IsKey(Isolate* isolate, Object* k);
3478 3478
3479 // Compute the probe offset (quadratic probing). 3479 // Compute the probe offset (quadratic probing).
3480 INLINE(static uint32_t GetProbeOffset(uint32_t n)) { 3480 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
3481 return (n + n * n) >> 1; 3481 return (n + n * n) >> 1;
3482 } 3482 }
3483 3483
3484 static const int kNumberOfElementsIndex = 0; 3484 static const int kNumberOfElementsIndex = 0;
3485 static const int kNumberOfElementsOffset = kHeaderSize;
3485 static const int kNumberOfDeletedElementsIndex = 1; 3486 static const int kNumberOfDeletedElementsIndex = 1;
3487 static const int kNumberOfDeletedElementsOffset =
3488 kNumberOfElementsOffset + kPointerSize;
3486 static const int kCapacityIndex = 2; 3489 static const int kCapacityIndex = 2;
3490 static const int kCapacityOffset =
3491 kNumberOfDeletedElementsOffset + kPointerSize;
3487 static const int kPrefixStartIndex = 3; 3492 static const int kPrefixStartIndex = 3;
3493 static const int kPrefixStartOffset = kCapacityOffset + kPointerSize;
Igor Sheludko 2016/10/21 15:01:10 I think you can remove these *Offset constants.
Camillo Bruni 2016/10/21 16:27:32 thought I did ;)
3488 3494
3489 // Constant used for denoting a absent entry. 3495 // Constant used for denoting a absent entry.
3490 static const int kNotFound = -1; 3496 static const int kNotFound = -1;
3491 3497
3498 // Minimum capacity for newly created hash tables.
3499 static const int kMinCapacity = 4;
3500
3492 protected: 3501 protected:
3493 // Update the number of elements in the hash table. 3502 // Update the number of elements in the hash table.
3494 inline void SetNumberOfElements(int nof); 3503 inline void SetNumberOfElements(int nof);
3495 3504
3496 // Update the number of deleted elements in the hash table. 3505 // Update the number of deleted elements in the hash table.
3497 inline void SetNumberOfDeletedElements(int nod); 3506 inline void SetNumberOfDeletedElements(int nod);
3498 3507
3499 // Returns probe entry. 3508 // Returns probe entry.
3500 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { 3509 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
3501 DCHECK(base::bits::IsPowerOfTwo32(size)); 3510 DCHECK(base::bits::IsPowerOfTwo32(size));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3559 3568
3560 // Returns the key at entry. 3569 // Returns the key at entry.
3561 Object* KeyAt(int entry) { return get(EntryToIndex(entry) + kEntryKeyIndex); } 3570 Object* KeyAt(int entry) { return get(EntryToIndex(entry) + kEntryKeyIndex); }
3562 3571
3563 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; 3572 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
3564 static const int kEntrySize = Shape::kEntrySize; 3573 static const int kEntrySize = Shape::kEntrySize;
3565 STATIC_ASSERT(kEntrySize > 0); 3574 STATIC_ASSERT(kEntrySize > 0);
3566 static const int kEntryKeyIndex = 0; 3575 static const int kEntryKeyIndex = 0;
3567 static const int kElementsStartOffset = 3576 static const int kElementsStartOffset =
3568 kHeaderSize + kElementsStartIndex * kPointerSize; 3577 kHeaderSize + kElementsStartIndex * kPointerSize;
3569 static const int kCapacityOffset = 3578 // Maximal capacity of HashTable. Based on maximal length of underlying
3570 kHeaderSize + kCapacityIndex * kPointerSize; 3579 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
3580 // cannot overflow.
3581 static const int kMaxCapacity =
3582 (FixedArray::kMaxLength - kElementsStartIndex) / kEntrySize;
Camillo Bruni 2016/10/21 13:37:15 Note: I change kElementsStartOffset to kElementsSt
3571 3583
3572 // Returns the index for an entry (of the key) 3584 // Returns the index for an entry (of the key)
3573 static inline int EntryToIndex(int entry) { 3585 static inline int EntryToIndex(int entry) {
3574 return (entry * kEntrySize) + kElementsStartIndex; 3586 return (entry * kEntrySize) + kElementsStartIndex;
3575 } 3587 }
3576 3588
3577 protected: 3589 protected:
3578 friend class ObjectHashTable; 3590 friend class ObjectHashTable;
3579 3591
3580 // Find the entry at which to insert element with the given key that 3592 // Find the entry at which to insert element with the given key that
(...skipping 16 matching lines...) Expand all
3597 // Sets the capacity of the hash table. 3609 // Sets the capacity of the hash table.
3598 void SetCapacity(int capacity) { 3610 void SetCapacity(int capacity) {
3599 // To scale a computed hash code to fit within the hash table, we 3611 // To scale a computed hash code to fit within the hash table, we
3600 // use bit-wise AND with a mask, so the capacity must be positive 3612 // use bit-wise AND with a mask, so the capacity must be positive
3601 // and non-zero. 3613 // and non-zero.
3602 DCHECK(capacity > 0); 3614 DCHECK(capacity > 0);
3603 DCHECK(capacity <= kMaxCapacity); 3615 DCHECK(capacity <= kMaxCapacity);
3604 set(kCapacityIndex, Smi::FromInt(capacity)); 3616 set(kCapacityIndex, Smi::FromInt(capacity));
3605 } 3617 }
3606 3618
3607 // Maximal capacity of HashTable. Based on maximal length of underlying
3608 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
3609 // cannot overflow.
3610 static const int kMaxCapacity =
3611 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
3612
3613 private: 3619 private:
3614 // Returns _expected_ if one of entries given by the first _probe_ probes is 3620 // Returns _expected_ if one of entries given by the first _probe_ probes is
3615 // equal to _expected_. Otherwise, returns the entry given by the probe 3621 // equal to _expected_. Otherwise, returns the entry given by the probe
3616 // number _probe_. 3622 // number _probe_.
3617 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); 3623 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
3618 3624
3619 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); 3625 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
3620 3626
3621 // Rehashes this hash-table into the new table. 3627 // Rehashes this hash-table into the new table.
3622 void Rehash(Handle<Derived> new_table, Key key); 3628 void Rehash(Handle<Derived> new_table, Key key);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3831 MUST_USE_RESULT static Handle<Derived> Add(Handle<Derived> dictionary, 3837 MUST_USE_RESULT static Handle<Derived> Add(Handle<Derived> dictionary,
3832 Key key, Handle<Object> value, 3838 Key key, Handle<Object> value,
3833 PropertyDetails details, 3839 PropertyDetails details,
3834 int* entry_out = nullptr); 3840 int* entry_out = nullptr);
3835 3841
3836 // Returns iteration indices array for the |dictionary|. 3842 // Returns iteration indices array for the |dictionary|.
3837 // Values are direct indices in the |HashTable| array. 3843 // Values are direct indices in the |HashTable| array.
3838 static Handle<FixedArray> BuildIterationIndicesArray( 3844 static Handle<FixedArray> BuildIterationIndicesArray(
3839 Handle<Derived> dictionary); 3845 Handle<Derived> dictionary);
3840 3846
3847 // Generate new enumeration indices to avoid enumeration index overflow.
3848 // Returns iteration indices array for the |dictionary|.
3849 static Handle<FixedArray> GenerateNewEnumerationIndices(
3850 Handle<Derived> dictionary);
3851 static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
3852 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3853
3841 protected: 3854 protected:
3842 // Generic at put operation. 3855 // Generic at put operation.
3843 MUST_USE_RESULT static Handle<Derived> AtPut( 3856 MUST_USE_RESULT static Handle<Derived> AtPut(
3844 Handle<Derived> dictionary, 3857 Handle<Derived> dictionary,
3845 Key key, 3858 Key key,
3846 Handle<Object> value); 3859 Handle<Object> value);
3847 3860
3848 // Add entry to dictionary. Returns entry value. 3861 // Add entry to dictionary. Returns entry value.
3849 static int AddEntry(Handle<Derived> dictionary, Key key, Handle<Object> value, 3862 static int AddEntry(Handle<Derived> dictionary, Key key, Handle<Object> value,
3850 PropertyDetails details, uint32_t hash); 3863 PropertyDetails details, uint32_t hash);
3851
3852 // Generate new enumeration indices to avoid enumeration index overflow.
3853 // Returns iteration indices array for the |dictionary|.
3854 static Handle<FixedArray> GenerateNewEnumerationIndices(
3855 Handle<Derived> dictionary);
3856 static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
3857 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3858 }; 3864 };
3859 3865
3860 3866
3861 template <typename Derived, typename Shape> 3867 template <typename Derived, typename Shape>
3862 class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > { 3868 class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > {
3863 typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary; 3869 typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary;
3864 3870
3865 public: 3871 public:
3866 // Find entry for key, otherwise return kNotFound. Optimized version of 3872 // Find entry for key, otherwise return kNotFound. Optimized version of
3867 // HashTable::FindEntry. 3873 // HashTable::FindEntry.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 DerivedDictionary; 3925 DerivedDictionary;
3920 3926
3921 public: 3927 public:
3922 DECLARE_CAST(NameDictionary) 3928 DECLARE_CAST(NameDictionary)
3923 3929
3924 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( 3930 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices(
3925 Handle<NameDictionary> dictionary); 3931 Handle<NameDictionary> dictionary);
3926 3932
3927 static const int kEntryValueIndex = 1; 3933 static const int kEntryValueIndex = 1;
3928 static const int kEntryDetailsIndex = 2; 3934 static const int kEntryDetailsIndex = 2;
3935 static const int kInitialCapacity = 2;
3929 }; 3936 };
3930 3937
3931 3938
3932 class GlobalDictionaryShape : public NameDictionaryShape { 3939 class GlobalDictionaryShape : public NameDictionaryShape {
3933 public: 3940 public:
3934 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize 3941 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize
3935 3942
3936 template <typename Dictionary> 3943 template <typename Dictionary>
3937 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); 3944 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry);
3938 3945
(...skipping 7791 matching lines...) Expand 10 before | Expand all | Expand 10 after
11730 } 11737 }
11731 return value; 11738 return value;
11732 } 11739 }
11733 }; 11740 };
11734 11741
11735 11742
11736 } // NOLINT, false-positive due to second-order macros. 11743 } // NOLINT, false-positive due to second-order macros.
11737 } // NOLINT, false-positive due to second-order macros. 11744 } // NOLINT, false-positive due to second-order macros.
11738 11745
11739 #endif // V8_OBJECTS_H_ 11746 #endif // V8_OBJECTS_H_
OLDNEW
« src/code-stub-assembler.cc ('K') | « src/contexts.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698