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

Side by Side Diff: src/objects.cc

Issue 462643002: Small clean up of externalizing strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: change Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 if (FLAG_enable_slow_asserts) { 1045 if (FLAG_enable_slow_asserts) {
1046 // Assert that the resource and the string are equivalent. 1046 // Assert that the resource and the string are equivalent.
1047 DCHECK(static_cast<size_t>(this->length()) == resource->length()); 1047 DCHECK(static_cast<size_t>(this->length()) == resource->length());
1048 ScopedVector<uc16> smart_chars(this->length()); 1048 ScopedVector<uc16> smart_chars(this->length());
1049 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 1049 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1050 DCHECK(memcmp(smart_chars.start(), 1050 DCHECK(memcmp(smart_chars.start(),
1051 resource->data(), 1051 resource->data(),
1052 resource->length() * sizeof(smart_chars[0])) == 0); 1052 resource->length() * sizeof(smart_chars[0])) == 0);
1053 } 1053 }
1054 #endif // DEBUG 1054 #endif // DEBUG
1055 int size = this->Size(); // Byte size of the original string.
1056 // Abort if size does not allow in-place conversion.
1057 if (size < ExternalString::kShortSize) return false;
1055 Heap* heap = GetHeap(); 1058 Heap* heap = GetHeap();
1056 int size = this->Size(); // Byte size of the original string.
1057 if (size < ExternalString::kShortSize) {
1058 return false;
1059 }
1060 bool is_ascii = this->IsOneByteRepresentation(); 1059 bool is_ascii = this->IsOneByteRepresentation();
1061 bool is_internalized = this->IsInternalizedString(); 1060 bool is_internalized = this->IsInternalizedString();
1062 1061
1063 // Morph the string to an external string by replacing the map and 1062 // Morph the string to an external string by replacing the map and
1064 // reinitializing the fields. This won't work if 1063 // reinitializing the fields. This won't work if
1065 // - the space the existing string occupies is too small for a regular 1064 // - the space the existing string occupies is too small for a regular
1066 // external string. 1065 // external string.
1067 // - the existing string is in old pointer space and the backing store of 1066 // - the existing string is in old pointer space and the backing store of
1068 // the external string is not aligned. The GC cannot deal with a field 1067 // the external string is not aligned. The GC cannot deal with a field
1069 // containing a possibly unaligned address to outside of V8's heap. 1068 // containing a possibly unaligned address to outside of V8's heap.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 ExternalTwoByteString* self = ExternalTwoByteString::cast(this); 1101 ExternalTwoByteString* self = ExternalTwoByteString::cast(this);
1103 self->set_resource(resource); 1102 self->set_resource(resource);
1104 if (is_internalized) self->Hash(); // Force regeneration of the hash value. 1103 if (is_internalized) self->Hash(); // Force regeneration of the hash value.
1105 1104
1106 heap->AdjustLiveBytes(this->address(), new_size - size, Heap::FROM_MUTATOR); 1105 heap->AdjustLiveBytes(this->address(), new_size - size, Heap::FROM_MUTATOR);
1107 return true; 1106 return true;
1108 } 1107 }
1109 1108
1110 1109
1111 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { 1110 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
1111 // Externalizing twice leaks the external resource, so it's
1112 // prohibited by the API.
1113 DCHECK(!this->IsExternalString());
1112 #ifdef ENABLE_SLOW_DCHECKS 1114 #ifdef ENABLE_SLOW_DCHECKS
1113 if (FLAG_enable_slow_asserts) { 1115 if (FLAG_enable_slow_asserts) {
1114 // Assert that the resource and the string are equivalent. 1116 // Assert that the resource and the string are equivalent.
1115 DCHECK(static_cast<size_t>(this->length()) == resource->length()); 1117 DCHECK(static_cast<size_t>(this->length()) == resource->length());
1116 if (this->IsTwoByteRepresentation()) { 1118 if (this->IsTwoByteRepresentation()) {
1117 ScopedVector<uint16_t> smart_chars(this->length()); 1119 ScopedVector<uint16_t> smart_chars(this->length());
1118 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 1120 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1119 DCHECK(String::IsOneByte(smart_chars.start(), this->length())); 1121 DCHECK(String::IsOneByte(smart_chars.start(), this->length()));
1120 } 1122 }
1121 ScopedVector<char> smart_chars(this->length()); 1123 ScopedVector<char> smart_chars(this->length());
1122 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 1124 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1123 DCHECK(memcmp(smart_chars.start(), 1125 DCHECK(memcmp(smart_chars.start(),
1124 resource->data(), 1126 resource->data(),
1125 resource->length() * sizeof(smart_chars[0])) == 0); 1127 resource->length() * sizeof(smart_chars[0])) == 0);
1126 } 1128 }
1127 #endif // DEBUG 1129 #endif // DEBUG
1130 int size = this->Size(); // Byte size of the original string.
1131 // Abort if size does not allow in-place conversion.
1132 if (size < ExternalString::kShortSize) return false;
1128 Heap* heap = GetHeap(); 1133 Heap* heap = GetHeap();
1129 int size = this->Size(); // Byte size of the original string.
1130 if (size < ExternalString::kShortSize) {
1131 return false;
1132 }
1133 bool is_internalized = this->IsInternalizedString(); 1134 bool is_internalized = this->IsInternalizedString();
1134 1135
1135 // Morph the string to an external string by replacing the map and 1136 // Morph the string to an external string by replacing the map and
1136 // reinitializing the fields. This won't work if 1137 // reinitializing the fields. This won't work if
1137 // - the space the existing string occupies is too small for a regular 1138 // - the space the existing string occupies is too small for a regular
1138 // external string. 1139 // external string.
1139 // - the existing string is in old pointer space and the backing store of 1140 // - the existing string is in old pointer space and the backing store of
1140 // the external string is not aligned. The GC cannot deal with a field 1141 // the external string is not aligned. The GC cannot deal with a field
1141 // containing a possibly unaligned address to outside of V8's heap. 1142 // containing a possibly unaligned address to outside of V8's heap.
1142 // In either case we resort to a short external string instead, omitting 1143 // In either case we resort to a short external string instead, omitting
(...skipping 15755 matching lines...) Expand 10 before | Expand all | Expand 10 after
16898 #define ERROR_MESSAGES_TEXTS(C, T) T, 16899 #define ERROR_MESSAGES_TEXTS(C, T) T,
16899 static const char* error_messages_[] = { 16900 static const char* error_messages_[] = {
16900 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16901 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16901 }; 16902 };
16902 #undef ERROR_MESSAGES_TEXTS 16903 #undef ERROR_MESSAGES_TEXTS
16903 return error_messages_[reason]; 16904 return error_messages_[reason];
16904 } 16905 }
16905 16906
16906 16907
16907 } } // namespace v8::internal 16908 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698