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 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3452 // Returns the key at entry. | 3452 // Returns the key at entry. |
3453 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3453 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
3454 | 3454 |
3455 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; | 3455 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; |
3456 static const int kEntrySize = Shape::kEntrySize; | 3456 static const int kEntrySize = Shape::kEntrySize; |
3457 static const int kElementsStartOffset = | 3457 static const int kElementsStartOffset = |
3458 kHeaderSize + kElementsStartIndex * kPointerSize; | 3458 kHeaderSize + kElementsStartIndex * kPointerSize; |
3459 static const int kCapacityOffset = | 3459 static const int kCapacityOffset = |
3460 kHeaderSize + kCapacityIndex * kPointerSize; | 3460 kHeaderSize + kCapacityIndex * kPointerSize; |
3461 | 3461 |
| 3462 // Returns the index for an entry (of the key) |
| 3463 static inline int EntryToIndex(int entry) { |
| 3464 return (entry * kEntrySize) + kElementsStartIndex; |
| 3465 } |
| 3466 |
3462 protected: | 3467 protected: |
3463 friend class ObjectHashTable; | 3468 friend class ObjectHashTable; |
3464 | 3469 |
3465 // Find the entry at which to insert element with the given key that | 3470 // Find the entry at which to insert element with the given key that |
3466 // has the given hash value. | 3471 // has the given hash value. |
3467 uint32_t FindInsertionEntry(uint32_t hash); | 3472 uint32_t FindInsertionEntry(uint32_t hash); |
3468 | 3473 |
3469 // Attempt to shrink hash table after removal of key. | 3474 // Attempt to shrink hash table after removal of key. |
3470 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); | 3475 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
3471 | 3476 |
3472 // Ensure enough space for n additional elements. | 3477 // Ensure enough space for n additional elements. |
3473 MUST_USE_RESULT static Handle<Derived> EnsureCapacity( | 3478 MUST_USE_RESULT static Handle<Derived> EnsureCapacity( |
3474 Handle<Derived> table, | 3479 Handle<Derived> table, |
3475 int n, | 3480 int n, |
3476 Key key, | 3481 Key key, |
3477 PretenureFlag pretenure = NOT_TENURED); | 3482 PretenureFlag pretenure = NOT_TENURED); |
3478 | 3483 |
3479 // Returns the index for an entry (of the key) | |
3480 static inline int EntryToIndex(int entry) { | |
3481 return (entry * kEntrySize) + kElementsStartIndex; | |
3482 } | |
3483 | |
3484 // Sets the capacity of the hash table. | 3484 // Sets the capacity of the hash table. |
3485 void SetCapacity(int capacity) { | 3485 void SetCapacity(int capacity) { |
3486 // To scale a computed hash code to fit within the hash table, we | 3486 // To scale a computed hash code to fit within the hash table, we |
3487 // use bit-wise AND with a mask, so the capacity must be positive | 3487 // use bit-wise AND with a mask, so the capacity must be positive |
3488 // and non-zero. | 3488 // and non-zero. |
3489 DCHECK(capacity > 0); | 3489 DCHECK(capacity > 0); |
3490 DCHECK(capacity <= kMaxCapacity); | 3490 DCHECK(capacity <= kMaxCapacity); |
3491 set(kCapacityIndex, Smi::FromInt(capacity)); | 3491 set(kCapacityIndex, Smi::FromInt(capacity)); |
3492 } | 3492 } |
3493 | 3493 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 return this->get(Derived::EntryToIndex(entry) + 1); | 3599 return this->get(Derived::EntryToIndex(entry) + 1); |
3600 } | 3600 } |
3601 | 3601 |
3602 // Set the value for entry. | 3602 // Set the value for entry. |
3603 void ValueAtPut(int entry, Object* value) { | 3603 void ValueAtPut(int entry, Object* value) { |
3604 this->set(Derived::EntryToIndex(entry) + 1, value); | 3604 this->set(Derived::EntryToIndex(entry) + 1, value); |
3605 } | 3605 } |
3606 | 3606 |
3607 // Returns the property details for the property at entry. | 3607 // Returns the property details for the property at entry. |
3608 PropertyDetails DetailsAt(int entry) { | 3608 PropertyDetails DetailsAt(int entry) { |
3609 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). | 3609 return Shape::DetailsAt(static_cast<Derived*>(this), entry); |
3610 return PropertyDetails( | |
3611 Smi::cast(this->get(Derived::EntryToIndex(entry) + 2))); | |
3612 } | 3610 } |
3613 | 3611 |
3614 // Set the details for entry. | 3612 // Set the details for entry. |
3615 void DetailsAtPut(int entry, PropertyDetails value) { | 3613 void DetailsAtPut(int entry, PropertyDetails value) { |
3616 this->set(Derived::EntryToIndex(entry) + 2, value.AsSmi()); | 3614 Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value); |
3617 } | 3615 } |
3618 | 3616 |
3619 // Returns true if property at given entry is deleted. | 3617 // Returns true if property at given entry is deleted. |
3620 bool IsDeleted(int entry) { | 3618 bool IsDeleted(int entry) { |
3621 return Shape::IsDeleted(static_cast<Derived*>(this), entry); | 3619 return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
3622 } | 3620 } |
3623 | 3621 |
3624 // Delete a property from the dictionary. | 3622 // Delete a property from the dictionary. |
3625 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); | 3623 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
3626 | 3624 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3739 // Find entry for key, otherwise return kNotFound. Optimized version of | 3737 // Find entry for key, otherwise return kNotFound. Optimized version of |
3740 // HashTable::FindEntry. | 3738 // HashTable::FindEntry. |
3741 int FindEntry(Handle<Name> key); | 3739 int FindEntry(Handle<Name> key); |
3742 }; | 3740 }; |
3743 | 3741 |
3744 | 3742 |
3745 template <typename Key> | 3743 template <typename Key> |
3746 class BaseDictionaryShape : public BaseShape<Key> { | 3744 class BaseDictionaryShape : public BaseShape<Key> { |
3747 public: | 3745 public: |
3748 template <typename Dictionary> | 3746 template <typename Dictionary> |
| 3747 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { |
| 3748 STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3749 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
| 3750 return PropertyDetails( |
| 3751 Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2))); |
| 3752 } |
| 3753 |
| 3754 template <typename Dictionary> |
| 3755 static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3756 PropertyDetails value) { |
| 3757 STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3758 dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi()); |
| 3759 } |
| 3760 |
| 3761 template <typename Dictionary> |
3749 static bool IsDeleted(Dictionary* dict, int entry) { | 3762 static bool IsDeleted(Dictionary* dict, int entry) { |
3750 return false; | 3763 return false; |
3751 } | 3764 } |
| 3765 |
| 3766 template <typename Dictionary> |
| 3767 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3768 Handle<Object> value, PropertyDetails details); |
3752 }; | 3769 }; |
3753 | 3770 |
3754 | 3771 |
3755 class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { | 3772 class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { |
3756 public: | 3773 public: |
3757 static inline bool IsMatch(Handle<Name> key, Object* other); | 3774 static inline bool IsMatch(Handle<Name> key, Object* other); |
3758 static inline uint32_t Hash(Handle<Name> key); | 3775 static inline uint32_t Hash(Handle<Name> key); |
3759 static inline uint32_t HashForObject(Handle<Name> key, Object* object); | 3776 static inline uint32_t HashForObject(Handle<Name> key, Object* object); |
3760 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); | 3777 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); |
3761 static const int kPrefixSize = 2; | 3778 static const int kPrefixSize = 2; |
(...skipping 10 matching lines...) Expand all Loading... |
3772 public: | 3789 public: |
3773 DECLARE_CAST(NameDictionary) | 3790 DECLARE_CAST(NameDictionary) |
3774 | 3791 |
3775 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( | 3792 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
3776 Handle<NameDictionary> dictionary); | 3793 Handle<NameDictionary> dictionary); |
3777 }; | 3794 }; |
3778 | 3795 |
3779 | 3796 |
3780 class GlobalDictionaryShape : public NameDictionaryShape { | 3797 class GlobalDictionaryShape : public NameDictionaryShape { |
3781 public: | 3798 public: |
3782 static const int kEntrySize = 3; // Overrides NameDictionaryShape::kEntrySize | 3799 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize |
| 3800 |
| 3801 template <typename Dictionary> |
| 3802 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); |
| 3803 |
| 3804 template <typename Dictionary> |
| 3805 static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3806 PropertyDetails value); |
3783 | 3807 |
3784 template <typename Dictionary> | 3808 template <typename Dictionary> |
3785 static bool IsDeleted(Dictionary* dict, int entry); | 3809 static bool IsDeleted(Dictionary* dict, int entry); |
| 3810 |
| 3811 template <typename Dictionary> |
| 3812 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3813 Handle<Object> value, PropertyDetails details); |
3786 }; | 3814 }; |
3787 | 3815 |
3788 | 3816 |
3789 class GlobalDictionary | 3817 class GlobalDictionary |
3790 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { | 3818 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { |
3791 public: | 3819 public: |
3792 DECLARE_CAST(GlobalDictionary) | 3820 DECLARE_CAST(GlobalDictionary) |
3793 }; | 3821 }; |
3794 | 3822 |
3795 | 3823 |
(...skipping 6065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9861 kValueOffset + kPointerSize, | 9889 kValueOffset + kPointerSize, |
9862 kSize> BodyDescriptor; | 9890 kSize> BodyDescriptor; |
9863 | 9891 |
9864 private: | 9892 private: |
9865 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); | 9893 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); |
9866 }; | 9894 }; |
9867 | 9895 |
9868 | 9896 |
9869 class PropertyCell : public HeapObject { | 9897 class PropertyCell : public HeapObject { |
9870 public: | 9898 public: |
| 9899 // [property_details]: details of the global property. |
| 9900 DECL_ACCESSORS(property_details_raw, Object) |
9871 // [value]: value of the global property. | 9901 // [value]: value of the global property. |
9872 DECL_ACCESSORS(value, Object) | 9902 DECL_ACCESSORS(value, Object) |
9873 // [dependent_code]: dependent code that depends on the type of the global | 9903 // [dependent_code]: dependent code that depends on the type of the global |
9874 // property. | 9904 // property. |
9875 DECL_ACCESSORS(dependent_code, DependentCode) | 9905 DECL_ACCESSORS(dependent_code, DependentCode) |
9876 | 9906 |
| 9907 PropertyDetails property_details() { |
| 9908 return PropertyDetails(Smi::cast(property_details_raw())); |
| 9909 } |
| 9910 |
| 9911 void set_property_details(PropertyDetails details) { |
| 9912 set_property_details_raw(details.AsSmi()); |
| 9913 } |
| 9914 |
9877 PropertyCellConstantType GetConstantType(); | 9915 PropertyCellConstantType GetConstantType(); |
9878 | 9916 |
9879 // Computes the new type of the cell's contents for the given value, but | 9917 // Computes the new type of the cell's contents for the given value, but |
9880 // without actually modifying the details. | 9918 // without actually modifying the details. |
9881 static PropertyCellType UpdatedType(Handle<PropertyCell> cell, | 9919 static PropertyCellType UpdatedType(Handle<PropertyCell> cell, |
9882 Handle<Object> value, | 9920 Handle<Object> value, |
9883 PropertyDetails details); | 9921 PropertyDetails details); |
9884 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, | 9922 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, |
9885 Handle<Object> value, PropertyDetails details); | 9923 Handle<Object> value, PropertyDetails details); |
9886 | 9924 |
9887 static Handle<PropertyCell> InvalidateEntry( | 9925 static Handle<PropertyCell> InvalidateEntry( |
9888 Handle<GlobalDictionary> dictionary, int entry); | 9926 Handle<GlobalDictionary> dictionary, int entry); |
9889 | 9927 |
9890 static void SetValueWithInvalidation(Handle<PropertyCell> cell, | 9928 static void SetValueWithInvalidation(Handle<PropertyCell> cell, |
9891 Handle<Object> new_value); | 9929 Handle<Object> new_value); |
9892 | 9930 |
9893 DECLARE_CAST(PropertyCell) | 9931 DECLARE_CAST(PropertyCell) |
9894 | 9932 |
9895 // Dispatched behavior. | 9933 // Dispatched behavior. |
9896 DECLARE_PRINTER(PropertyCell) | 9934 DECLARE_PRINTER(PropertyCell) |
9897 DECLARE_VERIFIER(PropertyCell) | 9935 DECLARE_VERIFIER(PropertyCell) |
9898 | 9936 |
9899 // Layout description. | 9937 // Layout description. |
9900 static const int kValueOffset = HeapObject::kHeaderSize; | 9938 static const int kDetailsOffset = HeapObject::kHeaderSize; |
| 9939 static const int kValueOffset = kDetailsOffset + kPointerSize; |
9901 static const int kDependentCodeOffset = kValueOffset + kPointerSize; | 9940 static const int kDependentCodeOffset = kValueOffset + kPointerSize; |
9902 static const int kSize = kDependentCodeOffset + kPointerSize; | 9941 static const int kSize = kDependentCodeOffset + kPointerSize; |
9903 | 9942 |
9904 static const int kPointerFieldsBeginOffset = kValueOffset; | 9943 static const int kPointerFieldsBeginOffset = kValueOffset; |
9905 static const int kPointerFieldsEndOffset = kSize; | 9944 static const int kPointerFieldsEndOffset = kSize; |
9906 | 9945 |
9907 typedef FixedBodyDescriptor<kValueOffset, | 9946 typedef FixedBodyDescriptor<kValueOffset, |
9908 kSize, | 9947 kSize, |
9909 kSize> BodyDescriptor; | 9948 kSize> BodyDescriptor; |
9910 | 9949 |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11148 } else { | 11187 } else { |
11149 value &= ~(1 << bit_position); | 11188 value &= ~(1 << bit_position); |
11150 } | 11189 } |
11151 return value; | 11190 return value; |
11152 } | 11191 } |
11153 }; | 11192 }; |
11154 | 11193 |
11155 } } // namespace v8::internal | 11194 } } // namespace v8::internal |
11156 | 11195 |
11157 #endif // V8_OBJECTS_H_ | 11196 #endif // V8_OBJECTS_H_ |
OLD | NEW |