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 3450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3461 // Returns the key at entry. | 3461 // Returns the key at entry. |
3462 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3462 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
3463 | 3463 |
3464 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; | 3464 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; |
3465 static const int kEntrySize = Shape::kEntrySize; | 3465 static const int kEntrySize = Shape::kEntrySize; |
3466 static const int kElementsStartOffset = | 3466 static const int kElementsStartOffset = |
3467 kHeaderSize + kElementsStartIndex * kPointerSize; | 3467 kHeaderSize + kElementsStartIndex * kPointerSize; |
3468 static const int kCapacityOffset = | 3468 static const int kCapacityOffset = |
3469 kHeaderSize + kCapacityIndex * kPointerSize; | 3469 kHeaderSize + kCapacityIndex * kPointerSize; |
3470 | 3470 |
| 3471 // Returns the index for an entry (of the key) |
| 3472 static inline int EntryToIndex(int entry) { |
| 3473 return (entry * kEntrySize) + kElementsStartIndex; |
| 3474 } |
| 3475 |
3471 protected: | 3476 protected: |
3472 friend class ObjectHashTable; | 3477 friend class ObjectHashTable; |
3473 | 3478 |
3474 // Find the entry at which to insert element with the given key that | 3479 // Find the entry at which to insert element with the given key that |
3475 // has the given hash value. | 3480 // has the given hash value. |
3476 uint32_t FindInsertionEntry(uint32_t hash); | 3481 uint32_t FindInsertionEntry(uint32_t hash); |
3477 | 3482 |
3478 // Attempt to shrink hash table after removal of key. | 3483 // Attempt to shrink hash table after removal of key. |
3479 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); | 3484 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
3480 | 3485 |
3481 // Ensure enough space for n additional elements. | 3486 // Ensure enough space for n additional elements. |
3482 MUST_USE_RESULT static Handle<Derived> EnsureCapacity( | 3487 MUST_USE_RESULT static Handle<Derived> EnsureCapacity( |
3483 Handle<Derived> table, | 3488 Handle<Derived> table, |
3484 int n, | 3489 int n, |
3485 Key key, | 3490 Key key, |
3486 PretenureFlag pretenure = NOT_TENURED); | 3491 PretenureFlag pretenure = NOT_TENURED); |
3487 | 3492 |
3488 // Returns the index for an entry (of the key) | |
3489 static inline int EntryToIndex(int entry) { | |
3490 return (entry * kEntrySize) + kElementsStartIndex; | |
3491 } | |
3492 | |
3493 // Sets the capacity of the hash table. | 3493 // Sets the capacity of the hash table. |
3494 void SetCapacity(int capacity) { | 3494 void SetCapacity(int capacity) { |
3495 // To scale a computed hash code to fit within the hash table, we | 3495 // To scale a computed hash code to fit within the hash table, we |
3496 // use bit-wise AND with a mask, so the capacity must be positive | 3496 // use bit-wise AND with a mask, so the capacity must be positive |
3497 // and non-zero. | 3497 // and non-zero. |
3498 DCHECK(capacity > 0); | 3498 DCHECK(capacity > 0); |
3499 DCHECK(capacity <= kMaxCapacity); | 3499 DCHECK(capacity <= kMaxCapacity); |
3500 set(kCapacityIndex, Smi::FromInt(capacity)); | 3500 set(kCapacityIndex, Smi::FromInt(capacity)); |
3501 } | 3501 } |
3502 | 3502 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3608 return this->get(Derived::EntryToIndex(entry) + 1); | 3608 return this->get(Derived::EntryToIndex(entry) + 1); |
3609 } | 3609 } |
3610 | 3610 |
3611 // Set the value for entry. | 3611 // Set the value for entry. |
3612 void ValueAtPut(int entry, Object* value) { | 3612 void ValueAtPut(int entry, Object* value) { |
3613 this->set(Derived::EntryToIndex(entry) + 1, value); | 3613 this->set(Derived::EntryToIndex(entry) + 1, value); |
3614 } | 3614 } |
3615 | 3615 |
3616 // Returns the property details for the property at entry. | 3616 // Returns the property details for the property at entry. |
3617 PropertyDetails DetailsAt(int entry) { | 3617 PropertyDetails DetailsAt(int entry) { |
3618 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). | 3618 return Shape::DetailsAt(static_cast<Derived*>(this), entry); |
3619 return PropertyDetails( | |
3620 Smi::cast(this->get(Derived::EntryToIndex(entry) + 2))); | |
3621 } | 3619 } |
3622 | 3620 |
3623 // Set the details for entry. | 3621 // Set the details for entry. |
3624 void DetailsAtPut(int entry, PropertyDetails value) { | 3622 void DetailsAtPut(int entry, PropertyDetails value) { |
3625 this->set(Derived::EntryToIndex(entry) + 2, value.AsSmi()); | 3623 Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value); |
3626 } | 3624 } |
3627 | 3625 |
3628 // Returns true if property at given entry is deleted. | 3626 // Returns true if property at given entry is deleted. |
3629 bool IsDeleted(int entry) { | 3627 bool IsDeleted(int entry) { |
3630 return Shape::IsDeleted(static_cast<Derived*>(this), entry); | 3628 return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
3631 } | 3629 } |
3632 | 3630 |
3633 // Delete a property from the dictionary. | 3631 // Delete a property from the dictionary. |
3634 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); | 3632 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
3635 | 3633 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3748 // Find entry for key, otherwise return kNotFound. Optimized version of | 3746 // Find entry for key, otherwise return kNotFound. Optimized version of |
3749 // HashTable::FindEntry. | 3747 // HashTable::FindEntry. |
3750 int FindEntry(Handle<Name> key); | 3748 int FindEntry(Handle<Name> key); |
3751 }; | 3749 }; |
3752 | 3750 |
3753 | 3751 |
3754 template <typename Key> | 3752 template <typename Key> |
3755 class BaseDictionaryShape : public BaseShape<Key> { | 3753 class BaseDictionaryShape : public BaseShape<Key> { |
3756 public: | 3754 public: |
3757 template <typename Dictionary> | 3755 template <typename Dictionary> |
| 3756 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { |
| 3757 STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3758 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
| 3759 return PropertyDetails( |
| 3760 Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2))); |
| 3761 } |
| 3762 |
| 3763 template <typename Dictionary> |
| 3764 static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3765 PropertyDetails value) { |
| 3766 STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3767 dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi()); |
| 3768 } |
| 3769 |
| 3770 template <typename Dictionary> |
3758 static bool IsDeleted(Dictionary* dict, int entry) { | 3771 static bool IsDeleted(Dictionary* dict, int entry) { |
3759 return false; | 3772 return false; |
3760 } | 3773 } |
| 3774 |
| 3775 template <typename Dictionary> |
| 3776 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3777 Handle<Object> value, PropertyDetails details); |
3761 }; | 3778 }; |
3762 | 3779 |
3763 | 3780 |
3764 class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { | 3781 class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { |
3765 public: | 3782 public: |
3766 static inline bool IsMatch(Handle<Name> key, Object* other); | 3783 static inline bool IsMatch(Handle<Name> key, Object* other); |
3767 static inline uint32_t Hash(Handle<Name> key); | 3784 static inline uint32_t Hash(Handle<Name> key); |
3768 static inline uint32_t HashForObject(Handle<Name> key, Object* object); | 3785 static inline uint32_t HashForObject(Handle<Name> key, Object* object); |
3769 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); | 3786 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); |
3770 static const int kPrefixSize = 2; | 3787 static const int kPrefixSize = 2; |
(...skipping 10 matching lines...) Expand all Loading... |
3781 public: | 3798 public: |
3782 DECLARE_CAST(NameDictionary) | 3799 DECLARE_CAST(NameDictionary) |
3783 | 3800 |
3784 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( | 3801 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
3785 Handle<NameDictionary> dictionary); | 3802 Handle<NameDictionary> dictionary); |
3786 }; | 3803 }; |
3787 | 3804 |
3788 | 3805 |
3789 class GlobalDictionaryShape : public NameDictionaryShape { | 3806 class GlobalDictionaryShape : public NameDictionaryShape { |
3790 public: | 3807 public: |
3791 static const int kEntrySize = 3; // Overrides NameDictionaryShape::kEntrySize | 3808 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize |
| 3809 |
| 3810 template <typename Dictionary> |
| 3811 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); |
| 3812 |
| 3813 template <typename Dictionary> |
| 3814 static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3815 PropertyDetails value); |
3792 | 3816 |
3793 template <typename Dictionary> | 3817 template <typename Dictionary> |
3794 static bool IsDeleted(Dictionary* dict, int entry); | 3818 static bool IsDeleted(Dictionary* dict, int entry); |
| 3819 |
| 3820 template <typename Dictionary> |
| 3821 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3822 Handle<Object> value, PropertyDetails details); |
3795 }; | 3823 }; |
3796 | 3824 |
3797 | 3825 |
3798 class GlobalDictionary | 3826 class GlobalDictionary |
3799 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { | 3827 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { |
3800 public: | 3828 public: |
3801 DECLARE_CAST(GlobalDictionary) | 3829 DECLARE_CAST(GlobalDictionary) |
3802 }; | 3830 }; |
3803 | 3831 |
3804 | 3832 |
(...skipping 6078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9883 kValueOffset + kPointerSize, | 9911 kValueOffset + kPointerSize, |
9884 kSize> BodyDescriptor; | 9912 kSize> BodyDescriptor; |
9885 | 9913 |
9886 private: | 9914 private: |
9887 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); | 9915 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); |
9888 }; | 9916 }; |
9889 | 9917 |
9890 | 9918 |
9891 class PropertyCell : public HeapObject { | 9919 class PropertyCell : public HeapObject { |
9892 public: | 9920 public: |
| 9921 // [property_details]: details of the global property. |
| 9922 DECL_ACCESSORS(property_details_raw, Object) |
9893 // [value]: value of the global property. | 9923 // [value]: value of the global property. |
9894 DECL_ACCESSORS(value, Object) | 9924 DECL_ACCESSORS(value, Object) |
9895 // [dependent_code]: dependent code that depends on the type of the global | 9925 // [dependent_code]: dependent code that depends on the type of the global |
9896 // property. | 9926 // property. |
9897 DECL_ACCESSORS(dependent_code, DependentCode) | 9927 DECL_ACCESSORS(dependent_code, DependentCode) |
9898 | 9928 |
| 9929 PropertyDetails property_details() { |
| 9930 return PropertyDetails(Smi::cast(property_details_raw())); |
| 9931 } |
| 9932 |
| 9933 void set_property_details(PropertyDetails details) { |
| 9934 set_property_details_raw(details.AsSmi()); |
| 9935 } |
| 9936 |
9899 PropertyCellConstantType GetConstantType(); | 9937 PropertyCellConstantType GetConstantType(); |
9900 | 9938 |
9901 // Computes the new type of the cell's contents for the given value, but | 9939 // Computes the new type of the cell's contents for the given value, but |
9902 // without actually modifying the details. | 9940 // without actually modifying the details. |
9903 static PropertyCellType UpdatedType(Handle<PropertyCell> cell, | 9941 static PropertyCellType UpdatedType(Handle<PropertyCell> cell, |
9904 Handle<Object> value, | 9942 Handle<Object> value, |
9905 PropertyDetails details); | 9943 PropertyDetails details); |
9906 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, | 9944 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, |
9907 Handle<Object> value, PropertyDetails details); | 9945 Handle<Object> value, PropertyDetails details); |
9908 | 9946 |
9909 static Handle<PropertyCell> InvalidateEntry( | 9947 static Handle<PropertyCell> InvalidateEntry( |
9910 Handle<GlobalDictionary> dictionary, int entry); | 9948 Handle<GlobalDictionary> dictionary, int entry); |
9911 | 9949 |
9912 static void SetValueWithInvalidation(Handle<PropertyCell> cell, | 9950 static void SetValueWithInvalidation(Handle<PropertyCell> cell, |
9913 Handle<Object> new_value); | 9951 Handle<Object> new_value); |
9914 | 9952 |
9915 DECLARE_CAST(PropertyCell) | 9953 DECLARE_CAST(PropertyCell) |
9916 | 9954 |
9917 // Dispatched behavior. | 9955 // Dispatched behavior. |
9918 DECLARE_PRINTER(PropertyCell) | 9956 DECLARE_PRINTER(PropertyCell) |
9919 DECLARE_VERIFIER(PropertyCell) | 9957 DECLARE_VERIFIER(PropertyCell) |
9920 | 9958 |
9921 // Layout description. | 9959 // Layout description. |
9922 static const int kValueOffset = HeapObject::kHeaderSize; | 9960 static const int kDetailsOffset = HeapObject::kHeaderSize; |
| 9961 static const int kValueOffset = kDetailsOffset + kPointerSize; |
9923 static const int kDependentCodeOffset = kValueOffset + kPointerSize; | 9962 static const int kDependentCodeOffset = kValueOffset + kPointerSize; |
9924 static const int kSize = kDependentCodeOffset + kPointerSize; | 9963 static const int kSize = kDependentCodeOffset + kPointerSize; |
9925 | 9964 |
9926 static const int kPointerFieldsBeginOffset = kValueOffset; | 9965 static const int kPointerFieldsBeginOffset = kValueOffset; |
9927 static const int kPointerFieldsEndOffset = kSize; | 9966 static const int kPointerFieldsEndOffset = kSize; |
9928 | 9967 |
9929 typedef FixedBodyDescriptor<kValueOffset, | 9968 typedef FixedBodyDescriptor<kValueOffset, |
9930 kSize, | 9969 kSize, |
9931 kSize> BodyDescriptor; | 9970 kSize> BodyDescriptor; |
9932 | 9971 |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11170 } else { | 11209 } else { |
11171 value &= ~(1 << bit_position); | 11210 value &= ~(1 << bit_position); |
11172 } | 11211 } |
11173 return value; | 11212 return value; |
11174 } | 11213 } |
11175 }; | 11214 }; |
11176 | 11215 |
11177 } } // namespace v8::internal | 11216 } } // namespace v8::internal |
11178 | 11217 |
11179 #endif // V8_OBJECTS_H_ | 11218 #endif // V8_OBJECTS_H_ |
OLD | NEW |