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

Side by Side Diff: src/objects-inl.h

Issue 2625073002: Revert of Internalize strings in-place (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « src/objects-debug.cc ('k') | src/objects-printer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 STATIC_ASSERT(kNotInternalizedTag != 0); 267 STATIC_ASSERT(kNotInternalizedTag != 0);
268 return (type & (kIsNotStringMask | kIsNotInternalizedMask)) == 268 return (type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
269 (kStringTag | kInternalizedTag); 269 (kStringTag | kInternalizedTag);
270 } 270 }
271 271
272 bool HeapObject::IsConsString() const { 272 bool HeapObject::IsConsString() const {
273 if (!IsString()) return false; 273 if (!IsString()) return false;
274 return StringShape(String::cast(this)).IsCons(); 274 return StringShape(String::cast(this)).IsCons();
275 } 275 }
276 276
277 bool HeapObject::IsThinString() const {
278 if (!IsString()) return false;
279 return StringShape(String::cast(this)).IsThin();
280 }
281
282 bool HeapObject::IsSlicedString() const { 277 bool HeapObject::IsSlicedString() const {
283 if (!IsString()) return false; 278 if (!IsString()) return false;
284 return StringShape(String::cast(this)).IsSliced(); 279 return StringShape(String::cast(this)).IsSliced();
285 } 280 }
286 281
287 bool HeapObject::IsSeqString() const { 282 bool HeapObject::IsSeqString() const {
288 if (!IsString()) return false; 283 if (!IsString()) return false;
289 return StringShape(String::cast(this)).IsSequential(); 284 return StringShape(String::cast(this)).IsSequential();
290 } 285 }
291 286
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 CAST_ACCESSOR(SharedFunctionInfo) 690 CAST_ACCESSOR(SharedFunctionInfo)
696 CAST_ACCESSOR(Simd128Value) 691 CAST_ACCESSOR(Simd128Value)
697 CAST_ACCESSOR(SlicedString) 692 CAST_ACCESSOR(SlicedString)
698 CAST_ACCESSOR(Smi) 693 CAST_ACCESSOR(Smi)
699 CAST_ACCESSOR(String) 694 CAST_ACCESSOR(String)
700 CAST_ACCESSOR(StringSet) 695 CAST_ACCESSOR(StringSet)
701 CAST_ACCESSOR(StringTable) 696 CAST_ACCESSOR(StringTable)
702 CAST_ACCESSOR(Struct) 697 CAST_ACCESSOR(Struct)
703 CAST_ACCESSOR(Symbol) 698 CAST_ACCESSOR(Symbol)
704 CAST_ACCESSOR(TemplateInfo) 699 CAST_ACCESSOR(TemplateInfo)
705 CAST_ACCESSOR(ThinString)
706 CAST_ACCESSOR(Uint16x8) 700 CAST_ACCESSOR(Uint16x8)
707 CAST_ACCESSOR(Uint32x4) 701 CAST_ACCESSOR(Uint32x4)
708 CAST_ACCESSOR(Uint8x16) 702 CAST_ACCESSOR(Uint8x16)
709 CAST_ACCESSOR(UnseededNumberDictionary) 703 CAST_ACCESSOR(UnseededNumberDictionary)
710 CAST_ACCESSOR(WeakCell) 704 CAST_ACCESSOR(WeakCell)
711 CAST_ACCESSOR(WeakFixedArray) 705 CAST_ACCESSOR(WeakFixedArray)
712 CAST_ACCESSOR(WeakHashTable) 706 CAST_ACCESSOR(WeakHashTable)
713 707
714 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) 708 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name)
715 STRUCT_LIST(MAKE_STRUCT_CAST) 709 STRUCT_LIST(MAKE_STRUCT_CAST)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 bool String::HasOnlyOneByteChars() { 836 bool String::HasOnlyOneByteChars() {
843 uint32_t type = map()->instance_type(); 837 uint32_t type = map()->instance_type();
844 return (type & kOneByteDataHintMask) == kOneByteDataHintTag || 838 return (type & kOneByteDataHintMask) == kOneByteDataHintTag ||
845 IsOneByteRepresentation(); 839 IsOneByteRepresentation();
846 } 840 }
847 841
848 bool StringShape::IsCons() { 842 bool StringShape::IsCons() {
849 return (type_ & kStringRepresentationMask) == kConsStringTag; 843 return (type_ & kStringRepresentationMask) == kConsStringTag;
850 } 844 }
851 845
852 bool StringShape::IsThin() {
853 return (type_ & kStringRepresentationMask) == kThinStringTag;
854 }
855
856 bool StringShape::IsSliced() { 846 bool StringShape::IsSliced() {
857 return (type_ & kStringRepresentationMask) == kSlicedStringTag; 847 return (type_ & kStringRepresentationMask) == kSlicedStringTag;
858 } 848 }
859 849
860 bool StringShape::IsIndirect() { 850 bool StringShape::IsIndirect() {
861 return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag; 851 return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag;
862 } 852 }
863 853
864 bool StringShape::IsExternal() { 854 bool StringShape::IsExternal() {
865 return (type_ & kStringRepresentationMask) == kExternalStringTag; 855 return (type_ & kStringRepresentationMask) == kExternalStringTag;
(...skipping 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 bool String::Equals(Handle<String> one, Handle<String> two) { 3712 bool String::Equals(Handle<String> one, Handle<String> two) {
3723 if (one.is_identical_to(two)) return true; 3713 if (one.is_identical_to(two)) return true;
3724 if (one->IsInternalizedString() && two->IsInternalizedString()) { 3714 if (one->IsInternalizedString() && two->IsInternalizedString()) {
3725 return false; 3715 return false;
3726 } 3716 }
3727 return SlowEquals(one, two); 3717 return SlowEquals(one, two);
3728 } 3718 }
3729 3719
3730 3720
3731 Handle<String> String::Flatten(Handle<String> string, PretenureFlag pretenure) { 3721 Handle<String> String::Flatten(Handle<String> string, PretenureFlag pretenure) {
3732 if (string->IsConsString()) { 3722 if (!string->IsConsString()) return string;
3733 Handle<ConsString> cons = Handle<ConsString>::cast(string); 3723 Handle<ConsString> cons = Handle<ConsString>::cast(string);
3734 if (cons->IsFlat()) { 3724 if (cons->IsFlat()) return handle(cons->first());
3735 string = handle(cons->first()); 3725 return SlowFlatten(cons, pretenure);
3736 } else {
3737 return SlowFlatten(cons, pretenure);
3738 }
3739 }
3740 if (string->IsThinString()) {
3741 string = handle(Handle<ThinString>::cast(string)->actual());
3742 DCHECK(!string->IsConsString());
3743 }
3744 return string;
3745 } 3726 }
3746 3727
3747 3728
3748 uint16_t String::Get(int index) { 3729 uint16_t String::Get(int index) {
3749 DCHECK(index >= 0 && index < length()); 3730 DCHECK(index >= 0 && index < length());
3750 switch (StringShape(this).full_representation_tag()) { 3731 switch (StringShape(this).full_representation_tag()) {
3751 case kSeqStringTag | kOneByteStringTag: 3732 case kSeqStringTag | kOneByteStringTag:
3752 return SeqOneByteString::cast(this)->SeqOneByteStringGet(index); 3733 return SeqOneByteString::cast(this)->SeqOneByteStringGet(index);
3753 case kSeqStringTag | kTwoByteStringTag: 3734 case kSeqStringTag | kTwoByteStringTag:
3754 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 3735 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
3755 case kConsStringTag | kOneByteStringTag: 3736 case kConsStringTag | kOneByteStringTag:
3756 case kConsStringTag | kTwoByteStringTag: 3737 case kConsStringTag | kTwoByteStringTag:
3757 return ConsString::cast(this)->ConsStringGet(index); 3738 return ConsString::cast(this)->ConsStringGet(index);
3758 case kExternalStringTag | kOneByteStringTag: 3739 case kExternalStringTag | kOneByteStringTag:
3759 return ExternalOneByteString::cast(this)->ExternalOneByteStringGet(index); 3740 return ExternalOneByteString::cast(this)->ExternalOneByteStringGet(index);
3760 case kExternalStringTag | kTwoByteStringTag: 3741 case kExternalStringTag | kTwoByteStringTag:
3761 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 3742 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
3762 case kSlicedStringTag | kOneByteStringTag: 3743 case kSlicedStringTag | kOneByteStringTag:
3763 case kSlicedStringTag | kTwoByteStringTag: 3744 case kSlicedStringTag | kTwoByteStringTag:
3764 return SlicedString::cast(this)->SlicedStringGet(index); 3745 return SlicedString::cast(this)->SlicedStringGet(index);
3765 case kThinStringTag | kOneByteStringTag:
3766 case kThinStringTag | kTwoByteStringTag:
3767 return ThinString::cast(this)->ThinStringGet(index);
3768 default: 3746 default:
3769 break; 3747 break;
3770 } 3748 }
3771 3749
3772 UNREACHABLE(); 3750 UNREACHABLE();
3773 return 0; 3751 return 0;
3774 } 3752 }
3775 3753
3776 3754
3777 void String::Set(int index, uint16_t value) { 3755 void String::Set(int index, uint16_t value) {
(...skipping 11 matching lines...) Expand all
3789 return ConsString::cast(this)->second()->length() == 0; 3767 return ConsString::cast(this)->second()->length() == 0;
3790 } 3768 }
3791 3769
3792 3770
3793 String* String::GetUnderlying() { 3771 String* String::GetUnderlying() {
3794 // Giving direct access to underlying string only makes sense if the 3772 // Giving direct access to underlying string only makes sense if the
3795 // wrapping string is already flattened. 3773 // wrapping string is already flattened.
3796 DCHECK(this->IsFlat()); 3774 DCHECK(this->IsFlat());
3797 DCHECK(StringShape(this).IsIndirect()); 3775 DCHECK(StringShape(this).IsIndirect());
3798 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset); 3776 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset);
3799 STATIC_ASSERT(ConsString::kFirstOffset == ThinString::kActualOffset);
3800 const int kUnderlyingOffset = SlicedString::kParentOffset; 3777 const int kUnderlyingOffset = SlicedString::kParentOffset;
3801 return String::cast(READ_FIELD(this, kUnderlyingOffset)); 3778 return String::cast(READ_FIELD(this, kUnderlyingOffset));
3802 } 3779 }
3803 3780
3804 3781
3805 template<class Visitor> 3782 template<class Visitor>
3806 ConsString* String::VisitFlat(Visitor* visitor, 3783 ConsString* String::VisitFlat(Visitor* visitor,
3807 String* string, 3784 String* string,
3808 const int offset) { 3785 const int offset) {
3809 int slice_offset = offset; 3786 int slice_offset = offset;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3841 SlicedString* slicedString = SlicedString::cast(string); 3818 SlicedString* slicedString = SlicedString::cast(string);
3842 slice_offset += slicedString->offset(); 3819 slice_offset += slicedString->offset();
3843 string = slicedString->parent(); 3820 string = slicedString->parent();
3844 continue; 3821 continue;
3845 } 3822 }
3846 3823
3847 case kConsStringTag | kOneByteStringTag: 3824 case kConsStringTag | kOneByteStringTag:
3848 case kConsStringTag | kTwoByteStringTag: 3825 case kConsStringTag | kTwoByteStringTag:
3849 return ConsString::cast(string); 3826 return ConsString::cast(string);
3850 3827
3851 case kThinStringTag | kOneByteStringTag:
3852 case kThinStringTag | kTwoByteStringTag:
3853 string = ThinString::cast(string)->actual();
3854 continue;
3855
3856 default: 3828 default:
3857 UNREACHABLE(); 3829 UNREACHABLE();
3858 return NULL; 3830 return NULL;
3859 } 3831 }
3860 } 3832 }
3861 } 3833 }
3862 3834
3863 3835
3864 template <> 3836 template <>
3865 inline Vector<const uint8_t> String::GetCharVector() { 3837 inline Vector<const uint8_t> String::GetCharVector() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3977 Object* ConsString::unchecked_second() { 3949 Object* ConsString::unchecked_second() {
3978 return READ_FIELD(this, kSecondOffset); 3950 return READ_FIELD(this, kSecondOffset);
3979 } 3951 }
3980 3952
3981 3953
3982 void ConsString::set_second(String* value, WriteBarrierMode mode) { 3954 void ConsString::set_second(String* value, WriteBarrierMode mode) {
3983 WRITE_FIELD(this, kSecondOffset, value); 3955 WRITE_FIELD(this, kSecondOffset, value);
3984 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); 3956 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode);
3985 } 3957 }
3986 3958
3987 ACCESSORS(ThinString, actual, String, kActualOffset);
3988 3959
3989 bool ExternalString::is_short() { 3960 bool ExternalString::is_short() {
3990 InstanceType type = map()->instance_type(); 3961 InstanceType type = map()->instance_type();
3991 return (type & kShortExternalStringMask) == kShortExternalStringTag; 3962 return (type & kShortExternalStringMask) == kShortExternalStringTag;
3992 } 3963 }
3993 3964
3994 3965
3995 const ExternalOneByteString::Resource* ExternalOneByteString::resource() { 3966 const ExternalOneByteString::Resource* ExternalOneByteString::resource() {
3996 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); 3967 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset));
3997 } 3968 }
(...skipping 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after
8501 #undef WRITE_INT64_FIELD 8472 #undef WRITE_INT64_FIELD
8502 #undef READ_BYTE_FIELD 8473 #undef READ_BYTE_FIELD
8503 #undef WRITE_BYTE_FIELD 8474 #undef WRITE_BYTE_FIELD
8504 #undef NOBARRIER_READ_BYTE_FIELD 8475 #undef NOBARRIER_READ_BYTE_FIELD
8505 #undef NOBARRIER_WRITE_BYTE_FIELD 8476 #undef NOBARRIER_WRITE_BYTE_FIELD
8506 8477
8507 } // namespace internal 8478 } // namespace internal
8508 } // namespace v8 8479 } // namespace v8
8509 8480
8510 #endif // V8_OBJECTS_INL_H_ 8481 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698