OLD | NEW |
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 | 9 |
10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
(...skipping 3171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3182 inline static uint32_t NextProbe( | 3182 inline static uint32_t NextProbe( |
3183 uint32_t last, uint32_t number, uint32_t size) { | 3183 uint32_t last, uint32_t number, uint32_t size) { |
3184 return (last + number) & (size - 1); | 3184 return (last + number) & (size - 1); |
3185 } | 3185 } |
3186 }; | 3186 }; |
3187 | 3187 |
3188 | 3188 |
3189 template <typename Derived, typename Shape, typename Key> | 3189 template <typename Derived, typename Shape, typename Key> |
3190 class HashTable : public HashTableBase { | 3190 class HashTable : public HashTableBase { |
3191 public: | 3191 public: |
3192 typedef Shape ShapeT; | |
3193 | |
3194 // Wrapper methods | 3192 // Wrapper methods |
3195 inline uint32_t Hash(Key key) { | 3193 inline uint32_t Hash(Key key) { |
3196 if (Shape::UsesSeed) { | 3194 if (Shape::UsesSeed) { |
3197 return Shape::SeededHash(key, GetHeap()->HashSeed()); | 3195 return Shape::SeededHash(key, GetHeap()->HashSeed()); |
3198 } else { | 3196 } else { |
3199 return Shape::Hash(key); | 3197 return Shape::Hash(key); |
3200 } | 3198 } |
3201 } | 3199 } |
3202 | 3200 |
3203 inline uint32_t HashForObject(Key key, Object* object) { | 3201 inline uint32_t HashForObject(Key key, Object* object) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3470 int at_least_space_for, | 3468 int at_least_space_for, |
3471 PretenureFlag pretenure = NOT_TENURED); | 3469 PretenureFlag pretenure = NOT_TENURED); |
3472 | 3470 |
3473 // Ensures that a new dictionary is created when the capacity is checked. | 3471 // Ensures that a new dictionary is created when the capacity is checked. |
3474 void SetRequiresCopyOnCapacityChange(); | 3472 void SetRequiresCopyOnCapacityChange(); |
3475 | 3473 |
3476 // Ensure enough space for n additional elements. | 3474 // Ensure enough space for n additional elements. |
3477 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); | 3475 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); |
3478 | 3476 |
3479 #ifdef OBJECT_PRINT | 3477 #ifdef OBJECT_PRINT |
3480 // For our gdb macros, we should perhaps change these in the future. | |
3481 void Print(); | |
3482 | |
3483 void Print(std::ostream& os); // NOLINT | 3478 void Print(std::ostream& os); // NOLINT |
3484 #endif | 3479 #endif |
3485 // Returns the key (slow). | 3480 // Returns the key (slow). |
3486 Object* SlowReverseLookup(Object* value); | 3481 Object* SlowReverseLookup(Object* value); |
3487 | 3482 |
3488 // Sets the entry to (key, value) pair. | 3483 // Sets the entry to (key, value) pair. |
3489 inline void SetEntry(int entry, | 3484 inline void SetEntry(int entry, |
3490 Handle<Object> key, | 3485 Handle<Object> key, |
3491 Handle<Object> value); | 3486 Handle<Object> value); |
3492 inline void SetEntry(int entry, | 3487 inline void SetEntry(int entry, |
(...skipping 5075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8568 // Shift constant retrieving hash code from hash field. | 8563 // Shift constant retrieving hash code from hash field. |
8569 static const int kHashShift = kNofHashBitFields; | 8564 static const int kHashShift = kNofHashBitFields; |
8570 | 8565 |
8571 // Only these bits are relevant in the hash, since the top two are shifted | 8566 // Only these bits are relevant in the hash, since the top two are shifted |
8572 // out. | 8567 // out. |
8573 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; | 8568 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
8574 | 8569 |
8575 // Array index strings this short can keep their index in the hash field. | 8570 // Array index strings this short can keep their index in the hash field. |
8576 static const int kMaxCachedArrayIndexLength = 7; | 8571 static const int kMaxCachedArrayIndexLength = 7; |
8577 | 8572 |
8578 // Maximum number of characters to consider when trying to convert a string | |
8579 // value into an array index. | |
8580 static const int kMaxArrayIndexSize = 10; | |
8581 | |
8582 // For strings which are array indexes the hash value has the string length | 8573 // For strings which are array indexes the hash value has the string length |
8583 // mixed into the hash, mainly to avoid a hash value of zero which would be | 8574 // mixed into the hash, mainly to avoid a hash value of zero which would be |
8584 // the case for the string '0'. 24 bits are used for the array index value. | 8575 // the case for the string '0'. 24 bits are used for the array index value. |
8585 static const int kArrayIndexValueBits = 24; | 8576 static const int kArrayIndexValueBits = 24; |
8586 static const int kArrayIndexLengthBits = | 8577 static const int kArrayIndexLengthBits = |
8587 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | 8578 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
8588 | 8579 |
8589 STATIC_ASSERT(kArrayIndexLengthBits > 0); | 8580 STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
8590 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); | |
8591 | 8581 |
8592 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, | 8582 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
8593 kArrayIndexValueBits> {}; // NOLINT | 8583 kArrayIndexValueBits> {}; // NOLINT |
8594 class ArrayIndexLengthBits : public BitField<unsigned int, | 8584 class ArrayIndexLengthBits : public BitField<unsigned int, |
8595 kNofHashBitFields + kArrayIndexValueBits, | 8585 kNofHashBitFields + kArrayIndexValueBits, |
8596 kArrayIndexLengthBits> {}; // NOLINT | 8586 kArrayIndexLengthBits> {}; // NOLINT |
8597 | 8587 |
8598 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we | 8588 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
8599 // could use a mask to test if the length of string is less than or equal to | 8589 // could use a mask to test if the length of string is less than or equal to |
8600 // kMaxCachedArrayIndexLength. | 8590 // kMaxCachedArrayIndexLength. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8670 // Ecma-262: | 8660 // Ecma-262: |
8671 // 4.3.16 String Value | 8661 // 4.3.16 String Value |
8672 // A string value is a member of the type String and is a finite | 8662 // A string value is a member of the type String and is a finite |
8673 // ordered sequence of zero or more 16-bit unsigned integer values. | 8663 // ordered sequence of zero or more 16-bit unsigned integer values. |
8674 // | 8664 // |
8675 // All string values have a length field. | 8665 // All string values have a length field. |
8676 class String: public Name { | 8666 class String: public Name { |
8677 public: | 8667 public: |
8678 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; | 8668 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
8679 | 8669 |
| 8670 // Array index strings this short can keep their index in the hash field. |
| 8671 static const int kMaxCachedArrayIndexLength = 7; |
| 8672 |
| 8673 // For strings which are array indexes the hash value has the string length |
| 8674 // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8675 // the case for the string '0'. 24 bits are used for the array index value. |
| 8676 static const int kArrayIndexValueBits = 24; |
| 8677 static const int kArrayIndexLengthBits = |
| 8678 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8679 |
| 8680 STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8681 |
| 8682 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8683 kArrayIndexValueBits> {}; // NOLINT |
| 8684 class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8685 kNofHashBitFields + kArrayIndexValueBits, |
| 8686 kArrayIndexLengthBits> {}; // NOLINT |
| 8687 |
| 8688 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8689 // could use a mask to test if the length of string is less than or equal to |
| 8690 // kMaxCachedArrayIndexLength. |
| 8691 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8692 |
| 8693 static const unsigned int kContainsCachedArrayIndexMask = |
| 8694 (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8695 << ArrayIndexLengthBits::kShift) | |
| 8696 kIsNotArrayIndexMask; |
| 8697 |
8680 class SubStringRange { | 8698 class SubStringRange { |
8681 public: | 8699 public: |
8682 explicit inline SubStringRange(String* string, int first = 0, | 8700 explicit inline SubStringRange(String* string, int first = 0, |
8683 int length = -1); | 8701 int length = -1); |
8684 class iterator; | 8702 class iterator; |
8685 inline iterator begin(); | 8703 inline iterator begin(); |
8686 inline iterator end(); | 8704 inline iterator end(); |
8687 | 8705 |
8688 private: | 8706 private: |
8689 String* string_; | 8707 String* string_; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8881 #endif | 8899 #endif |
8882 DECLARE_PRINTER(String) | 8900 DECLARE_PRINTER(String) |
8883 DECLARE_VERIFIER(String) | 8901 DECLARE_VERIFIER(String) |
8884 | 8902 |
8885 inline bool IsFlat(); | 8903 inline bool IsFlat(); |
8886 | 8904 |
8887 // Layout description. | 8905 // Layout description. |
8888 static const int kLengthOffset = Name::kSize; | 8906 static const int kLengthOffset = Name::kSize; |
8889 static const int kSize = kLengthOffset + kPointerSize; | 8907 static const int kSize = kLengthOffset + kPointerSize; |
8890 | 8908 |
| 8909 // Maximum number of characters to consider when trying to convert a string |
| 8910 // value into an array index. |
| 8911 static const int kMaxArrayIndexSize = 10; |
| 8912 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
| 8913 |
8891 // Max char codes. | 8914 // Max char codes. |
8892 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; | 8915 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
8893 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; | 8916 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
8894 static const int kMaxUtf16CodeUnit = 0xffff; | 8917 static const int kMaxUtf16CodeUnit = 0xffff; |
8895 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; | 8918 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; |
8896 static const uc32 kMaxCodePoint = 0x10ffff; | 8919 static const uc32 kMaxCodePoint = 0x10ffff; |
8897 | 8920 |
8898 // Maximal string length. | 8921 // Maximal string length. |
8899 static const int kMaxLength = (1 << 28) - 16; | 8922 static const int kMaxLength = (1 << 28) - 16; |
8900 | 8923 |
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10786 } | 10809 } |
10787 return value; | 10810 return value; |
10788 } | 10811 } |
10789 }; | 10812 }; |
10790 | 10813 |
10791 | 10814 |
10792 } // NOLINT, false-positive due to second-order macros. | 10815 } // NOLINT, false-positive due to second-order macros. |
10793 } // NOLINT, false-positive due to second-order macros. | 10816 } // NOLINT, false-positive due to second-order macros. |
10794 | 10817 |
10795 #endif // V8_OBJECTS_H_ | 10818 #endif // V8_OBJECTS_H_ |
OLD | NEW |