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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // It describes the type of the instances. | 210 // It describes the type of the instances. |
211 // | 211 // |
212 // As an example, a JavaScript object is a heap object and its map | 212 // As an example, a JavaScript object is a heap object and its map |
213 // instance_type is JS_OBJECT_TYPE. | 213 // instance_type is JS_OBJECT_TYPE. |
214 // | 214 // |
215 // The names of the string instance types are intended to systematically | 215 // The names of the string instance types are intended to systematically |
216 // mirror their encoding in the instance_type field of the map. The default | 216 // mirror their encoding in the instance_type field of the map. The default |
217 // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII | 217 // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
218 // encoding is mentioned explicitly in the name. Likewise, the default | 218 // encoding is mentioned explicitly in the name. Likewise, the default |
219 // representation is considered sequential. It is not mentioned in the | 219 // representation is considered sequential. It is not mentioned in the |
220 // name. The other representations (eg, CONS, EXTERNAL) are explicitly | 220 // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
221 // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a | 221 // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
222 // symbol) or a STRING_TYPE (if it is not a symbol). | 222 // symbol) or a STRING_TYPE (if it is not a symbol). |
223 // | 223 // |
224 // NOTE: The following things are some that depend on the string types having | 224 // NOTE: The following things are some that depend on the string types having |
225 // instance_types that are less than those of all other types: | 225 // instance_types that are less than those of all other types: |
226 // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and | 226 // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
227 // Object::IsString. | 227 // Object::IsString. |
228 // | 228 // |
229 // NOTE: Everything following JS_VALUE_TYPE is considered a | 229 // NOTE: Everything following JS_VALUE_TYPE is considered a |
230 // JSObject for GC purposes. The first four entries here have typeof | 230 // JSObject for GC purposes. The first four entries here have typeof |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); | 485 (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
486 STATIC_ASSERT( | 486 STATIC_ASSERT( |
487 (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); | 487 (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
488 | 488 |
489 // Use this mask to distinguish between cons and slice only after making | 489 // Use this mask to distinguish between cons and slice only after making |
490 // sure that the string is one of the two (an indirect string). | 490 // sure that the string is one of the two (an indirect string). |
491 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; | 491 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
492 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); | 492 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
493 | 493 |
494 // If bit 7 is clear, then bit 3 indicates whether this two-byte | 494 // If bit 7 is clear, then bit 3 indicates whether this two-byte |
495 // string actually contains ascii data. | 495 // string actually contains ASCII data. |
496 const uint32_t kAsciiDataHintMask = 0x08; | 496 const uint32_t kAsciiDataHintMask = 0x08; |
497 const uint32_t kAsciiDataHintTag = 0x08; | 497 const uint32_t kAsciiDataHintTag = 0x08; |
498 | 498 |
499 // If bit 7 is clear and string representation indicates an external string, | 499 // If bit 7 is clear and string representation indicates an external string, |
500 // then bit 4 indicates whether the data pointer is cached. | 500 // then bit 4 indicates whether the data pointer is cached. |
501 const uint32_t kShortExternalStringMask = 0x10; | 501 const uint32_t kShortExternalStringMask = 0x10; |
502 const uint32_t kShortExternalStringTag = 0x10; | 502 const uint32_t kShortExternalStringTag = 0x10; |
503 | 503 |
504 | 504 |
505 // A ConsString with an empty string as the right side is a candidate | 505 // A ConsString with an empty string as the right side is a candidate |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 | 1079 |
1080 private: | 1080 private: |
1081 inline intptr_t value() const; | 1081 inline intptr_t value() const; |
1082 static inline Failure* Construct(Type type, intptr_t value = 0); | 1082 static inline Failure* Construct(Type type, intptr_t value = 0); |
1083 | 1083 |
1084 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); | 1084 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
1085 }; | 1085 }; |
1086 | 1086 |
1087 | 1087 |
1088 // Heap objects typically have a map pointer in their first word. However, | 1088 // Heap objects typically have a map pointer in their first word. However, |
1089 // during GC other data (eg, mark bits, forwarding addresses) is sometimes | 1089 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
1090 // encoded in the first word. The class MapWord is an abstraction of the | 1090 // encoded in the first word. The class MapWord is an abstraction of the |
1091 // value in a heap object's first word. | 1091 // value in a heap object's first word. |
1092 class MapWord BASE_EMBEDDED { | 1092 class MapWord BASE_EMBEDDED { |
1093 public: | 1093 public: |
1094 // Normal state: the map word contains a map pointer. | 1094 // Normal state: the map word contains a map pointer. |
1095 | 1095 |
1096 // Create a map word from a map pointer. | 1096 // Create a map word from a map pointer. |
1097 static inline MapWord FromMap(Map* map); | 1097 static inline MapWord FromMap(Map* map); |
1098 | 1098 |
1099 // View this map word as a map pointer. | 1099 // View this map word as a map pointer. |
1100 inline Map* ToMap(); | 1100 inline Map* ToMap(); |
1101 | 1101 |
1102 | 1102 |
1103 // Scavenge collection: the map word of live objects in the from space | 1103 // Scavenge collection: the map word of live objects in the from space |
1104 // contains a forwarding address (a heap object pointer in the to space). | 1104 // contains a forwarding address (a heap object pointer in the to space). |
1105 | 1105 |
1106 // True if this map word is a forwarding address for a scavenge | 1106 // True if this map word is a forwarding address for a scavenge |
1107 // collection. Only valid during a scavenge collection (specifically, | 1107 // collection. Only valid during a scavenge collection (specifically, |
1108 // when all map words are heap object pointers, ie. not during a full GC). | 1108 // when all map words are heap object pointers, i.e. not during a full GC). |
1109 inline bool IsForwardingAddress(); | 1109 inline bool IsForwardingAddress(); |
1110 | 1110 |
1111 // Create a map word from a forwarding address. | 1111 // Create a map word from a forwarding address. |
1112 static inline MapWord FromForwardingAddress(HeapObject* object); | 1112 static inline MapWord FromForwardingAddress(HeapObject* object); |
1113 | 1113 |
1114 // View this map word as a forwarding address. | 1114 // View this map word as a forwarding address. |
1115 inline HeapObject* ToForwardingAddress(); | 1115 inline HeapObject* ToForwardingAddress(); |
1116 | 1116 |
1117 static inline MapWord FromRawValue(uintptr_t value) { | 1117 static inline MapWord FromRawValue(uintptr_t value) { |
1118 return MapWord(value); | 1118 return MapWord(value); |
(...skipping 5363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6482 // If the string isn't flat, and therefore doesn't have flat content, the | 6482 // If the string isn't flat, and therefore doesn't have flat content, the |
6483 // returned structure will report so, and can't provide a vector of either | 6483 // returned structure will report so, and can't provide a vector of either |
6484 // kind. | 6484 // kind. |
6485 FlatContent GetFlatContent(); | 6485 FlatContent GetFlatContent(); |
6486 | 6486 |
6487 // Returns the parent of a sliced string or first part of a flat cons string. | 6487 // Returns the parent of a sliced string or first part of a flat cons string. |
6488 // Requires: StringShape(this).IsIndirect() && this->IsFlat() | 6488 // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
6489 inline String* GetUnderlying(); | 6489 inline String* GetUnderlying(); |
6490 | 6490 |
6491 // Mark the string as an undetectable object. It only applies to | 6491 // Mark the string as an undetectable object. It only applies to |
6492 // ascii and two byte string types. | 6492 // ASCII and two byte string types. |
6493 bool MarkAsUndetectable(); | 6493 bool MarkAsUndetectable(); |
6494 | 6494 |
6495 // Return a substring. | 6495 // Return a substring. |
6496 MUST_USE_RESULT MaybeObject* SubString(int from, | 6496 MUST_USE_RESULT MaybeObject* SubString(int from, |
6497 int to, | 6497 int to, |
6498 PretenureFlag pretenure = NOT_TENURED); | 6498 PretenureFlag pretenure = NOT_TENURED); |
6499 | 6499 |
6500 // String equality operations. | 6500 // String equality operations. |
6501 inline bool Equals(String* other); | 6501 inline bool Equals(String* other); |
6502 bool IsEqualTo(Vector<const char> str); | 6502 bool IsEqualTo(Vector<const char> str); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6579 | 6579 |
6580 // Layout description. | 6580 // Layout description. |
6581 static const int kLengthOffset = HeapObject::kHeaderSize; | 6581 static const int kLengthOffset = HeapObject::kHeaderSize; |
6582 static const int kHashFieldOffset = kLengthOffset + kPointerSize; | 6582 static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
6583 static const int kSize = kHashFieldOffset + kPointerSize; | 6583 static const int kSize = kHashFieldOffset + kPointerSize; |
6584 | 6584 |
6585 // Maximum number of characters to consider when trying to convert a string | 6585 // Maximum number of characters to consider when trying to convert a string |
6586 // value into an array index. | 6586 // value into an array index. |
6587 static const int kMaxArrayIndexSize = 10; | 6587 static const int kMaxArrayIndexSize = 10; |
6588 | 6588 |
6589 // Max ascii char code. | 6589 // Max ASCII char code. |
6590 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; | 6590 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
6591 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; | 6591 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
6592 static const int kMaxUC16CharCode = 0xffff; | 6592 static const int kMaxUC16CharCode = 0xffff; |
6593 | 6593 |
6594 // Minimum length for a cons string. | 6594 // Minimum length for a cons string. |
6595 static const int kMinNonFlatLength = 13; | 6595 static const int kMinNonFlatLength = 13; |
6596 | 6596 |
6597 // Mask constant for checking if a string has a computed hash code | 6597 // Mask constant for checking if a string has a computed hash code |
6598 // and if it is an array index. The least significant bit indicates | 6598 // and if it is an array index. The least significant bit indicates |
6599 // whether a hash code has been computed. If the hash code has been | 6599 // whether a hash code has been computed. If the hash code has been |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6765 static inline SeqString* cast(Object* obj); | 6765 static inline SeqString* cast(Object* obj); |
6766 | 6766 |
6767 // Layout description. | 6767 // Layout description. |
6768 static const int kHeaderSize = String::kSize; | 6768 static const int kHeaderSize = String::kSize; |
6769 | 6769 |
6770 private: | 6770 private: |
6771 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); | 6771 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
6772 }; | 6772 }; |
6773 | 6773 |
6774 | 6774 |
6775 // The AsciiString class captures sequential ascii string objects. | 6775 // The AsciiString class captures sequential ASCII string objects. |
6776 // Each character in the AsciiString is an ascii character. | 6776 // Each character in the AsciiString is an ASCII character. |
6777 class SeqAsciiString: public SeqString { | 6777 class SeqAsciiString: public SeqString { |
6778 public: | 6778 public: |
6779 static const bool kHasAsciiEncoding = true; | 6779 static const bool kHasAsciiEncoding = true; |
6780 | 6780 |
6781 // Dispatched behavior. | 6781 // Dispatched behavior. |
6782 inline uint16_t SeqAsciiStringGet(int index); | 6782 inline uint16_t SeqAsciiStringGet(int index); |
6783 inline void SeqAsciiStringSet(int index, uint16_t value); | 6783 inline void SeqAsciiStringSet(int index, uint16_t value); |
6784 | 6784 |
6785 // Get the address of the characters in this string. | 6785 // Get the address of the characters in this string. |
6786 inline Address GetCharsAddress(); | 6786 inline Address GetCharsAddress(); |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8191 } else { | 8191 } else { |
8192 value &= ~(1 << bit_position); | 8192 value &= ~(1 << bit_position); |
8193 } | 8193 } |
8194 return value; | 8194 return value; |
8195 } | 8195 } |
8196 }; | 8196 }; |
8197 | 8197 |
8198 } } // namespace v8::internal | 8198 } } // namespace v8::internal |
8199 | 8199 |
8200 #endif // V8_OBJECTS_H_ | 8200 #endif // V8_OBJECTS_H_ |
OLD | NEW |