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

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

Issue 2621913002: 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->IsThinString()) {
3733 return handle(Handle<ThinString>::cast(string)->actual());
3734 }
3735 if (!string->IsConsString()) return string; 3722 if (!string->IsConsString()) return string;
3736 Handle<ConsString> cons = Handle<ConsString>::cast(string); 3723 Handle<ConsString> cons = Handle<ConsString>::cast(string);
3737 if (cons->IsFlat()) return handle(cons->first()); 3724 if (cons->IsFlat()) return handle(cons->first());
3738 return SlowFlatten(cons, pretenure); 3725 return SlowFlatten(cons, pretenure);
3739 } 3726 }
3740 3727
3741 3728
3742 uint16_t String::Get(int index) { 3729 uint16_t String::Get(int index) {
3743 DCHECK(index >= 0 && index < length()); 3730 DCHECK(index >= 0 && index < length());
3744 switch (StringShape(this).full_representation_tag()) { 3731 switch (StringShape(this).full_representation_tag()) {
3745 case kSeqStringTag | kOneByteStringTag: 3732 case kSeqStringTag | kOneByteStringTag:
3746 return SeqOneByteString::cast(this)->SeqOneByteStringGet(index); 3733 return SeqOneByteString::cast(this)->SeqOneByteStringGet(index);
3747 case kSeqStringTag | kTwoByteStringTag: 3734 case kSeqStringTag | kTwoByteStringTag:
3748 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 3735 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
3749 case kConsStringTag | kOneByteStringTag: 3736 case kConsStringTag | kOneByteStringTag:
3750 case kConsStringTag | kTwoByteStringTag: 3737 case kConsStringTag | kTwoByteStringTag:
3751 return ConsString::cast(this)->ConsStringGet(index); 3738 return ConsString::cast(this)->ConsStringGet(index);
3752 case kExternalStringTag | kOneByteStringTag: 3739 case kExternalStringTag | kOneByteStringTag:
3753 return ExternalOneByteString::cast(this)->ExternalOneByteStringGet(index); 3740 return ExternalOneByteString::cast(this)->ExternalOneByteStringGet(index);
3754 case kExternalStringTag | kTwoByteStringTag: 3741 case kExternalStringTag | kTwoByteStringTag:
3755 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 3742 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
3756 case kSlicedStringTag | kOneByteStringTag: 3743 case kSlicedStringTag | kOneByteStringTag:
3757 case kSlicedStringTag | kTwoByteStringTag: 3744 case kSlicedStringTag | kTwoByteStringTag:
3758 return SlicedString::cast(this)->SlicedStringGet(index); 3745 return SlicedString::cast(this)->SlicedStringGet(index);
3759 case kThinStringTag | kOneByteStringTag:
3760 case kThinStringTag | kTwoByteStringTag:
3761 return ThinString::cast(this)->ThinStringGet(index);
3762 default: 3746 default:
3763 break; 3747 break;
3764 } 3748 }
3765 3749
3766 UNREACHABLE(); 3750 UNREACHABLE();
3767 return 0; 3751 return 0;
3768 } 3752 }
3769 3753
3770 3754
3771 void String::Set(int index, uint16_t value) { 3755 void String::Set(int index, uint16_t value) {
(...skipping 11 matching lines...) Expand all
3783 return ConsString::cast(this)->second()->length() == 0; 3767 return ConsString::cast(this)->second()->length() == 0;
3784 } 3768 }
3785 3769
3786 3770
3787 String* String::GetUnderlying() { 3771 String* String::GetUnderlying() {
3788 // Giving direct access to underlying string only makes sense if the 3772 // Giving direct access to underlying string only makes sense if the
3789 // wrapping string is already flattened. 3773 // wrapping string is already flattened.
3790 DCHECK(this->IsFlat()); 3774 DCHECK(this->IsFlat());
3791 DCHECK(StringShape(this).IsIndirect()); 3775 DCHECK(StringShape(this).IsIndirect());
3792 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset); 3776 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset);
3793 STATIC_ASSERT(ConsString::kFirstOffset == ThinString::kActualOffset);
3794 const int kUnderlyingOffset = SlicedString::kParentOffset; 3777 const int kUnderlyingOffset = SlicedString::kParentOffset;
3795 return String::cast(READ_FIELD(this, kUnderlyingOffset)); 3778 return String::cast(READ_FIELD(this, kUnderlyingOffset));
3796 } 3779 }
3797 3780
3798 3781
3799 template<class Visitor> 3782 template<class Visitor>
3800 ConsString* String::VisitFlat(Visitor* visitor, 3783 ConsString* String::VisitFlat(Visitor* visitor,
3801 String* string, 3784 String* string,
3802 const int offset) { 3785 const int offset) {
3803 int slice_offset = offset; 3786 int slice_offset = offset;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 SlicedString* slicedString = SlicedString::cast(string); 3818 SlicedString* slicedString = SlicedString::cast(string);
3836 slice_offset += slicedString->offset(); 3819 slice_offset += slicedString->offset();
3837 string = slicedString->parent(); 3820 string = slicedString->parent();
3838 continue; 3821 continue;
3839 } 3822 }
3840 3823
3841 case kConsStringTag | kOneByteStringTag: 3824 case kConsStringTag | kOneByteStringTag:
3842 case kConsStringTag | kTwoByteStringTag: 3825 case kConsStringTag | kTwoByteStringTag:
3843 return ConsString::cast(string); 3826 return ConsString::cast(string);
3844 3827
3845 case kThinStringTag | kOneByteStringTag:
3846 case kThinStringTag | kTwoByteStringTag:
3847 string = ThinString::cast(string)->actual();
3848 continue;
3849
3850 default: 3828 default:
3851 UNREACHABLE(); 3829 UNREACHABLE();
3852 return NULL; 3830 return NULL;
3853 } 3831 }
3854 } 3832 }
3855 } 3833 }
3856 3834
3857 3835
3858 template <> 3836 template <>
3859 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
3971 Object* ConsString::unchecked_second() { 3949 Object* ConsString::unchecked_second() {
3972 return READ_FIELD(this, kSecondOffset); 3950 return READ_FIELD(this, kSecondOffset);
3973 } 3951 }
3974 3952
3975 3953
3976 void ConsString::set_second(String* value, WriteBarrierMode mode) { 3954 void ConsString::set_second(String* value, WriteBarrierMode mode) {
3977 WRITE_FIELD(this, kSecondOffset, value); 3955 WRITE_FIELD(this, kSecondOffset, value);
3978 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); 3956 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode);
3979 } 3957 }
3980 3958
3981 ACCESSORS(ThinString, actual, String, kActualOffset);
3982 3959
3983 bool ExternalString::is_short() { 3960 bool ExternalString::is_short() {
3984 InstanceType type = map()->instance_type(); 3961 InstanceType type = map()->instance_type();
3985 return (type & kShortExternalStringMask) == kShortExternalStringTag; 3962 return (type & kShortExternalStringMask) == kShortExternalStringTag;
3986 } 3963 }
3987 3964
3988 3965
3989 const ExternalOneByteString::Resource* ExternalOneByteString::resource() { 3966 const ExternalOneByteString::Resource* ExternalOneByteString::resource() {
3990 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); 3967 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset));
3991 } 3968 }
(...skipping 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after
8495 #undef WRITE_INT64_FIELD 8472 #undef WRITE_INT64_FIELD
8496 #undef READ_BYTE_FIELD 8473 #undef READ_BYTE_FIELD
8497 #undef WRITE_BYTE_FIELD 8474 #undef WRITE_BYTE_FIELD
8498 #undef NOBARRIER_READ_BYTE_FIELD 8475 #undef NOBARRIER_READ_BYTE_FIELD
8499 #undef NOBARRIER_WRITE_BYTE_FIELD 8476 #undef NOBARRIER_WRITE_BYTE_FIELD
8500 8477
8501 } // namespace internal 8478 } // namespace internal
8502 } // namespace v8 8479 } // namespace v8
8503 8480
8504 #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