Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/objects.h

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: forgot one Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <memory> 9 #include <memory>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // - ScriptContextTable 100 // - ScriptContextTable
101 // - WeakFixedArray 101 // - WeakFixedArray
102 // - FixedDoubleArray 102 // - FixedDoubleArray
103 // - Name 103 // - Name
104 // - String 104 // - String
105 // - SeqString 105 // - SeqString
106 // - SeqOneByteString 106 // - SeqOneByteString
107 // - SeqTwoByteString 107 // - SeqTwoByteString
108 // - SlicedString 108 // - SlicedString
109 // - ConsString 109 // - ConsString
110 // - ThinString
110 // - ExternalString 111 // - ExternalString
111 // - ExternalOneByteString 112 // - ExternalOneByteString
112 // - ExternalTwoByteString 113 // - ExternalTwoByteString
113 // - InternalizedString 114 // - InternalizedString
114 // - SeqInternalizedString 115 // - SeqInternalizedString
115 // - SeqOneByteInternalizedString 116 // - SeqOneByteInternalizedString
116 // - SeqTwoByteInternalizedString 117 // - SeqTwoByteInternalizedString
117 // - ConsInternalizedString 118 // - ConsInternalizedString
118 // - ExternalInternalizedString 119 // - ExternalInternalizedString
119 // - ExternalOneByteInternalizedString 120 // - ExternalOneByteInternalizedString
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // Object::IsString. 318 // Object::IsString.
318 // 319 //
319 // NOTE: Everything following JS_VALUE_TYPE is considered a 320 // NOTE: Everything following JS_VALUE_TYPE is considered a
320 // JSObject for GC purposes. The first four entries here have typeof 321 // JSObject for GC purposes. The first four entries here have typeof
321 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. 322 // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
322 #define INSTANCE_TYPE_LIST(V) \ 323 #define INSTANCE_TYPE_LIST(V) \
323 V(STRING_TYPE) \ 324 V(STRING_TYPE) \
324 V(ONE_BYTE_STRING_TYPE) \ 325 V(ONE_BYTE_STRING_TYPE) \
325 V(CONS_STRING_TYPE) \ 326 V(CONS_STRING_TYPE) \
326 V(CONS_ONE_BYTE_STRING_TYPE) \ 327 V(CONS_ONE_BYTE_STRING_TYPE) \
328 V(THIN_STRING_TYPE) \
329 V(THIN_ONE_BYTE_STRING_TYPE) \
327 V(SLICED_STRING_TYPE) \ 330 V(SLICED_STRING_TYPE) \
328 V(SLICED_ONE_BYTE_STRING_TYPE) \ 331 V(SLICED_ONE_BYTE_STRING_TYPE) \
329 V(EXTERNAL_STRING_TYPE) \ 332 V(EXTERNAL_STRING_TYPE) \
330 V(EXTERNAL_ONE_BYTE_STRING_TYPE) \ 333 V(EXTERNAL_ONE_BYTE_STRING_TYPE) \
331 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ 334 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
332 V(SHORT_EXTERNAL_STRING_TYPE) \ 335 V(SHORT_EXTERNAL_STRING_TYPE) \
333 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \ 336 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \
334 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ 337 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
335 \ 338 \
336 V(INTERNALIZED_STRING_TYPE) \ 339 V(INTERNALIZED_STRING_TYPE) \
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \ 520 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \
518 ExternalTwoByteString::kShortSize, short_external_internalized_string, \ 521 ExternalTwoByteString::kShortSize, short_external_internalized_string, \
519 ShortExternalInternalizedString) \ 522 ShortExternalInternalizedString) \
520 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \ 523 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \
521 ExternalOneByteString::kShortSize, \ 524 ExternalOneByteString::kShortSize, \
522 short_external_one_byte_internalized_string, \ 525 short_external_one_byte_internalized_string, \
523 ShortExternalOneByteInternalizedString) \ 526 ShortExternalOneByteInternalizedString) \
524 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ 527 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
525 ExternalTwoByteString::kShortSize, \ 528 ExternalTwoByteString::kShortSize, \
526 short_external_internalized_string_with_one_byte_data, \ 529 short_external_internalized_string_with_one_byte_data, \
527 ShortExternalInternalizedStringWithOneByteData) 530 ShortExternalInternalizedStringWithOneByteData) \
531 V(THIN_STRING_TYPE, ThinString::kSize, thin_string, ThinString) \
532 V(THIN_ONE_BYTE_STRING_TYPE, ThinString::kSize, thin_one_byte_string, \
533 ThinOneByteString)
528 534
529 // A struct is a simple object a set of object-valued fields. Including an 535 // A struct is a simple object a set of object-valued fields. Including an
530 // object type in this causes the compiler to generate most of the boilerplate 536 // object type in this causes the compiler to generate most of the boilerplate
531 // code for the class including allocation and garbage collection routines, 537 // code for the class including allocation and garbage collection routines,
532 // casts and predicates. All you need to define is the class, methods and 538 // casts and predicates. All you need to define is the class, methods and
533 // object verification routines. Easy, no? 539 // object verification routines. Easy, no?
534 // 540 //
535 // Note that for subtle reasons related to the ordering or numerical values of 541 // Note that for subtle reasons related to the ordering or numerical values of
536 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST 542 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
537 // manually. 543 // manually.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 const uint32_t kIsNotStringMask = 0x80; 575 const uint32_t kIsNotStringMask = 0x80;
570 const uint32_t kStringTag = 0x0; 576 const uint32_t kStringTag = 0x0;
571 const uint32_t kNotStringTag = 0x80; 577 const uint32_t kNotStringTag = 0x80;
572 578
573 // Bit 6 indicates that the object is an internalized string (if set) or not. 579 // Bit 6 indicates that the object is an internalized string (if set) or not.
574 // Bit 7 has to be clear as well. 580 // Bit 7 has to be clear as well.
575 const uint32_t kIsNotInternalizedMask = 0x40; 581 const uint32_t kIsNotInternalizedMask = 0x40;
576 const uint32_t kNotInternalizedTag = 0x40; 582 const uint32_t kNotInternalizedTag = 0x40;
577 const uint32_t kInternalizedTag = 0x0; 583 const uint32_t kInternalizedTag = 0x0;
578 584
579 // If bit 7 is clear then bit 2 indicates whether the string consists of 585 // If bit 7 is clear then bit 3 indicates whether the string consists of
580 // two-byte characters or one-byte characters. 586 // two-byte characters or one-byte characters.
581 const uint32_t kStringEncodingMask = 0x4; 587 const uint32_t kStringEncodingMask = 0x8;
582 const uint32_t kTwoByteStringTag = 0x0; 588 const uint32_t kTwoByteStringTag = 0x0;
583 const uint32_t kOneByteStringTag = 0x4; 589 const uint32_t kOneByteStringTag = 0x8;
584 590
585 // If bit 7 is clear, the low-order 2 bits indicate the representation 591 // If bit 7 is clear, the low-order 3 bits indicate the representation
586 // of the string. 592 // of the string.
587 const uint32_t kStringRepresentationMask = 0x03; 593 const uint32_t kStringRepresentationMask = 0x07;
588 enum StringRepresentationTag { 594 enum StringRepresentationTag {
589 kSeqStringTag = 0x0, 595 kSeqStringTag = 0x0,
590 kConsStringTag = 0x1, 596 kConsStringTag = 0x1,
591 kExternalStringTag = 0x2, 597 kExternalStringTag = 0x2,
592 kSlicedStringTag = 0x3 598 kSlicedStringTag = 0x3,
599 kThinStringTag = 0x5
593 }; 600 };
594 const uint32_t kIsIndirectStringMask = 0x1; 601 const uint32_t kIsIndirectStringMask = 0x1;
595 const uint32_t kIsIndirectStringTag = 0x1; 602 const uint32_t kIsIndirectStringTag = 0x1;
596 STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT 603 STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT
597 STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT 604 STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT
598 STATIC_ASSERT((kConsStringTag & 605 STATIC_ASSERT((kConsStringTag &
599 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT 606 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
600 STATIC_ASSERT((kSlicedStringTag & 607 STATIC_ASSERT((kSlicedStringTag &
601 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT 608 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
609 STATIC_ASSERT((kThinStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
602 610
603 // Use this mask to distinguish between cons and slice only after making 611 // If bit 7 is clear, then bit 4 indicates whether this two-byte
604 // sure that the string is one of the two (an indirect string).
605 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
606 STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask));
607
608 // If bit 7 is clear, then bit 3 indicates whether this two-byte
609 // string actually contains one byte data. 612 // string actually contains one byte data.
610 const uint32_t kOneByteDataHintMask = 0x08; 613 const uint32_t kOneByteDataHintMask = 0x10;
611 const uint32_t kOneByteDataHintTag = 0x08; 614 const uint32_t kOneByteDataHintTag = 0x10;
612 615
613 // If bit 7 is clear and string representation indicates an external string, 616 // If bit 7 is clear and string representation indicates an external string,
614 // then bit 4 indicates whether the data pointer is cached. 617 // then bit 5 indicates whether the data pointer is cached.
615 const uint32_t kShortExternalStringMask = 0x10; 618 const uint32_t kShortExternalStringMask = 0x20;
616 const uint32_t kShortExternalStringTag = 0x10; 619 const uint32_t kShortExternalStringTag = 0x20;
617
618 620
619 // A ConsString with an empty string as the right side is a candidate 621 // A ConsString with an empty string as the right side is a candidate
620 // for being shortcut by the garbage collector. We don't allocate any 622 // for being shortcut by the garbage collector. We don't allocate any
621 // non-flat internalized strings, so we do not shortcut them thereby 623 // non-flat internalized strings, so we do not shortcut them thereby
622 // avoiding turning internalized strings into strings. The bit-masks 624 // avoiding turning internalized strings into strings. The bit-masks
623 // below contain the internalized bit as additional safety. 625 // below contain the internalized bit as additional safety.
624 // See heap.cc, mark-compact.cc and objects-visiting.cc. 626 // See heap.cc, mark-compact.cc and objects-visiting.cc.
625 const uint32_t kShortcutTypeMask = 627 const uint32_t kShortcutTypeMask =
626 kIsNotStringMask | 628 kIsNotStringMask |
627 kIsNotInternalizedMask | 629 kIsNotInternalizedMask |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = 673 EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
672 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | 674 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
673 kNotInternalizedTag, 675 kNotInternalizedTag,
674 SHORT_EXTERNAL_STRING_TYPE = 676 SHORT_EXTERNAL_STRING_TYPE =
675 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, 677 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
676 SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE = 678 SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE =
677 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, 679 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
678 SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = 680 SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
679 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | 681 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
680 kNotInternalizedTag, 682 kNotInternalizedTag,
683 THIN_STRING_TYPE = kTwoByteStringTag | kThinStringTag | kNotInternalizedTag,
684 THIN_ONE_BYTE_STRING_TYPE =
685 kOneByteStringTag | kThinStringTag | kNotInternalizedTag,
681 686
682 // Non-string names 687 // Non-string names
683 SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE 688 SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE
684 689
685 // Other primitives (cannot contain non-map-word pointers to heap objects). 690 // Other primitives (cannot contain non-map-word pointers to heap objects).
686 HEAP_NUMBER_TYPE, 691 HEAP_NUMBER_TYPE,
687 SIMD128_VALUE_TYPE, 692 SIMD128_VALUE_TYPE,
688 ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE 693 ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE
689 694
690 // Objects allocated in their own spaces (never in new space). 695 // Objects allocated in their own spaces (never in new space).
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 V(String) \ 1050 V(String) \
1046 V(SeqString) \ 1051 V(SeqString) \
1047 V(ExternalString) \ 1052 V(ExternalString) \
1048 V(ConsString) \ 1053 V(ConsString) \
1049 V(SlicedString) \ 1054 V(SlicedString) \
1050 V(ExternalTwoByteString) \ 1055 V(ExternalTwoByteString) \
1051 V(ExternalOneByteString) \ 1056 V(ExternalOneByteString) \
1052 V(SeqTwoByteString) \ 1057 V(SeqTwoByteString) \
1053 V(SeqOneByteString) \ 1058 V(SeqOneByteString) \
1054 V(InternalizedString) \ 1059 V(InternalizedString) \
1060 V(ThinString) \
1055 V(Symbol) \ 1061 V(Symbol) \
1056 \ 1062 \
1057 V(FixedTypedArrayBase) \ 1063 V(FixedTypedArrayBase) \
1058 V(FixedUint8Array) \ 1064 V(FixedUint8Array) \
1059 V(FixedInt8Array) \ 1065 V(FixedInt8Array) \
1060 V(FixedUint16Array) \ 1066 V(FixedUint16Array) \
1061 V(FixedInt16Array) \ 1067 V(FixedInt16Array) \
1062 V(FixedUint32Array) \ 1068 V(FixedUint32Array) \
1063 V(FixedInt32Array) \ 1069 V(FixedInt32Array) \
1064 V(FixedFloat32Array) \ 1070 V(FixedFloat32Array) \
(...skipping 8523 matching lines...) Expand 10 before | Expand all | Expand 10 after
9588 // concrete performance benefit at that particular point in the code. 9594 // concrete performance benefit at that particular point in the code.
9589 class StringShape BASE_EMBEDDED { 9595 class StringShape BASE_EMBEDDED {
9590 public: 9596 public:
9591 inline explicit StringShape(const String* s); 9597 inline explicit StringShape(const String* s);
9592 inline explicit StringShape(Map* s); 9598 inline explicit StringShape(Map* s);
9593 inline explicit StringShape(InstanceType t); 9599 inline explicit StringShape(InstanceType t);
9594 inline bool IsSequential(); 9600 inline bool IsSequential();
9595 inline bool IsExternal(); 9601 inline bool IsExternal();
9596 inline bool IsCons(); 9602 inline bool IsCons();
9597 inline bool IsSliced(); 9603 inline bool IsSliced();
9604 inline bool IsThin();
9598 inline bool IsIndirect(); 9605 inline bool IsIndirect();
9599 inline bool IsExternalOneByte(); 9606 inline bool IsExternalOneByte();
9600 inline bool IsExternalTwoByte(); 9607 inline bool IsExternalTwoByte();
9601 inline bool IsSequentialOneByte(); 9608 inline bool IsSequentialOneByte();
9602 inline bool IsSequentialTwoByte(); 9609 inline bool IsSequentialTwoByte();
9603 inline bool IsInternalized(); 9610 inline bool IsInternalized();
9604 inline StringRepresentationTag representation_tag(); 9611 inline StringRepresentationTag representation_tag();
9605 inline uint32_t encoding_tag(); 9612 inline uint32_t encoding_tag();
9606 inline uint32_t full_representation_tag(); 9613 inline uint32_t full_representation_tag();
9607 inline uint32_t size_tag(); 9614 inline uint32_t size_tag();
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
10300 10307
10301 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> 10308 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
10302 BodyDescriptor; 10309 BodyDescriptor;
10303 10310
10304 DECLARE_VERIFIER(ConsString) 10311 DECLARE_VERIFIER(ConsString)
10305 10312
10306 private: 10313 private:
10307 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); 10314 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
10308 }; 10315 };
10309 10316
10317 class ThinString : public String {
Hannes Payer (out of office) 2016/12/21 09:53:14 Please add a description what a ThinString is.
Jakob Kummerow 2017/01/04 12:45:06 Done.
10318 public:
10319 // Actual string that this ThinString refers to.
10320 inline String* actual() const;
10321 inline void set_actual(String* s,
10322 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
10323
10324 V8_EXPORT_PRIVATE uint16_t ThinStringGet(int index);
10325
10326 DECLARE_CAST(ThinString)
10327 DECLARE_VERIFIER(ThinString)
10328
10329 // Layout description.
10330 static const int kActualOffset = String::kSize;
10331 static const int kSize = kActualOffset + kPointerSize;
10332
10333 typedef FixedBodyDescriptor<kActualOffset, kSize, kSize> BodyDescriptor;
10334
10335 private:
10336 DISALLOW_COPY_AND_ASSIGN(ThinString);
10337 };
10310 10338
10311 // The Sliced String class describes strings that are substrings of another 10339 // The Sliced String class describes strings that are substrings of another
10312 // sequential string. The motivation is to save time and memory when creating 10340 // sequential string. The motivation is to save time and memory when creating
10313 // a substring. A Sliced String is described as a pointer to the parent, 10341 // a substring. A Sliced String is described as a pointer to the parent,
10314 // the offset from the start of the parent string and the length. Using 10342 // the offset from the start of the parent string and the length. Using
10315 // a Sliced String therefore requires unpacking of the parent string and 10343 // a Sliced String therefore requires unpacking of the parent string and
10316 // adding the offset to the start address. A substring of a Sliced String 10344 // adding the offset to the start address. A substring of a Sliced String
10317 // are not nested since the double indirection is simplified when creating 10345 // are not nested since the double indirection is simplified when creating
10318 // such a substring. 10346 // such a substring.
10319 // Currently missing features are: 10347 // Currently missing features are:
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
12029 } 12057 }
12030 return value; 12058 return value;
12031 } 12059 }
12032 }; 12060 };
12033 12061
12034 12062
12035 } // NOLINT, false-positive due to second-order macros. 12063 } // NOLINT, false-positive due to second-order macros.
12036 } // NOLINT, false-positive due to second-order macros. 12064 } // NOLINT, false-positive due to second-order macros.
12037 12065
12038 #endif // V8_OBJECTS_H_ 12066 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698