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

Side by Side Diff: src/objects.cc

Issue 8635011: Introduce short external strings without pointer cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 ASSERT(static_cast<size_t>(this->length()) == resource->length()); 945 ASSERT(static_cast<size_t>(this->length()) == resource->length());
946 ScopedVector<uc16> smart_chars(this->length()); 946 ScopedVector<uc16> smart_chars(this->length());
947 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 947 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
948 ASSERT(memcmp(smart_chars.start(), 948 ASSERT(memcmp(smart_chars.start(),
949 resource->data(), 949 resource->data(),
950 resource->length() * sizeof(smart_chars[0])) == 0); 950 resource->length() * sizeof(smart_chars[0])) == 0);
951 } 951 }
952 #endif // DEBUG 952 #endif // DEBUG
953 Heap* heap = GetHeap(); 953 Heap* heap = GetHeap();
954 int size = this->Size(); // Byte size of the original string. 954 int size = this->Size(); // Byte size of the original string.
955 if (size < ExternalString::kSize) { 955 if (size < ExternalString::kShortSize) {
956 return false; 956 return false;
957 } 957 }
958 ASSERT(size >= ExternalString::kSize); 958 ASSERT(size >= ExternalString::kShortSize);
Lasse Reichstein 2011/11/23 08:43:20 This assert can safely be dropped.
Yang 2011/11/23 09:58:48 Done.
959 bool is_ascii = this->IsAsciiRepresentation(); 959 bool is_ascii = this->IsAsciiRepresentation();
960 bool is_symbol = this->IsSymbol(); 960 bool is_symbol = this->IsSymbol();
961 int length = this->length();
962 int hash_field = this->hash_field();
963 961
964 // Morph the object to an external string by adjusting the map and 962 // Morph the object to an external string by adjusting the map and
965 // reinitializing the fields. 963 // reinitializing the fields.
966 this->set_map(is_ascii ? 964 if (size >= ExternalString::kSize) {
967 heap->external_string_with_ascii_data_map() : 965 this->set_map(
968 heap->external_string_map()); 966 is_symbol
967 ? (is_ascii ? heap->external_symbol_with_ascii_data_map()
968 : heap->external_symbol_map())
969 : (is_ascii ? heap->external_string_with_ascii_data_map()
970 : heap->external_string_map()));
971 } else {
972 this->set_map(
973 is_symbol
974 ? (is_ascii ? heap->short_external_symbol_with_ascii_data_map()
975 : heap->short_external_symbol_map())
976 : (is_ascii ? heap->short_external_string_with_ascii_data_map()
977 : heap->short_external_string_map()));
978 }
969 ExternalTwoByteString* self = ExternalTwoByteString::cast(this); 979 ExternalTwoByteString* self = ExternalTwoByteString::cast(this);
970 self->set_length(length);
971 self->set_hash_field(hash_field);
972 self->set_resource(resource); 980 self->set_resource(resource);
973 // Additionally make the object into an external symbol if the original string 981 STATIC_ASSERT(String::kLengthOffset == ExternalTwoByteString::kLengthOffset);
974 // was a symbol to start with. 982 STATIC_ASSERT(String::kHashFieldOffset ==
975 if (is_symbol) { 983 ExternalTwoByteString::kHashFieldOffset);
Lasse Reichstein 2011/11/23 08:43:20 These two asserts are unnecessary, since ExternalA
Yang 2011/11/23 09:58:48 Done.
976 self->Hash(); // Force regeneration of the hash value. 984 if (is_symbol) self->Hash(); // Force regeneration of the hash value.
977 // Now morph this external string into a external symbol.
978 this->set_map(is_ascii ?
979 heap->external_symbol_with_ascii_data_map() :
980 heap->external_symbol_map());
981 }
982 985
983 // Fill the remainder of the string with dead wood. 986 // Fill the remainder of the string with dead wood.
984 int new_size = this->Size(); // Byte size of the external String object. 987 int new_size = this->Size(); // Byte size of the external String object.
985 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); 988 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size);
986 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { 989 if (Marking::IsBlack(Marking::MarkBitFrom(this))) {
987 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); 990 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size);
988 } 991 }
989 return true; 992 return true;
990 } 993 }
991 994
992 995
993 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { 996 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
994 #ifdef DEBUG 997 #ifdef DEBUG
995 if (FLAG_enable_slow_asserts) { 998 if (FLAG_enable_slow_asserts) {
996 // Assert that the resource and the string are equivalent. 999 // Assert that the resource and the string are equivalent.
997 ASSERT(static_cast<size_t>(this->length()) == resource->length()); 1000 ASSERT(static_cast<size_t>(this->length()) == resource->length());
998 ScopedVector<char> smart_chars(this->length()); 1001 ScopedVector<char> smart_chars(this->length());
999 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 1002 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1000 ASSERT(memcmp(smart_chars.start(), 1003 ASSERT(memcmp(smart_chars.start(),
1001 resource->data(), 1004 resource->data(),
1002 resource->length() * sizeof(smart_chars[0])) == 0); 1005 resource->length() * sizeof(smart_chars[0])) == 0);
1003 } 1006 }
1004 #endif // DEBUG 1007 #endif // DEBUG
1005 Heap* heap = GetHeap(); 1008 Heap* heap = GetHeap();
1006 int size = this->Size(); // Byte size of the original string. 1009 int size = this->Size(); // Byte size of the original string.
1007 if (size < ExternalString::kSize) { 1010 if (size < ExternalString::kShortSize) {
1008 return false; 1011 return false;
1009 } 1012 }
1010 ASSERT(size >= ExternalString::kSize); 1013 ASSERT(size >= ExternalString::kShortSize);
Lasse Reichstein 2011/11/23 08:43:20 Ditto.
Yang 2011/11/23 09:58:48 Done.
1011 bool is_symbol = this->IsSymbol(); 1014 bool is_symbol = this->IsSymbol();
1012 int length = this->length();
1013 int hash_field = this->hash_field();
1014 1015
1015 // Morph the object to an external string by adjusting the map and 1016 // Morph the object to an external string by adjusting the map and
1016 // reinitializing the fields. 1017 // reinitializing the fields. Use short version if space is limited.
1017 this->set_map(heap->external_ascii_string_map()); 1018 if (size >= ExternalString::kSize) {
1019 this->set_map(is_symbol ? heap->external_ascii_symbol_map()
1020 : heap->external_ascii_string_map());
1021 } else {
1022 this->set_map(is_symbol ? heap->short_external_ascii_symbol_map()
1023 : heap->short_external_ascii_string_map());
1024 }
1018 ExternalAsciiString* self = ExternalAsciiString::cast(this); 1025 ExternalAsciiString* self = ExternalAsciiString::cast(this);
1019 self->set_length(length);
1020 self->set_hash_field(hash_field);
1021 self->set_resource(resource); 1026 self->set_resource(resource);
1022 // Additionally make the object into an external symbol if the original string 1027 STATIC_ASSERT(String::kLengthOffset == ExternalAsciiString::kLengthOffset);
1023 // was a symbol to start with. 1028 STATIC_ASSERT(String::kHashFieldOffset ==
1024 if (is_symbol) { 1029 ExternalAsciiString::kHashFieldOffset);
Lasse Reichstein 2011/11/23 08:43:20 As above.
Yang 2011/11/23 09:58:48 Done.
1025 self->Hash(); // Force regeneration of the hash value. 1030 if (is_symbol) self->Hash(); // Force regeneration of the hash value.
Lasse Reichstein 2011/11/23 08:43:20 Is there an explanation of how the hash can possib
Yang 2011/11/23 09:58:48 Looking into that later.
1026 // Now morph this external string into a external symbol.
1027 this->set_map(heap->external_ascii_symbol_map());
1028 }
1029 1031
1030 // Fill the remainder of the string with dead wood. 1032 // Fill the remainder of the string with dead wood.
1031 int new_size = this->Size(); // Byte size of the external String object. 1033 int new_size = this->Size(); // Byte size of the external String object.
1032 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); 1034 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size);
1033 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { 1035 if (Marking::IsBlack(Marking::MarkBitFrom(this))) {
1034 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); 1036 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size);
1035 } 1037 }
1036
1037 return true; 1038 return true;
1038 } 1039 }
1039 1040
1040 1041
1041 void String::StringShortPrint(StringStream* accumulator) { 1042 void String::StringShortPrint(StringStream* accumulator) {
1042 int len = length(); 1043 int len = length();
1043 if (len > kMaxShortPrintLength) { 1044 if (len > kMaxShortPrintLength) {
1044 accumulator->Add("<Very long string[%u]>", len); 1045 accumulator->Add("<Very long string[%u]>", len);
1045 return; 1046 return;
1046 } 1047 }
(...skipping 11468 matching lines...) Expand 10 before | Expand all | Expand 10 after
12515 if (break_point_objects()->IsUndefined()) return 0; 12516 if (break_point_objects()->IsUndefined()) return 0;
12516 // Single break point. 12517 // Single break point.
12517 if (!break_point_objects()->IsFixedArray()) return 1; 12518 if (!break_point_objects()->IsFixedArray()) return 1;
12518 // Multiple break points. 12519 // Multiple break points.
12519 return FixedArray::cast(break_point_objects())->length(); 12520 return FixedArray::cast(break_point_objects())->length();
12520 } 12521 }
12521 #endif // ENABLE_DEBUGGER_SUPPORT 12522 #endif // ENABLE_DEBUGGER_SUPPORT
12522 12523
12523 12524
12524 } } // namespace v8::internal 12525 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698