OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // - FixedDoubleArray | 88 // - FixedDoubleArray |
89 // - ExternalArray | 89 // - ExternalArray |
90 // - ExternalPixelArray | 90 // - ExternalPixelArray |
91 // - ExternalByteArray | 91 // - ExternalByteArray |
92 // - ExternalUnsignedByteArray | 92 // - ExternalUnsignedByteArray |
93 // - ExternalShortArray | 93 // - ExternalShortArray |
94 // - ExternalUnsignedShortArray | 94 // - ExternalUnsignedShortArray |
95 // - ExternalIntArray | 95 // - ExternalIntArray |
96 // - ExternalUnsignedIntArray | 96 // - ExternalUnsignedIntArray |
97 // - ExternalFloatArray | 97 // - ExternalFloatArray |
98 // - String | 98 // - Name |
99 // - SeqString | 99 // - String |
100 // - SeqOneByteString | 100 // - SeqString |
101 // - SeqTwoByteString | 101 // - SeqOneByteString |
102 // - SlicedString | 102 // - SeqTwoByteString |
103 // - ConsString | 103 // - SlicedString |
104 // - ExternalString | 104 // - ConsString |
105 // - ExternalAsciiString | 105 // - ExternalString |
106 // - ExternalTwoByteString | 106 // - ExternalAsciiString |
| 107 // - ExternalTwoByteString |
| 108 // - InternalizedString |
| 109 // - SeqInternalizedString |
| 110 // - SeqOneByteInternalizedString |
| 111 // - SeqTwoByteInternalizedString |
| 112 // - ConsInternalizedString |
| 113 // - ExternalInternalizedString |
| 114 // - ExternalAsciiInternalizedString |
| 115 // - ExternalTwoByteInternalizedString |
| 116 // - Symbol |
107 // - HeapNumber | 117 // - HeapNumber |
108 // - Code | 118 // - Code |
109 // - Map | 119 // - Map |
110 // - Oddball | 120 // - Oddball |
111 // - Foreign | 121 // - Foreign |
112 // - SharedFunctionInfo | 122 // - SharedFunctionInfo |
113 // - Struct | 123 // - Struct |
114 // - AccessorInfo | 124 // - AccessorInfo |
115 // - AccessorPair | 125 // - AccessorPair |
116 // - AccessCheckInfo | 126 // - AccessCheckInfo |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 V(ASCII_INTERNALIZED_STRING_TYPE) \ | 269 V(ASCII_INTERNALIZED_STRING_TYPE) \ |
260 V(CONS_INTERNALIZED_STRING_TYPE) \ | 270 V(CONS_INTERNALIZED_STRING_TYPE) \ |
261 V(CONS_ASCII_INTERNALIZED_STRING_TYPE) \ | 271 V(CONS_ASCII_INTERNALIZED_STRING_TYPE) \ |
262 V(EXTERNAL_INTERNALIZED_STRING_TYPE) \ | 272 V(EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
263 V(EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE) \ | 273 V(EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE) \ |
264 V(EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE) \ | 274 V(EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE) \ |
265 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \ | 275 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
266 V(SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE) \ | 276 V(SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE) \ |
267 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE) \ | 277 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE) \ |
268 \ | 278 \ |
| 279 V(SYMBOL_TYPE) \ |
269 V(MAP_TYPE) \ | 280 V(MAP_TYPE) \ |
270 V(CODE_TYPE) \ | 281 V(CODE_TYPE) \ |
271 V(ODDBALL_TYPE) \ | 282 V(ODDBALL_TYPE) \ |
272 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ | 283 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
273 \ | 284 \ |
274 V(HEAP_NUMBER_TYPE) \ | 285 V(HEAP_NUMBER_TYPE) \ |
275 V(FOREIGN_TYPE) \ | 286 V(FOREIGN_TYPE) \ |
276 V(BYTE_ARRAY_TYPE) \ | 287 V(BYTE_ARRAY_TYPE) \ |
277 V(FREE_SPACE_TYPE) \ | 288 V(FREE_SPACE_TYPE) \ |
278 /* Note: the order of these external array */ \ | 289 /* Note: the order of these external array */ \ |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 EXTERNAL_ASCII_STRING_TYPE | kInternalizedTag, | 575 EXTERNAL_ASCII_STRING_TYPE | kInternalizedTag, |
565 EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE = | 576 EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE = |
566 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE | kInternalizedTag, | 577 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE | kInternalizedTag, |
567 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = | 578 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = |
568 SHORT_EXTERNAL_STRING_TYPE | kInternalizedTag, | 579 SHORT_EXTERNAL_STRING_TYPE | kInternalizedTag, |
569 SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE = | 580 SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE = |
570 SHORT_EXTERNAL_ASCII_STRING_TYPE | kInternalizedTag, | 581 SHORT_EXTERNAL_ASCII_STRING_TYPE | kInternalizedTag, |
571 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE = | 582 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ASCII_DATA_TYPE = |
572 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE | kInternalizedTag, | 583 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE | kInternalizedTag, |
573 | 584 |
| 585 // Non-string names |
| 586 SYMBOL_TYPE = kNotStringTag, // LAST_NAME_TYPE, FIRST_NONSTRING_TYPE |
| 587 |
574 // Objects allocated in their own spaces (never in new space). | 588 // Objects allocated in their own spaces (never in new space). |
575 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE | 589 MAP_TYPE, |
576 CODE_TYPE, | 590 CODE_TYPE, |
577 ODDBALL_TYPE, | 591 ODDBALL_TYPE, |
578 JS_GLOBAL_PROPERTY_CELL_TYPE, | 592 JS_GLOBAL_PROPERTY_CELL_TYPE, |
579 | 593 |
580 // "Data", objects that cannot contain non-map-word pointers to heap | 594 // "Data", objects that cannot contain non-map-word pointers to heap |
581 // objects. | 595 // objects. |
582 HEAP_NUMBER_TYPE, | 596 HEAP_NUMBER_TYPE, |
583 FOREIGN_TYPE, | 597 FOREIGN_TYPE, |
584 BYTE_ARRAY_TYPE, | 598 BYTE_ARRAY_TYPE, |
585 FREE_SPACE_TYPE, | 599 FREE_SPACE_TYPE, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 JS_WEAK_MAP_TYPE, | 659 JS_WEAK_MAP_TYPE, |
646 | 660 |
647 JS_REGEXP_TYPE, | 661 JS_REGEXP_TYPE, |
648 | 662 |
649 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE | 663 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
650 | 664 |
651 // Pseudo-types | 665 // Pseudo-types |
652 FIRST_TYPE = 0x0, | 666 FIRST_TYPE = 0x0, |
653 LAST_TYPE = JS_FUNCTION_TYPE, | 667 LAST_TYPE = JS_FUNCTION_TYPE, |
654 INVALID_TYPE = FIRST_TYPE - 1, | 668 INVALID_TYPE = FIRST_TYPE - 1, |
655 FIRST_NONSTRING_TYPE = MAP_TYPE, | 669 LAST_NAME_TYPE = SYMBOL_TYPE, |
| 670 FIRST_NONSTRING_TYPE = SYMBOL_TYPE, |
656 // Boundaries for testing for an external array. | 671 // Boundaries for testing for an external array. |
657 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, | 672 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
658 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, | 673 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
659 // Boundary for promotion to old data space/old pointer space. | 674 // Boundary for promotion to old data space/old pointer space. |
660 LAST_DATA_TYPE = FILLER_TYPE, | 675 LAST_DATA_TYPE = FILLER_TYPE, |
661 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). | 676 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
662 // Note that there is no range for JSObject or JSProxy, since their subtypes | 677 // Note that there is no range for JSObject or JSProxy, since their subtypes |
663 // are not continuous in this enum! The enum ranges instead reflect the | 678 // are not continuous in this enum! The enum ranges instead reflect the |
664 // external class names, where proxies are treated as either ordinary objects, | 679 // external class names, where proxies are treated as either ordinary objects, |
665 // or functions. | 680 // or functions. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 }; | 836 }; |
822 | 837 |
823 | 838 |
824 #define OBJECT_TYPE_LIST(V) \ | 839 #define OBJECT_TYPE_LIST(V) \ |
825 V(Smi) \ | 840 V(Smi) \ |
826 V(HeapObject) \ | 841 V(HeapObject) \ |
827 V(Number) \ | 842 V(Number) \ |
828 | 843 |
829 #define HEAP_OBJECT_TYPE_LIST(V) \ | 844 #define HEAP_OBJECT_TYPE_LIST(V) \ |
830 V(HeapNumber) \ | 845 V(HeapNumber) \ |
| 846 V(Name) \ |
831 V(String) \ | 847 V(String) \ |
832 V(SeqString) \ | 848 V(SeqString) \ |
833 V(ExternalString) \ | 849 V(ExternalString) \ |
834 V(ConsString) \ | 850 V(ConsString) \ |
835 V(SlicedString) \ | 851 V(SlicedString) \ |
836 V(ExternalTwoByteString) \ | 852 V(ExternalTwoByteString) \ |
837 V(ExternalAsciiString) \ | 853 V(ExternalAsciiString) \ |
838 V(SeqTwoByteString) \ | 854 V(SeqTwoByteString) \ |
839 V(SeqOneByteString) \ | 855 V(SeqOneByteString) \ |
840 V(InternalizedString) \ | 856 V(InternalizedString) \ |
| 857 V(Symbol) \ |
841 \ | 858 \ |
842 V(ExternalArray) \ | 859 V(ExternalArray) \ |
843 V(ExternalByteArray) \ | 860 V(ExternalByteArray) \ |
844 V(ExternalUnsignedByteArray) \ | 861 V(ExternalUnsignedByteArray) \ |
845 V(ExternalShortArray) \ | 862 V(ExternalShortArray) \ |
846 V(ExternalUnsignedShortArray) \ | 863 V(ExternalUnsignedShortArray) \ |
847 V(ExternalIntArray) \ | 864 V(ExternalIntArray) \ |
848 V(ExternalUnsignedIntArray) \ | 865 V(ExternalUnsignedIntArray) \ |
849 V(ExternalFloatArray) \ | 866 V(ExternalFloatArray) \ |
850 V(ExternalDoubleArray) \ | 867 V(ExternalDoubleArray) \ |
(...skipping 6266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7117 uint32_t type_; | 7134 uint32_t type_; |
7118 #ifdef DEBUG | 7135 #ifdef DEBUG |
7119 inline void set_valid() { valid_ = true; } | 7136 inline void set_valid() { valid_ = true; } |
7120 bool valid_; | 7137 bool valid_; |
7121 #else | 7138 #else |
7122 inline void set_valid() { } | 7139 inline void set_valid() { } |
7123 #endif | 7140 #endif |
7124 }; | 7141 }; |
7125 | 7142 |
7126 | 7143 |
| 7144 // The Name abstract class captures anything that can be used as a property |
| 7145 // name, i.e., strings and symbols. All names store a hash value. |
| 7146 class Name: public HeapObject { |
| 7147 public: |
| 7148 // Get and set the hash field of the name. |
| 7149 inline uint32_t hash_field(); |
| 7150 inline void set_hash_field(uint32_t value); |
| 7151 |
| 7152 // Tells whether the hash code has been computed. |
| 7153 inline bool HasHashCode(); |
| 7154 |
| 7155 // Returns a hash value used for the property table |
| 7156 inline uint32_t Hash(); |
| 7157 |
| 7158 // Casting. |
| 7159 static inline Name* cast(Object* obj); |
| 7160 |
| 7161 // Layout description. |
| 7162 static const int kHashFieldOffset = HeapObject::kHeaderSize; |
| 7163 static const int kSize = kHashFieldOffset + kPointerSize; |
| 7164 |
| 7165 // Mask constant for checking if a name has a computed hash code |
| 7166 // and if it is a string that is an array index. The least significant bit |
| 7167 // indicates whether a hash code has been computed. If the hash code has |
| 7168 // been computed the 2nd bit tells whether the string can be used as an |
| 7169 // array index. |
| 7170 static const int kHashNotComputedMask = 1; |
| 7171 static const int kIsNotArrayIndexMask = 1 << 1; |
| 7172 static const int kNofHashBitFields = 2; |
| 7173 |
| 7174 // Shift constant retrieving hash code from hash field. |
| 7175 static const int kHashShift = kNofHashBitFields; |
| 7176 |
| 7177 // Only these bits are relevant in the hash, since the top two are shifted |
| 7178 // out. |
| 7179 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 7180 |
| 7181 // Array index strings this short can keep their index in the hash field. |
| 7182 static const int kMaxCachedArrayIndexLength = 7; |
| 7183 |
| 7184 // For strings which are array indexes the hash value has the string length |
| 7185 // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 7186 // the case for the string '0'. 24 bits are used for the array index value. |
| 7187 static const int kArrayIndexValueBits = 24; |
| 7188 static const int kArrayIndexLengthBits = |
| 7189 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 7190 |
| 7191 STATIC_CHECK((kArrayIndexLengthBits > 0)); |
| 7192 |
| 7193 static const int kArrayIndexHashLengthShift = |
| 7194 kArrayIndexValueBits + kNofHashBitFields; |
| 7195 |
| 7196 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
| 7197 |
| 7198 static const int kArrayIndexValueMask = |
| 7199 ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
| 7200 |
| 7201 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 7202 // could use a mask to test if the length of string is less than or equal to |
| 7203 // kMaxCachedArrayIndexLength. |
| 7204 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 7205 |
| 7206 static const int kContainsCachedArrayIndexMask = |
| 7207 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 7208 kIsNotArrayIndexMask; |
| 7209 |
| 7210 // Value of empty hash field indicating that the hash is not computed. |
| 7211 static const int kEmptyHashField = |
| 7212 kIsNotArrayIndexMask | kHashNotComputedMask; |
| 7213 |
| 7214 protected: |
| 7215 static inline bool IsHashFieldComputed(uint32_t field); |
| 7216 |
| 7217 private: |
| 7218 DISALLOW_IMPLICIT_CONSTRUCTORS(Name); |
| 7219 }; |
| 7220 |
| 7221 |
| 7222 // ES6 symbols. |
| 7223 class Symbol: public Name { |
| 7224 public: |
| 7225 // Casting. |
| 7226 static inline Symbol* cast(Object* obj); |
| 7227 |
| 7228 // Dispatched behavior. |
| 7229 DECLARE_PRINTER(Symbol) |
| 7230 DECLARE_VERIFIER(Symbol) |
| 7231 |
| 7232 // Layout description. |
| 7233 static const int kSize = Name::kSize; |
| 7234 |
| 7235 private: |
| 7236 DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol); |
| 7237 }; |
| 7238 |
| 7239 |
7127 // The String abstract class captures JavaScript string values: | 7240 // The String abstract class captures JavaScript string values: |
7128 // | 7241 // |
7129 // Ecma-262: | 7242 // Ecma-262: |
7130 // 4.3.16 String Value | 7243 // 4.3.16 String Value |
7131 // A string value is a member of the type String and is a finite | 7244 // A string value is a member of the type String and is a finite |
7132 // ordered sequence of zero or more 16-bit unsigned integer values. | 7245 // ordered sequence of zero or more 16-bit unsigned integer values. |
7133 // | 7246 // |
7134 // All string values have a length field. | 7247 // All string values have a length field. |
7135 class String: public HeapObject { | 7248 class String: public Name { |
7136 public: | 7249 public: |
7137 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; | 7250 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
7138 | 7251 |
7139 // Representation of the flat content of a String. | 7252 // Representation of the flat content of a String. |
7140 // A non-flat string doesn't have flat content. | 7253 // A non-flat string doesn't have flat content. |
7141 // A flat string has content that's encoded as a sequence of either | 7254 // A flat string has content that's encoded as a sequence of either |
7142 // ASCII chars or two-byte UC16. | 7255 // ASCII chars or two-byte UC16. |
7143 // Returned by String::GetFlatContent(). | 7256 // Returned by String::GetFlatContent(). |
7144 class FlatContent { | 7257 class FlatContent { |
7145 public: | 7258 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7178 Vector<const uint8_t> buffer_; | 7291 Vector<const uint8_t> buffer_; |
7179 State state_; | 7292 State state_; |
7180 | 7293 |
7181 friend class String; | 7294 friend class String; |
7182 }; | 7295 }; |
7183 | 7296 |
7184 // Get and set the length of the string. | 7297 // Get and set the length of the string. |
7185 inline int length(); | 7298 inline int length(); |
7186 inline void set_length(int value); | 7299 inline void set_length(int value); |
7187 | 7300 |
7188 // Get and set the hash field of the string. | |
7189 inline uint32_t hash_field(); | |
7190 inline void set_hash_field(uint32_t value); | |
7191 | |
7192 // Returns whether this string has only ASCII chars, i.e. all of them can | 7301 // Returns whether this string has only ASCII chars, i.e. all of them can |
7193 // be ASCII encoded. This might be the case even if the string is | 7302 // be ASCII encoded. This might be the case even if the string is |
7194 // two-byte. Such strings may appear when the embedder prefers | 7303 // two-byte. Such strings may appear when the embedder prefers |
7195 // two-byte external representations even for ASCII data. | 7304 // two-byte external representations even for ASCII data. |
7196 inline bool IsOneByteRepresentation(); | 7305 inline bool IsOneByteRepresentation(); |
7197 inline bool IsTwoByteRepresentation(); | 7306 inline bool IsTwoByteRepresentation(); |
7198 | 7307 |
7199 // Cons and slices have an encoding flag that may not represent the actual | 7308 // Cons and slices have an encoding flag that may not represent the actual |
7200 // encoding of the underlying string. This is taken into account here. | 7309 // encoding of the underlying string. This is taken into account here. |
7201 // Requires: this->IsFlat() | 7310 // Requires: this->IsFlat() |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7282 | 7391 |
7283 // Return a 16 bit Unicode representation of the string. | 7392 // Return a 16 bit Unicode representation of the string. |
7284 // The string should be nearly flat, otherwise the performance of | 7393 // The string should be nearly flat, otherwise the performance of |
7285 // of this method may be very bad. Setting robustness_flag to | 7394 // of this method may be very bad. Setting robustness_flag to |
7286 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it | 7395 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
7287 // handles unexpected data without causing assert failures and it does not | 7396 // handles unexpected data without causing assert failures and it does not |
7288 // do any heap allocations. This is useful when printing stack traces. | 7397 // do any heap allocations. This is useful when printing stack traces. |
7289 SmartArrayPointer<uc16> ToWideCString( | 7398 SmartArrayPointer<uc16> ToWideCString( |
7290 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); | 7399 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
7291 | 7400 |
7292 // Tells whether the hash code has been computed. | |
7293 inline bool HasHashCode(); | |
7294 | |
7295 // Returns a hash value used for the property table | |
7296 inline uint32_t Hash(); | |
7297 | |
7298 bool ComputeArrayIndex(uint32_t* index); | 7401 bool ComputeArrayIndex(uint32_t* index); |
7299 | 7402 |
7300 // Externalization. | 7403 // Externalization. |
7301 bool MakeExternal(v8::String::ExternalStringResource* resource); | 7404 bool MakeExternal(v8::String::ExternalStringResource* resource); |
7302 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); | 7405 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
7303 | 7406 |
7304 // Conversion. | 7407 // Conversion. |
7305 inline bool AsArrayIndex(uint32_t* index); | 7408 inline bool AsArrayIndex(uint32_t* index); |
7306 | 7409 |
7307 // Casting. | 7410 // Casting. |
(...skipping 12 matching lines...) Expand all Loading... |
7320 } | 7423 } |
7321 void StringPrint(FILE* out); | 7424 void StringPrint(FILE* out); |
7322 | 7425 |
7323 char* ToAsciiArray(); | 7426 char* ToAsciiArray(); |
7324 #endif | 7427 #endif |
7325 DECLARE_VERIFIER(String) | 7428 DECLARE_VERIFIER(String) |
7326 | 7429 |
7327 inline bool IsFlat(); | 7430 inline bool IsFlat(); |
7328 | 7431 |
7329 // Layout description. | 7432 // Layout description. |
7330 static const int kLengthOffset = HeapObject::kHeaderSize; | 7433 static const int kLengthOffset = Name::kSize; |
7331 static const int kHashFieldOffset = kLengthOffset + kPointerSize; | 7434 static const int kSize = kLengthOffset + kPointerSize; |
7332 static const int kSize = kHashFieldOffset + kPointerSize; | |
7333 | 7435 |
7334 // Maximum number of characters to consider when trying to convert a string | 7436 // Maximum number of characters to consider when trying to convert a string |
7335 // value into an array index. | 7437 // value into an array index. |
7336 static const int kMaxArrayIndexSize = 10; | 7438 static const int kMaxArrayIndexSize = 10; |
| 7439 STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
7337 | 7440 |
7338 // Max char codes. | 7441 // Max char codes. |
7339 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; | 7442 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
7340 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; | 7443 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
7341 static const int kMaxUtf16CodeUnit = 0xffff; | 7444 static const int kMaxUtf16CodeUnit = 0xffff; |
7342 | 7445 |
7343 // Mask constant for checking if a string has a computed hash code | |
7344 // and if it is an array index. The least significant bit indicates | |
7345 // whether a hash code has been computed. If the hash code has been | |
7346 // computed the 2nd bit tells whether the string can be used as an | |
7347 // array index. | |
7348 static const int kHashNotComputedMask = 1; | |
7349 static const int kIsNotArrayIndexMask = 1 << 1; | |
7350 static const int kNofHashBitFields = 2; | |
7351 | |
7352 // Shift constant retrieving hash code from hash field. | |
7353 static const int kHashShift = kNofHashBitFields; | |
7354 | |
7355 // Only these bits are relevant in the hash, since the top two are shifted | |
7356 // out. | |
7357 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; | |
7358 | |
7359 // Array index strings this short can keep their index in the hash | |
7360 // field. | |
7361 static const int kMaxCachedArrayIndexLength = 7; | |
7362 | |
7363 // For strings which are array indexes the hash value has the string length | |
7364 // mixed into the hash, mainly to avoid a hash value of zero which would be | |
7365 // the case for the string '0'. 24 bits are used for the array index value. | |
7366 static const int kArrayIndexValueBits = 24; | |
7367 static const int kArrayIndexLengthBits = | |
7368 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | |
7369 | |
7370 STATIC_CHECK((kArrayIndexLengthBits > 0)); | |
7371 STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); | |
7372 | |
7373 static const int kArrayIndexHashLengthShift = | |
7374 kArrayIndexValueBits + kNofHashBitFields; | |
7375 | |
7376 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; | |
7377 | |
7378 static const int kArrayIndexValueMask = | |
7379 ((1 << kArrayIndexValueBits) - 1) << kHashShift; | |
7380 | |
7381 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we | |
7382 // could use a mask to test if the length of string is less than or equal to | |
7383 // kMaxCachedArrayIndexLength. | |
7384 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); | |
7385 | |
7386 static const int kContainsCachedArrayIndexMask = | |
7387 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | | |
7388 kIsNotArrayIndexMask; | |
7389 | |
7390 // Value of empty hash field indicating that the hash is not computed. | |
7391 static const int kEmptyHashField = | |
7392 kIsNotArrayIndexMask | kHashNotComputedMask; | |
7393 | |
7394 // Value of hash field containing computed hash equal to zero. | 7446 // Value of hash field containing computed hash equal to zero. |
7395 static const int kEmptyStringHash = kIsNotArrayIndexMask; | 7447 static const int kEmptyStringHash = kIsNotArrayIndexMask; |
7396 | 7448 |
7397 // Maximal string length. | 7449 // Maximal string length. |
7398 static const int kMaxLength = (1 << (32 - 2)) - 1; | 7450 static const int kMaxLength = (1 << (32 - 2)) - 1; |
7399 | 7451 |
7400 // Max length for computing hash. For strings longer than this limit the | 7452 // Max length for computing hash. For strings longer than this limit the |
7401 // string length is used as the hash value. | 7453 // string length is used as the hash value. |
7402 static const int kMaxHashCalcLength = 16383; | 7454 static const int kMaxHashCalcLength = 16383; |
7403 | 7455 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7465 | 7517 |
7466 template<class Visitor, class ConsOp> | 7518 template<class Visitor, class ConsOp> |
7467 static inline void Visit(String* string, | 7519 static inline void Visit(String* string, |
7468 unsigned offset, | 7520 unsigned offset, |
7469 Visitor& visitor, | 7521 Visitor& visitor, |
7470 ConsOp& cons_op, | 7522 ConsOp& cons_op, |
7471 int32_t type, | 7523 int32_t type, |
7472 unsigned length); | 7524 unsigned length); |
7473 | 7525 |
7474 private: | 7526 private: |
| 7527 friend class Name; |
| 7528 |
7475 // Try to flatten the top level ConsString that is hiding behind this | 7529 // Try to flatten the top level ConsString that is hiding behind this |
7476 // string. This is a no-op unless the string is a ConsString. Flatten | 7530 // string. This is a no-op unless the string is a ConsString. Flatten |
7477 // mutates the ConsString and might return a failure. | 7531 // mutates the ConsString and might return a failure. |
7478 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); | 7532 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
7479 | 7533 |
7480 static inline bool IsHashFieldComputed(uint32_t field); | |
7481 | |
7482 // Slow case of String::Equals. This implementation works on any strings | 7534 // Slow case of String::Equals. This implementation works on any strings |
7483 // but it is most efficient on strings that are almost flat. | 7535 // but it is most efficient on strings that are almost flat. |
7484 bool SlowEquals(String* other); | 7536 bool SlowEquals(String* other); |
7485 | 7537 |
7486 // Slow case of AsArrayIndex. | 7538 // Slow case of AsArrayIndex. |
7487 bool SlowAsArrayIndex(uint32_t* index); | 7539 bool SlowAsArrayIndex(uint32_t* index); |
7488 | 7540 |
7489 // Compute and set the hash code. | 7541 // Compute and set the hash code. |
7490 uint32_t ComputeAndSetHash(); | 7542 uint32_t ComputeAndSetHash(); |
7491 | 7543 |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8886 } else { | 8938 } else { |
8887 value &= ~(1 << bit_position); | 8939 value &= ~(1 << bit_position); |
8888 } | 8940 } |
8889 return value; | 8941 return value; |
8890 } | 8942 } |
8891 }; | 8943 }; |
8892 | 8944 |
8893 } } // namespace v8::internal | 8945 } } // namespace v8::internal |
8894 | 8946 |
8895 #endif // V8_OBJECTS_H_ | 8947 #endif // V8_OBJECTS_H_ |
OLD | NEW |