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 3168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3179 inline static uint32_t NextProbe( | 3179 inline static uint32_t NextProbe( |
3180 uint32_t last, uint32_t number, uint32_t size) { | 3180 uint32_t last, uint32_t number, uint32_t size) { |
3181 return (last + number) & (size - 1); | 3181 return (last + number) & (size - 1); |
3182 } | 3182 } |
3183 }; | 3183 }; |
3184 | 3184 |
3185 | 3185 |
3186 template <typename Derived, typename Shape, typename Key> | 3186 template <typename Derived, typename Shape, typename Key> |
3187 class HashTable : public HashTableBase { | 3187 class HashTable : public HashTableBase { |
3188 public: | 3188 public: |
| 3189 typedef Shape ShapeT; |
| 3190 |
3189 // Wrapper methods | 3191 // Wrapper methods |
3190 inline uint32_t Hash(Key key) { | 3192 inline uint32_t Hash(Key key) { |
3191 if (Shape::UsesSeed) { | 3193 if (Shape::UsesSeed) { |
3192 return Shape::SeededHash(key, GetHeap()->HashSeed()); | 3194 return Shape::SeededHash(key, GetHeap()->HashSeed()); |
3193 } else { | 3195 } else { |
3194 return Shape::Hash(key); | 3196 return Shape::Hash(key); |
3195 } | 3197 } |
3196 } | 3198 } |
3197 | 3199 |
3198 inline uint32_t HashForObject(Key key, Object* object) { | 3200 inline uint32_t HashForObject(Key key, Object* object) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3465 int at_least_space_for, | 3467 int at_least_space_for, |
3466 PretenureFlag pretenure = NOT_TENURED); | 3468 PretenureFlag pretenure = NOT_TENURED); |
3467 | 3469 |
3468 // Ensures that a new dictionary is created when the capacity is checked. | 3470 // Ensures that a new dictionary is created when the capacity is checked. |
3469 void SetRequiresCopyOnCapacityChange(); | 3471 void SetRequiresCopyOnCapacityChange(); |
3470 | 3472 |
3471 // Ensure enough space for n additional elements. | 3473 // Ensure enough space for n additional elements. |
3472 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); | 3474 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); |
3473 | 3475 |
3474 #ifdef OBJECT_PRINT | 3476 #ifdef OBJECT_PRINT |
| 3477 // For our gdb macros, we should perhaps change these in the future. |
| 3478 void Print(); |
| 3479 |
3475 void Print(std::ostream& os); // NOLINT | 3480 void Print(std::ostream& os); // NOLINT |
3476 #endif | 3481 #endif |
3477 // Returns the key (slow). | 3482 // Returns the key (slow). |
3478 Object* SlowReverseLookup(Object* value); | 3483 Object* SlowReverseLookup(Object* value); |
3479 | 3484 |
3480 // Sets the entry to (key, value) pair. | 3485 // Sets the entry to (key, value) pair. |
3481 inline void SetEntry(int entry, | 3486 inline void SetEntry(int entry, |
3482 Handle<Object> key, | 3487 Handle<Object> key, |
3483 Handle<Object> value); | 3488 Handle<Object> value); |
3484 inline void SetEntry(int entry, | 3489 inline void SetEntry(int entry, |
(...skipping 5059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8544 // Shift constant retrieving hash code from hash field. | 8549 // Shift constant retrieving hash code from hash field. |
8545 static const int kHashShift = kNofHashBitFields; | 8550 static const int kHashShift = kNofHashBitFields; |
8546 | 8551 |
8547 // Only these bits are relevant in the hash, since the top two are shifted | 8552 // Only these bits are relevant in the hash, since the top two are shifted |
8548 // out. | 8553 // out. |
8549 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; | 8554 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
8550 | 8555 |
8551 // Array index strings this short can keep their index in the hash field. | 8556 // Array index strings this short can keep their index in the hash field. |
8552 static const int kMaxCachedArrayIndexLength = 7; | 8557 static const int kMaxCachedArrayIndexLength = 7; |
8553 | 8558 |
| 8559 // Maximum number of characters to consider when trying to convert a string |
| 8560 // value into an array index. |
| 8561 static const int kMaxArrayIndexSize = 10; |
| 8562 |
8554 // For strings which are array indexes the hash value has the string length | 8563 // For strings which are array indexes the hash value has the string length |
8555 // mixed into the hash, mainly to avoid a hash value of zero which would be | 8564 // mixed into the hash, mainly to avoid a hash value of zero which would be |
8556 // the case for the string '0'. 24 bits are used for the array index value. | 8565 // the case for the string '0'. 24 bits are used for the array index value. |
8557 static const int kArrayIndexValueBits = 24; | 8566 static const int kArrayIndexValueBits = 24; |
8558 static const int kArrayIndexLengthBits = | 8567 static const int kArrayIndexLengthBits = |
8559 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | 8568 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
8560 | 8569 |
8561 STATIC_ASSERT((kArrayIndexLengthBits > 0)); | 8570 STATIC_ASSERT(kArrayIndexLengthBits > 0); |
| 8571 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
8562 | 8572 |
8563 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, | 8573 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
8564 kArrayIndexValueBits> {}; // NOLINT | 8574 kArrayIndexValueBits> {}; // NOLINT |
8565 class ArrayIndexLengthBits : public BitField<unsigned int, | 8575 class ArrayIndexLengthBits : public BitField<unsigned int, |
8566 kNofHashBitFields + kArrayIndexValueBits, | 8576 kNofHashBitFields + kArrayIndexValueBits, |
8567 kArrayIndexLengthBits> {}; // NOLINT | 8577 kArrayIndexLengthBits> {}; // NOLINT |
8568 | 8578 |
8569 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we | 8579 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
8570 // could use a mask to test if the length of string is less than or equal to | 8580 // could use a mask to test if the length of string is less than or equal to |
8571 // kMaxCachedArrayIndexLength. | 8581 // kMaxCachedArrayIndexLength. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8641 // Ecma-262: | 8651 // Ecma-262: |
8642 // 4.3.16 String Value | 8652 // 4.3.16 String Value |
8643 // A string value is a member of the type String and is a finite | 8653 // A string value is a member of the type String and is a finite |
8644 // ordered sequence of zero or more 16-bit unsigned integer values. | 8654 // ordered sequence of zero or more 16-bit unsigned integer values. |
8645 // | 8655 // |
8646 // All string values have a length field. | 8656 // All string values have a length field. |
8647 class String: public Name { | 8657 class String: public Name { |
8648 public: | 8658 public: |
8649 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; | 8659 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
8650 | 8660 |
8651 // Array index strings this short can keep their index in the hash field. | |
8652 static const int kMaxCachedArrayIndexLength = 7; | |
8653 | |
8654 // For strings which are array indexes the hash value has the string length | |
8655 // mixed into the hash, mainly to avoid a hash value of zero which would be | |
8656 // the case for the string '0'. 24 bits are used for the array index value. | |
8657 static const int kArrayIndexValueBits = 24; | |
8658 static const int kArrayIndexLengthBits = | |
8659 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | |
8660 | |
8661 STATIC_ASSERT((kArrayIndexLengthBits > 0)); | |
8662 | |
8663 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, | |
8664 kArrayIndexValueBits> {}; // NOLINT | |
8665 class ArrayIndexLengthBits : public BitField<unsigned int, | |
8666 kNofHashBitFields + kArrayIndexValueBits, | |
8667 kArrayIndexLengthBits> {}; // NOLINT | |
8668 | |
8669 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we | |
8670 // could use a mask to test if the length of string is less than or equal to | |
8671 // kMaxCachedArrayIndexLength. | |
8672 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); | |
8673 | |
8674 static const unsigned int kContainsCachedArrayIndexMask = | |
8675 (~static_cast<unsigned>(kMaxCachedArrayIndexLength) | |
8676 << ArrayIndexLengthBits::kShift) | | |
8677 kIsNotArrayIndexMask; | |
8678 | |
8679 class SubStringRange { | 8661 class SubStringRange { |
8680 public: | 8662 public: |
8681 explicit inline SubStringRange(String* string, int first = 0, | 8663 explicit inline SubStringRange(String* string, int first = 0, |
8682 int length = -1); | 8664 int length = -1); |
8683 class iterator; | 8665 class iterator; |
8684 inline iterator begin(); | 8666 inline iterator begin(); |
8685 inline iterator end(); | 8667 inline iterator end(); |
8686 | 8668 |
8687 private: | 8669 private: |
8688 String* string_; | 8670 String* string_; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8880 #endif | 8862 #endif |
8881 DECLARE_PRINTER(String) | 8863 DECLARE_PRINTER(String) |
8882 DECLARE_VERIFIER(String) | 8864 DECLARE_VERIFIER(String) |
8883 | 8865 |
8884 inline bool IsFlat(); | 8866 inline bool IsFlat(); |
8885 | 8867 |
8886 // Layout description. | 8868 // Layout description. |
8887 static const int kLengthOffset = Name::kSize; | 8869 static const int kLengthOffset = Name::kSize; |
8888 static const int kSize = kLengthOffset + kPointerSize; | 8870 static const int kSize = kLengthOffset + kPointerSize; |
8889 | 8871 |
8890 // Maximum number of characters to consider when trying to convert a string | |
8891 // value into an array index. | |
8892 static const int kMaxArrayIndexSize = 10; | |
8893 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); | |
8894 | |
8895 // Max char codes. | 8872 // Max char codes. |
8896 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; | 8873 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
8897 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; | 8874 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
8898 static const int kMaxUtf16CodeUnit = 0xffff; | 8875 static const int kMaxUtf16CodeUnit = 0xffff; |
8899 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; | 8876 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; |
8900 static const uc32 kMaxCodePoint = 0x10ffff; | 8877 static const uc32 kMaxCodePoint = 0x10ffff; |
8901 | 8878 |
8902 // Maximal string length. | 8879 // Maximal string length. |
8903 static const int kMaxLength = (1 << 28) - 16; | 8880 static const int kMaxLength = (1 << 28) - 16; |
8904 | 8881 |
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10790 } | 10767 } |
10791 return value; | 10768 return value; |
10792 } | 10769 } |
10793 }; | 10770 }; |
10794 | 10771 |
10795 | 10772 |
10796 } // NOLINT, false-positive due to second-order macros. | 10773 } // NOLINT, false-positive due to second-order macros. |
10797 } // NOLINT, false-positive due to second-order macros. | 10774 } // NOLINT, false-positive due to second-order macros. |
10798 | 10775 |
10799 #endif // V8_OBJECTS_H_ | 10776 #endif // V8_OBJECTS_H_ |
OLD | NEW |